2016-08-04 15:26:53 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "refactoringclient.h"
|
|
|
|
|
|
2017-07-03 12:35:58 +02:00
|
|
|
#include "clangqueryhighlighter.h"
|
|
|
|
|
#include "clangqueryexamplehighlighter.h"
|
|
|
|
|
|
|
|
|
|
#include <clangrefactoringmessages.h>
|
2017-09-21 11:43:59 +02:00
|
|
|
#include <filepathcachinginterface.h>
|
|
|
|
|
#include <refactoringconnectionclient.h>
|
2016-08-04 15:26:53 +02:00
|
|
|
|
|
|
|
|
namespace ClangRefactoring {
|
|
|
|
|
|
|
|
|
|
void RefactoringClient::alive()
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
if (m_connectionClient)
|
|
|
|
|
m_connectionClient->resetProcessAliveTimer();
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-15 15:38:12 +01:00
|
|
|
void RefactoringClient::sourceRangesAndDiagnosticsForQueryMessage(
|
|
|
|
|
ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message)
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
m_clangQueryExampleHighlighter->setSourceRanges(message.takeSourceRanges());
|
2018-04-04 18:25:23 +02:00
|
|
|
m_clangQueryHighlighter->setDiagnostics(message.diagnostics);
|
2017-07-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RefactoringClient::sourceRangesForQueryMessage(ClangBackEnd::SourceRangesForQueryMessage &&message)
|
|
|
|
|
{
|
|
|
|
|
++m_resultCounter;
|
2018-04-04 18:25:23 +02:00
|
|
|
addSearchResults(message.sourceRanges);
|
2016-11-23 13:13:38 +01:00
|
|
|
setResultCounterAndSendSearchIsFinishedIfFinished();
|
2016-11-15 15:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-27 17:52:44 +02:00
|
|
|
void RefactoringClient::progress(ClangBackEnd::ProgressMessage &&message)
|
|
|
|
|
{
|
|
|
|
|
m_progressManager.setProgress(message.progress, message.total);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngine)
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
m_refactoringEngine = refactoringEngine;
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:13:38 +01:00
|
|
|
void RefactoringClient::setSearchHandle(SearchHandle *searchHandle)
|
2016-11-15 15:38:12 +01:00
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
m_searchHandle = searchHandle;
|
2016-11-15 15:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:13:38 +01:00
|
|
|
SearchHandle *RefactoringClient::searchHandle() const
|
2016-11-15 15:38:12 +01:00
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
return m_searchHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RefactoringClient::setClangQueryExampleHighlighter(ClangQueryExampleHighlighter *highlighter)
|
|
|
|
|
{
|
|
|
|
|
m_clangQueryExampleHighlighter = highlighter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RefactoringClient::setClangQueryHighlighter(ClangQueryHighlighter *highlighter)
|
|
|
|
|
{
|
|
|
|
|
m_clangQueryHighlighter = highlighter;
|
2016-11-15 15:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:13:38 +01:00
|
|
|
void RefactoringClient::setExpectedResultCount(uint count)
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
m_expectedResultCount = count;
|
|
|
|
|
m_resultCounter = 0;
|
|
|
|
|
m_searchHandle->setExpectedResultCount(count);
|
2016-11-23 13:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint RefactoringClient::expectedResultCount() const
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
return m_expectedResultCount;
|
2016-11-23 13:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint RefactoringClient::resultCounter() const
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
return m_resultCounter;
|
2016-11-23 13:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-05 15:19:39 +01:00
|
|
|
void RefactoringClient::setRefactoringConnectionClient(
|
|
|
|
|
ClangBackEnd::RefactoringConnectionClient *connectionClient)
|
|
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
m_connectionClient = connectionClient;
|
2016-12-05 15:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-15 15:38:12 +01:00
|
|
|
void RefactoringClient::addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges)
|
|
|
|
|
{
|
2018-04-04 18:25:23 +02:00
|
|
|
for (const auto &sourceRangeWithText : sourceRanges.sourceRangeWithTextContainers)
|
2017-09-21 11:43:59 +02:00
|
|
|
addSearchResult(sourceRangeWithText);
|
2016-11-15 15:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
void RefactoringClient::addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRangeWithText)
|
2016-11-15 15:38:12 +01:00
|
|
|
{
|
2017-09-21 11:43:59 +02:00
|
|
|
auto &filePathCache = m_refactoringEngine->filePathCache();
|
|
|
|
|
|
|
|
|
|
m_searchHandle->addResult(QString(filePathCache.filePath(sourceRangeWithText.filePathId()).path()),
|
2018-04-04 18:25:23 +02:00
|
|
|
QString(sourceRangeWithText.text),
|
|
|
|
|
{{int(sourceRangeWithText.start.line),
|
|
|
|
|
int(sourceRangeWithText.start.column - 1),
|
|
|
|
|
int(sourceRangeWithText.start.offset)},
|
|
|
|
|
{int(sourceRangeWithText.end.line),
|
|
|
|
|
int(sourceRangeWithText.end.column - 1),
|
|
|
|
|
int(sourceRangeWithText.end.offset)}});
|
2016-11-15 15:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:13:38 +01:00
|
|
|
void RefactoringClient::setResultCounterAndSendSearchIsFinishedIfFinished()
|
2016-11-15 15:38:12 +01:00
|
|
|
{
|
2017-07-03 12:35:58 +02:00
|
|
|
m_searchHandle->setResultCounter(m_resultCounter);
|
|
|
|
|
if (m_resultCounter == m_expectedResultCount)
|
|
|
|
|
m_searchHandle->finishSearch();
|
2016-11-15 15:38:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-08-04 15:26:53 +02:00
|
|
|
} // namespace ClangRefactoring
|