forked from qt-creator/qt-creator
Clang: Extend clang query
It's a first step to introduce clang query. Change-Id: I4d001a8883f56066765ce6bc561fa3f49611c0a4 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -1,129 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "clangquerycurrentfilefindfilter.h"
|
||||
|
||||
#include "projectpartutilities.h"
|
||||
#include "refactoringclient.h"
|
||||
#include "refactoringcompileroptionsbuilder.h"
|
||||
#include "searchinterface.h"
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
#include <requestsourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
ClangQueryCurrentFileFindFilter::ClangQueryCurrentFileFindFilter(
|
||||
ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient)
|
||||
: server(server),
|
||||
searchInterface(searchInterface),
|
||||
refactoringClient(refactoringClient)
|
||||
{
|
||||
}
|
||||
|
||||
QString ClangQueryCurrentFileFindFilter::id() const
|
||||
{
|
||||
return QStringLiteral("Clang Query Current File");
|
||||
}
|
||||
|
||||
QString ClangQueryCurrentFileFindFilter::displayName() const
|
||||
{
|
||||
return tr("Clang Query Current File");
|
||||
}
|
||||
|
||||
bool ClangQueryCurrentFileFindFilter::isEnabled() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClangQueryCurrentFileFindFilter::findAll(const QString &queryText, Core::FindFlags)
|
||||
{
|
||||
searchHandle = searchInterface.startNewSearch(tr("Clang Query"), queryText);
|
||||
|
||||
refactoringClient.setSearchHandle(searchHandle.get());
|
||||
|
||||
server.requestSourceRangesAndDiagnosticsForQueryMessage(createMessage(queryText));
|
||||
}
|
||||
|
||||
Core::FindFlags ClangQueryCurrentFileFindFilter::supportedFindFlags() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClangQueryCurrentFileFindFilter::setCurrentDocumentFilePath(const QString &filePath)
|
||||
{
|
||||
currentDocumentFilePath = filePath;
|
||||
}
|
||||
|
||||
void ClangQueryCurrentFileFindFilter::setUnsavedDocumentContent(const QString &unsavedContent)
|
||||
{
|
||||
unsavedDocumentContent = unsavedContent;
|
||||
}
|
||||
|
||||
void ClangQueryCurrentFileFindFilter::setProjectPart(const CppTools::ProjectPart::Ptr &projectPart)
|
||||
{
|
||||
this->projectPart = projectPart;
|
||||
}
|
||||
|
||||
void ClangQueryCurrentFileFindFilter::setUsable(bool isUsable)
|
||||
{
|
||||
server.setUsable(isUsable);
|
||||
}
|
||||
|
||||
bool ClangQueryCurrentFileFindFilter::isUsable() const
|
||||
{
|
||||
return server.isUsable();
|
||||
}
|
||||
|
||||
ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage
|
||||
ClangQueryCurrentFileFindFilter::createMessage(const QString &queryText) const
|
||||
{
|
||||
std::vector<ClangBackEnd::V2::FileContainer> fileContainers;
|
||||
fileContainers.emplace_back(ClangBackEnd::FilePath(currentDocumentFilePath),
|
||||
unsavedDocumentContent,
|
||||
createCommandLine());
|
||||
|
||||
return ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage(
|
||||
Utils::SmallString(queryText),
|
||||
std::move(fileContainers));
|
||||
}
|
||||
|
||||
Utils::SmallStringVector ClangQueryCurrentFileFindFilter::createCommandLine() const
|
||||
{
|
||||
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
|
||||
|
||||
auto commandLine = RefactoringCompilerOptionsBuilder::build(
|
||||
projectPart.data(),
|
||||
fileKindInProjectPart(projectPart.data(), currentDocumentFilePath),
|
||||
RefactoringCompilerOptionsBuilder::PchUsage::None);
|
||||
|
||||
commandLine.push_back(currentDocumentFilePath);
|
||||
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -1,82 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "searchhandleinterface.h"
|
||||
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <coreplugin/find/ifindfilter.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class RefactoringServerInterface;
|
||||
class RequestSourceRangesAndDiagnosticsForQueryMessage;
|
||||
}
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class RefactoringClient;
|
||||
class SearchInterface;
|
||||
|
||||
class ClangQueryCurrentFileFindFilter : public Core::IFindFilter
|
||||
{
|
||||
public:
|
||||
ClangQueryCurrentFileFindFilter(ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient);
|
||||
QString id() const;
|
||||
QString displayName() const;
|
||||
bool isEnabled() const;
|
||||
void findAll(const QString &queryText, Core::FindFlags findFlags = 0);
|
||||
Core::FindFlags supportedFindFlags() const;
|
||||
|
||||
void setCurrentDocumentFilePath(const QString &filePath);
|
||||
void setUnsavedDocumentContent(const QString &unsavedContent);
|
||||
void setCurrentDocumentRevision(int revision);
|
||||
void setProjectPart(const CppTools::ProjectPart::Ptr &projectPart);
|
||||
|
||||
void setUsable(bool isUsable);
|
||||
bool isUsable() const;
|
||||
|
||||
private:
|
||||
ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage createMessage(
|
||||
const QString &queryText) const;
|
||||
|
||||
Utils::SmallStringVector createCommandLine() const;
|
||||
|
||||
private:
|
||||
QString currentDocumentFilePath;
|
||||
QString unsavedDocumentContent;
|
||||
std::unique_ptr<SearchHandleInterface> searchHandle;
|
||||
CppTools::ProjectPart::Ptr projectPart;
|
||||
ClangBackEnd::RefactoringServerInterface &server;
|
||||
SearchInterface &searchInterface;
|
||||
RefactoringClient &refactoringClient;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -25,10 +25,13 @@
|
||||
|
||||
#include "clangqueryprojectsfindfilter.h"
|
||||
|
||||
#include "projectpartutilities.h"
|
||||
#include "refactoringclient.h"
|
||||
#include "refactoringcompileroptionsbuilder.h"
|
||||
#include "searchinterface.h"
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
#include <requestsourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
@@ -61,9 +64,15 @@ void ClangQueryProjectsFindFilter::findAll(const QString &queryText, Core::FindF
|
||||
{
|
||||
searchHandle = searchInterface.startNewSearch(tr("Clang Query"), queryText);
|
||||
|
||||
searchHandle->setRefactoringServer(&server);
|
||||
|
||||
refactoringClient.setSearchHandle(searchHandle.get());
|
||||
|
||||
//server.requestSourceRangesAndDiagnosticsForQueryMessage(createMessage(queryText));
|
||||
auto message = createMessage(queryText);
|
||||
|
||||
refactoringClient.setExpectedResultCount(message.fileContainers().size());
|
||||
|
||||
server.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message));
|
||||
}
|
||||
|
||||
Core::FindFlags ClangQueryProjectsFindFilter::supportedFindFlags() const
|
||||
@@ -71,6 +80,11 @@ Core::FindFlags ClangQueryProjectsFindFilter::supportedFindFlags() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClangQueryProjectsFindFilter::setProjectParts(const std::vector<CppTools::ProjectPart::Ptr> &projectParts)
|
||||
{
|
||||
this->projectParts = projectParts;
|
||||
}
|
||||
|
||||
bool ClangQueryProjectsFindFilter::isUsable() const
|
||||
{
|
||||
return server.isUsable();
|
||||
@@ -81,4 +95,53 @@ void ClangQueryProjectsFindFilter::setUsable(bool isUsable)
|
||||
server.setUsable(isUsable);
|
||||
}
|
||||
|
||||
SearchHandle *ClangQueryProjectsFindFilter::searchHandleForTestOnly() const
|
||||
{
|
||||
return searchHandle.get();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Utils::SmallStringVector createCommandLine(CppTools::ProjectPart *projectPart,
|
||||
const QString &documentFilePath,
|
||||
CppTools::ProjectFile::Kind fileKind)
|
||||
{
|
||||
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
|
||||
|
||||
auto commandLine = RefactoringCompilerOptionsBuilder::build(projectPart,
|
||||
fileKind,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||
|
||||
commandLine.push_back(documentFilePath);
|
||||
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
std::vector<ClangBackEnd::V2::FileContainer>
|
||||
createFileContainers(const std::vector<CppTools::ProjectPart::Ptr> &projectParts)
|
||||
{
|
||||
std::vector<ClangBackEnd::V2::FileContainer> fileContainers;
|
||||
|
||||
for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) {
|
||||
for (const CppTools::ProjectFile &projectFile : projectPart->files) {
|
||||
fileContainers.emplace_back(ClangBackEnd::FilePath(projectFile.path),
|
||||
"",
|
||||
createCommandLine(projectPart.data(),
|
||||
projectFile.path,
|
||||
projectFile.kind));
|
||||
}
|
||||
}
|
||||
|
||||
return fileContainers;
|
||||
}
|
||||
}
|
||||
|
||||
ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage ClangQueryProjectsFindFilter::createMessage(const QString &queryText) const
|
||||
{
|
||||
return ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage(
|
||||
Utils::SmallString(queryText),
|
||||
createFileContainers(projectParts));
|
||||
}
|
||||
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -25,10 +25,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "searchhandleinterface.h"
|
||||
#include "searchhandle.h"
|
||||
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <coreplugin/find/ifindfilter.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
@@ -54,11 +58,20 @@ public:
|
||||
void findAll(const QString &queryText, Core::FindFlags findFlags = 0);
|
||||
Core::FindFlags supportedFindFlags() const;
|
||||
|
||||
void setProjectParts(const std::vector<CppTools::ProjectPart::Ptr> &projectParts);
|
||||
|
||||
bool isUsable() const;
|
||||
void setUsable(bool isUsable);
|
||||
|
||||
SearchHandle* searchHandleForTestOnly() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SearchHandleInterface> searchHandle;
|
||||
ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage createMessage(
|
||||
const QString &queryText) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SearchHandle> searchHandle;
|
||||
std::vector<CppTools::ProjectPart::Ptr> projectParts;
|
||||
ClangBackEnd::RefactoringServerInterface &server;
|
||||
SearchInterface &searchInterface;
|
||||
RefactoringClient &refactoringClient;
|
||||
|
||||
@@ -8,7 +8,6 @@ HEADERS += \
|
||||
$$PWD/searchinterface.h \
|
||||
$$PWD/searchhandleinterface.h \
|
||||
$$PWD/projectpartutilities.h \
|
||||
$$PWD/clangquerycurrentfilefindfilter.h \
|
||||
$$PWD/clangqueryprojectsfindfilter.h
|
||||
|
||||
SOURCES += \
|
||||
@@ -19,5 +18,4 @@ SOURCES += \
|
||||
$$PWD/searchinterface.cpp \
|
||||
$$PWD/searchhandleinterface.cpp \
|
||||
$$PWD/projectpartutilities.cpp \
|
||||
$$PWD/clangquerycurrentfilefindfilter.cpp \
|
||||
$$PWD/clangqueryprojectsfindfilter.cpp
|
||||
|
||||
@@ -25,66 +25,48 @@
|
||||
|
||||
#include "qtcreatorclangqueryfindfilter.h"
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/baseeditordocumentparser.h>
|
||||
#include <cpptools/projectinfo.h>
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
QtCreatorClangQueryFindFilter::QtCreatorClangQueryFindFilter(ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient)
|
||||
: ClangQueryCurrentFileFindFilter(server, searchInterface, refactoringClient)
|
||||
: ClangQueryProjectsFindFilter(server, searchInterface, refactoringClient)
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
CppTools::CppModelManager *cppToolManager()
|
||||
{
|
||||
return CppTools::CppModelManager::instance();
|
||||
}
|
||||
|
||||
bool isCppEditor(Core::IEditor *currentEditor)
|
||||
{
|
||||
return cppToolManager()->isCppEditor(currentEditor);
|
||||
}
|
||||
|
||||
CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath)
|
||||
{
|
||||
if (const auto parser = CppTools::BaseEditorDocumentParser::get(filePath))
|
||||
return parser->projectPart();
|
||||
return CppTools::ProjectPart::Ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QtCreatorClangQueryFindFilter::findAll(const QString &queryText, Core::FindFlags findFlags)
|
||||
{
|
||||
prepareFind();
|
||||
|
||||
ClangQueryCurrentFileFindFilter::findAll(queryText, findFlags);
|
||||
ClangQueryProjectsFindFilter::findAll(queryText, findFlags);
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::vector<CppTools::ProjectPart::Ptr>
|
||||
convertProjectParts(const QList<CppTools::ProjectPart::Ptr> &projectPartList)
|
||||
{
|
||||
std::vector<CppTools::ProjectPart::Ptr> projectPartVector;
|
||||
projectPartVector.reserve(projectPartList.size());
|
||||
|
||||
std::copy(projectPartList.begin(), projectPartList.end(), std::back_inserter(projectPartVector));
|
||||
|
||||
return projectPartVector;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QtCreatorClangQueryFindFilter::prepareFind()
|
||||
{
|
||||
Core::IEditor *currentEditor = Core::EditorManager::currentEditor();
|
||||
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::startupProject();
|
||||
|
||||
if (isCppEditor(currentEditor)) {
|
||||
Core::IDocument *currentDocument = currentEditor->document();
|
||||
auto currentTextDocument = static_cast<TextEditor::TextDocument*>(currentDocument);
|
||||
const QString filePath = currentDocument->filePath().toString();
|
||||
const CppTools::ProjectInfo projectInfo = CppTools::CppModelManager::instance()->projectInfo(currentProject);
|
||||
|
||||
setCurrentDocumentFilePath(filePath);
|
||||
setCurrentDocumentRevision(currentTextDocument->document()->revision());
|
||||
setProjectPart(projectPartForFile(filePath));
|
||||
|
||||
if (currentTextDocument->isModified())
|
||||
setUnsavedDocumentContent(currentTextDocument->document()->toPlainText());
|
||||
}
|
||||
setProjectParts(convertProjectParts(projectInfo.projectParts()));
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -25,18 +25,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "clangquerycurrentfilefindfilter.h"
|
||||
#include "clangqueryprojectsfindfilter.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorClangQueryFindFilter final : public ClangQueryCurrentFileFindFilter
|
||||
class QtCreatorClangQueryFindFilter final : public ClangQueryProjectsFindFilter
|
||||
{
|
||||
public:
|
||||
QtCreatorClangQueryFindFilter(ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient);
|
||||
|
||||
void findAll(const QString &queryText, Core::FindFlags findFlags = 0);
|
||||
void findAll(const QString &queryText, Core::FindFlags findFlags = 0) override;
|
||||
|
||||
private:
|
||||
void prepareFind();
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
|
||||
#include "qtcreatorsearchhandle.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
QtCreatorSearch::QtCreatorSearch(Core::SearchResultWindow &searchResultWindow)
|
||||
@@ -34,7 +38,7 @@ QtCreatorSearch::QtCreatorSearch(Core::SearchResultWindow &searchResultWindow)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<SearchHandleInterface> QtCreatorSearch::startNewSearch(const QString &searchLabel,
|
||||
std::unique_ptr<SearchHandle> QtCreatorSearch::startNewSearch(const QString &searchLabel,
|
||||
const QString &searchTerm)
|
||||
{
|
||||
Core::SearchResult *searchResult = searchResultWindow.startNewSearch(
|
||||
@@ -44,7 +48,24 @@ std::unique_ptr<SearchHandleInterface> QtCreatorSearch::startNewSearch(const QSt
|
||||
Core::SearchResultWindow::SearchOnly,
|
||||
Core::SearchResultWindow::PreserveCaseEnabled);
|
||||
|
||||
return std::unique_ptr<SearchHandleInterface>(new QtCreatorSearchHandle(searchResult));
|
||||
QObject::connect(searchResult,
|
||||
&Core::SearchResult::activated,
|
||||
&QtCreatorSearch::openEditor);
|
||||
|
||||
auto searchHandle = std::unique_ptr<SearchHandle>(new QtCreatorSearchHandle(searchResult));
|
||||
|
||||
QObject::connect(searchResult,
|
||||
&Core::SearchResult::cancelled,
|
||||
[handle=searchHandle.get()] () { handle->cancel(); });
|
||||
|
||||
return searchHandle;
|
||||
}
|
||||
|
||||
void QtCreatorSearch::openEditor(const Core::SearchResultItem &item)
|
||||
{
|
||||
Core::EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
||||
item.mainRange.begin.line,
|
||||
item.mainRange.begin.column);
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
|
||||
namespace Core {
|
||||
class SearchResultItem;
|
||||
}
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorSearch final : public SearchInterface
|
||||
@@ -36,9 +40,12 @@ class QtCreatorSearch final : public SearchInterface
|
||||
public:
|
||||
QtCreatorSearch(Core::SearchResultWindow &searchResultWindow);
|
||||
|
||||
std::unique_ptr<SearchHandleInterface> startNewSearch(const QString &searchLabel,
|
||||
std::unique_ptr<SearchHandle> startNewSearch(const QString &searchLabel,
|
||||
const QString &searchTerm);
|
||||
|
||||
private:
|
||||
static void openEditor(const Core::SearchResultItem &item);
|
||||
|
||||
private:
|
||||
Core::SearchResultWindow &searchResultWindow;
|
||||
};
|
||||
|
||||
@@ -25,21 +25,40 @@
|
||||
|
||||
#include "qtcreatorsearchhandle.h"
|
||||
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
QtCreatorSearchHandle::QtCreatorSearchHandle(Core::SearchResult *searchResult)
|
||||
: searchResult(searchResult)
|
||||
{
|
||||
auto title = QCoreApplication::translate("QtCreatorSearchHandle", "Clang Query");
|
||||
Core::ProgressManager::addTask(promise.future(), title, "clang query", 0);
|
||||
}
|
||||
|
||||
void QtCreatorSearchHandle::addResult(const QString &fileName, int lineNumber, const QString &lineText, int searchTermStart, int searchTermLength)
|
||||
void QtCreatorSearchHandle::addResult(const QString &fileName,
|
||||
const QString &lineText,
|
||||
Core::TextRange textRange)
|
||||
{
|
||||
searchResult->addResult(fileName, lineNumber, lineText, searchTermStart, searchTermLength);
|
||||
searchResult->addResult(fileName, lineText, textRange);
|
||||
}
|
||||
|
||||
void QtCreatorSearchHandle::setExpectedResultCount(uint count)
|
||||
{
|
||||
promise.setExpectedResultCount(count);
|
||||
}
|
||||
|
||||
void QtCreatorSearchHandle::setResultCounter(uint counter)
|
||||
{
|
||||
promise.setProgressValue(counter);
|
||||
}
|
||||
|
||||
void QtCreatorSearchHandle::finishSearch()
|
||||
{
|
||||
searchResult->finishSearch(false);
|
||||
promise.reportFinished();
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -25,27 +25,31 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "searchhandleinterface.h"
|
||||
#include "searchhandle.h"
|
||||
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
|
||||
#include <QFutureInterface>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorSearchHandle final : public SearchHandleInterface
|
||||
class QtCreatorSearchHandle final : public SearchHandle
|
||||
{
|
||||
public:
|
||||
QtCreatorSearchHandle(Core::SearchResult *searchResult);
|
||||
|
||||
void addResult(const QString &fileName,
|
||||
int lineNumber,
|
||||
const QString &lineText,
|
||||
int searchTermStart,
|
||||
int searchTermLength);
|
||||
Core::TextRange textRange) override;
|
||||
|
||||
void finishSearch();
|
||||
void setExpectedResultCount(uint count) override;
|
||||
void setResultCounter(uint counter) override;
|
||||
|
||||
void finishSearch() override;
|
||||
|
||||
private:
|
||||
Core::SearchResult *searchResult;
|
||||
QFutureInterface<void> promise;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -48,8 +48,9 @@ void RefactoringClient::sourceLocationsForRenamingMessage(
|
||||
void RefactoringClient::sourceRangesAndDiagnosticsForQueryMessage(
|
||||
ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message)
|
||||
{
|
||||
++resultCounter_;
|
||||
addSearchResults(message.sourceRanges());
|
||||
sendSearchIsFinished();
|
||||
setResultCounterAndSendSearchIsFinishedIfFinished();
|
||||
}
|
||||
|
||||
void RefactoringClient::setLocalRenamingCallback(
|
||||
@@ -63,14 +64,14 @@ void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngin
|
||||
this->refactoringEngine = refactoringEngine;
|
||||
}
|
||||
|
||||
void RefactoringClient::setSearchHandle(SearchHandleInterface *searchHandleInterface)
|
||||
void RefactoringClient::setSearchHandle(SearchHandle *searchHandle)
|
||||
{
|
||||
this->searchHandleInterface = searchHandleInterface;
|
||||
this->searchHandle_ = searchHandle;
|
||||
}
|
||||
|
||||
SearchHandleInterface *RefactoringClient::searchHandle() const
|
||||
SearchHandle *RefactoringClient::searchHandle() const
|
||||
{
|
||||
return searchHandleInterface;
|
||||
return searchHandle_;
|
||||
}
|
||||
|
||||
bool RefactoringClient::hasValidLocalRenamingCallback() const
|
||||
@@ -78,6 +79,23 @@ bool RefactoringClient::hasValidLocalRenamingCallback() const
|
||||
return bool(localRenamingCallback);
|
||||
}
|
||||
|
||||
void RefactoringClient::setExpectedResultCount(uint count)
|
||||
{
|
||||
expectedResultCount_ = count;
|
||||
resultCounter_ = 0;
|
||||
searchHandle_->setExpectedResultCount(count);
|
||||
}
|
||||
|
||||
uint RefactoringClient::expectedResultCount() const
|
||||
{
|
||||
return expectedResultCount_;
|
||||
}
|
||||
|
||||
uint RefactoringClient::resultCounter() const
|
||||
{
|
||||
return resultCounter_;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Utils::SmallString concatenateFilePath(const ClangBackEnd::FilePath &filePath)
|
||||
@@ -122,16 +140,19 @@ void RefactoringClient::addSearchResults(const ClangBackEnd::SourceRangesContain
|
||||
void RefactoringClient::addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRangeWithText,
|
||||
std::unordered_map<uint, QString> &filePaths)
|
||||
{
|
||||
searchHandleInterface->addResult(filePaths[sourceRangeWithText.fileHash()],
|
||||
int(sourceRangeWithText.start().line()),
|
||||
sourceRangeWithText.text(),
|
||||
int(sourceRangeWithText.start().column()),
|
||||
int(sourceRangeWithText.end().column()));
|
||||
searchHandle_->addResult(filePaths[sourceRangeWithText.fileHash()],
|
||||
sourceRangeWithText.text(),
|
||||
{{int(sourceRangeWithText.start().line()),
|
||||
int(sourceRangeWithText.start().column())},
|
||||
{int(sourceRangeWithText.end().line()),
|
||||
int(sourceRangeWithText.end().column())}});
|
||||
}
|
||||
|
||||
void RefactoringClient::sendSearchIsFinished()
|
||||
void RefactoringClient::setResultCounterAndSendSearchIsFinishedIfFinished()
|
||||
{
|
||||
searchHandleInterface->finishSearch();
|
||||
searchHandle_->setResultCounter(resultCounter_);
|
||||
if (resultCounter_ == expectedResultCount_)
|
||||
searchHandle_->finishSearch();
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "refactoringengine.h"
|
||||
|
||||
#include <searchhandleinterface.h>
|
||||
#include <searchhandle.h>
|
||||
|
||||
#include <refactoringclientinterface.h>
|
||||
|
||||
@@ -53,23 +53,35 @@ public:
|
||||
void setLocalRenamingCallback(
|
||||
CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback) final;
|
||||
void setRefactoringEngine(ClangRefactoring::RefactoringEngine *refactoringEngine);
|
||||
void setSearchHandle(ClangRefactoring::SearchHandleInterface *searchHandleInterface);
|
||||
ClangRefactoring::SearchHandleInterface *searchHandle() const;
|
||||
void setSearchHandle(ClangRefactoring::SearchHandle *searchHandleInterface);
|
||||
ClangRefactoring::SearchHandle *searchHandle() const;
|
||||
|
||||
bool hasValidLocalRenamingCallback() const;
|
||||
|
||||
static std::unordered_map<uint, QString> convertFilePaths(
|
||||
const std::unordered_map<uint, ClangBackEnd::FilePath> &filePaths);
|
||||
|
||||
private:
|
||||
void addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges);
|
||||
void setExpectedResultCount(uint count);
|
||||
uint expectedResultCount() const;
|
||||
uint resultCounter() const;
|
||||
|
||||
|
||||
UNIT_TEST_PUBLIC:
|
||||
void addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRange,
|
||||
std::unordered_map<uint, QString> &filePaths);
|
||||
|
||||
private:
|
||||
void addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges);
|
||||
|
||||
void setResultCounterAndSendSearchIsFinishedIfFinished();
|
||||
void sendSearchIsFinished();
|
||||
|
||||
private:
|
||||
CppTools::RefactoringEngineInterface::RenameCallback localRenamingCallback;
|
||||
ClangRefactoring::SearchHandleInterface *searchHandleInterface = nullptr;
|
||||
ClangRefactoring::SearchHandle *searchHandle_ = nullptr;
|
||||
ClangRefactoring::RefactoringEngine *refactoringEngine = nullptr;
|
||||
uint expectedResultCount_ = 0;
|
||||
uint resultCounter_ = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
44
src/plugins/clangrefactoring/searchhandle.cpp
Normal file
44
src/plugins/clangrefactoring/searchhandle.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "searchhandle.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
SearchHandle::~SearchHandle()
|
||||
{
|
||||
}
|
||||
|
||||
void SearchHandle::cancel()
|
||||
{
|
||||
server->cancel();
|
||||
}
|
||||
|
||||
void SearchHandle::setRefactoringServer(ClangBackEnd::RefactoringServerInterface *server)
|
||||
{
|
||||
this->server = server;
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
56
src/plugins/clangrefactoring/searchhandle.h
Normal file
56
src/plugins/clangrefactoring/searchhandle.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/find/searchresultitem.h>
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class SearchHandle
|
||||
{
|
||||
public:
|
||||
virtual ~SearchHandle();
|
||||
|
||||
virtual void addResult(const QString &fileName,
|
||||
const QString &lineText,
|
||||
Core::Search::TextRange textRange) = 0;
|
||||
|
||||
virtual void setExpectedResultCount(uint count) = 0;
|
||||
virtual void setResultCounter(uint counter) = 0;
|
||||
|
||||
virtual void finishSearch() = 0;
|
||||
|
||||
void cancel();
|
||||
|
||||
void setRefactoringServer(ClangBackEnd::RefactoringServerInterface *server);
|
||||
|
||||
private:
|
||||
ClangBackEnd::RefactoringServerInterface *server = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -27,13 +27,18 @@
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
SearchHandleInterface::SearchHandleInterface()
|
||||
SearchHandle::~SearchHandle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SearchHandleInterface::~SearchHandleInterface()
|
||||
void SearchHandle::cancel()
|
||||
{
|
||||
server->cancel();
|
||||
}
|
||||
|
||||
void SearchHandle::setRefactoringServer(ClangBackEnd::RefactoringServerInterface *server)
|
||||
{
|
||||
this->server = server;
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -25,23 +25,32 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <coreplugin/find/searchresultitem.h>
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class SearchHandleInterface
|
||||
class SearchHandle
|
||||
{
|
||||
public:
|
||||
SearchHandleInterface();
|
||||
virtual ~SearchHandleInterface();
|
||||
virtual ~SearchHandle();
|
||||
|
||||
virtual void addResult(const QString &fileName,
|
||||
int lineNumber,
|
||||
const QString &lineText,
|
||||
int searchTermStart,
|
||||
int searchTermLength) = 0;
|
||||
Core::Search::TextRange textRange) = 0;
|
||||
|
||||
virtual void setExpectedResultCount(uint count) = 0;
|
||||
virtual void setResultCounter(uint counter) = 0;
|
||||
|
||||
virtual void finishSearch() = 0;
|
||||
|
||||
void cancel();
|
||||
|
||||
void setRefactoringServer(ClangBackEnd::RefactoringServerInterface *server);
|
||||
|
||||
private:
|
||||
ClangBackEnd::RefactoringServerInterface *server = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -27,5 +27,9 @@
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
SearchInterface::~SearchInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "searchhandleinterface.h"
|
||||
#include "searchhandle.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
@@ -36,9 +36,8 @@ namespace ClangRefactoring {
|
||||
class SearchInterface
|
||||
{
|
||||
public:
|
||||
virtual ~SearchInterface() {}
|
||||
|
||||
virtual std::unique_ptr<SearchHandleInterface> startNewSearch(const QString &searchLabel,
|
||||
virtual ~SearchInterface();
|
||||
virtual std::unique_ptr<SearchHandle> startNewSearch(const QString &searchLabel,
|
||||
const QString &searchTerm) = 0;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user