forked from qt-creator/qt-creator
Clang: Add clang query
Clang query is mechanism to use AST matcher to search for code. Think about regular expression but in the context of AST. So you get a semantic search tool for C++. Change-Id: I72e882c5b53a0c52f352a3664847c4c3e4f6fc2e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
128
src/plugins/clangrefactoring/clangquerycurrentfilefindfilter.cpp
Normal file
128
src/plugins/clangrefactoring/clangquerycurrentfilefindfilter.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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));
|
||||
|
||||
commandLine.push_back(currentDocumentFilePath);
|
||||
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "clangqueryprojectsfindfilter.h"
|
||||
|
||||
#include "refactoringclient.h"
|
||||
#include "searchinterface.h"
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
ClangQueryProjectsFindFilter::ClangQueryProjectsFindFilter(
|
||||
ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient)
|
||||
: server(server),
|
||||
searchInterface(searchInterface),
|
||||
refactoringClient(refactoringClient)
|
||||
{
|
||||
}
|
||||
|
||||
QString ClangQueryProjectsFindFilter::id() const
|
||||
{
|
||||
return QStringLiteral("Clang Query Project");
|
||||
}
|
||||
|
||||
QString ClangQueryProjectsFindFilter::displayName() const
|
||||
{
|
||||
return tr("Clang Query Project");
|
||||
}
|
||||
|
||||
bool ClangQueryProjectsFindFilter::isEnabled() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClangQueryProjectsFindFilter::findAll(const QString &queryText, Core::FindFlags)
|
||||
{
|
||||
searchHandle = searchInterface.startNewSearch(tr("Clang Query"), queryText);
|
||||
|
||||
refactoringClient.setSearchHandle(searchHandle.get());
|
||||
|
||||
//server.requestSourceRangesAndDiagnosticsForQueryMessage(createMessage(queryText));
|
||||
}
|
||||
|
||||
Core::FindFlags ClangQueryProjectsFindFilter::supportedFindFlags() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ClangQueryProjectsFindFilter::isUsable() const
|
||||
{
|
||||
return server.isUsable();
|
||||
}
|
||||
|
||||
void ClangQueryProjectsFindFilter::setUsable(bool isUsable)
|
||||
{
|
||||
server.setUsable(isUsable);
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
67
src/plugins/clangrefactoring/clangqueryprojectsfindfilter.h
Normal file
67
src/plugins/clangrefactoring/clangqueryprojectsfindfilter.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <coreplugin/find/ifindfilter.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class RefactoringServerInterface;
|
||||
class RequestSourceRangesAndDiagnosticsForQueryMessage;
|
||||
}
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class RefactoringClient;
|
||||
class SearchInterface;
|
||||
|
||||
class ClangQueryProjectsFindFilter : public Core::IFindFilter
|
||||
{
|
||||
public:
|
||||
ClangQueryProjectsFindFilter(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;
|
||||
|
||||
bool isUsable() const;
|
||||
void setUsable(bool isUsable);
|
||||
|
||||
private:
|
||||
std::unique_ptr<SearchHandleInterface> searchHandle;
|
||||
ClangBackEnd::RefactoringServerInterface &server;
|
||||
SearchInterface &searchInterface;
|
||||
RefactoringClient &refactoringClient;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -4,10 +4,20 @@ HEADERS += \
|
||||
$$PWD/refactoringengine.h \
|
||||
$$PWD/refactoringconnectionclient.h \
|
||||
$$PWD/refactoringcompileroptionsbuilder.h \
|
||||
$$PWD/refactoringclient.h
|
||||
$$PWD/refactoringclient.h \
|
||||
$$PWD/searchinterface.h \
|
||||
$$PWD/searchhandleinterface.h \
|
||||
$$PWD/projectpartutilities.h \
|
||||
$$PWD/clangquerycurrentfilefindfilter.h \
|
||||
$$PWD/clangqueryprojectsfindfilter.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/refactoringengine.cpp \
|
||||
$$PWD/refactoringconnectionclient.cpp \
|
||||
$$PWD/refactoringcompileroptionsbuilder.cpp \
|
||||
$$PWD/refactoringclient.cpp
|
||||
$$PWD/refactoringclient.cpp \
|
||||
$$PWD/searchinterface.cpp \
|
||||
$$PWD/searchhandleinterface.cpp \
|
||||
$$PWD/projectpartutilities.cpp \
|
||||
$$PWD/clangquerycurrentfilefindfilter.cpp \
|
||||
$$PWD/clangqueryprojectsfindfilter.cpp
|
||||
|
||||
@@ -5,7 +5,13 @@ include(../../shared/clang/clang_installation.pri)
|
||||
include(../../shared/clang/clang_defines.pri)
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/clangrefactoringplugin.h
|
||||
$$PWD/clangrefactoringplugin.h \
|
||||
qtcreatorsearch.h \
|
||||
qtcreatorsearchhandle.h \
|
||||
qtcreatorclangqueryfindfilter.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/clangrefactoringplugin.cpp
|
||||
$$PWD/clangrefactoringplugin.cpp \
|
||||
qtcreatorsearch.cpp \
|
||||
qtcreatorsearchhandle.cpp \
|
||||
qtcreatorclangqueryfindfilter.cpp
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
@@ -44,17 +46,24 @@ QString backendProcessPath()
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
std::unique_ptr<RefactoringClient> ClangRefactoringPlugin::client;
|
||||
std::unique_ptr<RefactoringClient> ClangRefactoringPlugin::refactoringClient;
|
||||
std::unique_ptr<ClangBackEnd::RefactoringConnectionClient> ClangRefactoringPlugin::connectionClient;
|
||||
std::unique_ptr<RefactoringEngine> ClangRefactoringPlugin::engine;
|
||||
std::unique_ptr<QtCreatorSearch> ClangRefactoringPlugin::qtCreatorSearch;
|
||||
std::unique_ptr<QtCreatorClangQueryFindFilter> ClangRefactoringPlugin::qtCreatorfindFilter;
|
||||
|
||||
bool ClangRefactoringPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/)
|
||||
{
|
||||
client.reset(new RefactoringClient);
|
||||
connectionClient.reset(new ClangBackEnd::RefactoringConnectionClient(client.get()));
|
||||
engine.reset(new RefactoringEngine(connectionClient->serverProxy(), *client));
|
||||
refactoringClient.reset(new RefactoringClient);
|
||||
connectionClient.reset(new ClangBackEnd::RefactoringConnectionClient(refactoringClient.get()));
|
||||
engine.reset(new RefactoringEngine(connectionClient->serverProxy(), *refactoringClient));
|
||||
qtCreatorSearch.reset(new ClangRefactoring::QtCreatorSearch(*Core::SearchResultWindow::instance()));
|
||||
qtCreatorfindFilter.reset(new QtCreatorClangQueryFindFilter(connectionClient->serverProxy(),
|
||||
*qtCreatorSearch.get(),
|
||||
*refactoringClient));
|
||||
|
||||
client->setRefactoringEngine(engine.get());
|
||||
refactoringClient->setRefactoringEngine(engine.get());
|
||||
ExtensionSystem::PluginManager::addObject(qtCreatorfindFilter.get());
|
||||
|
||||
connectBackend();
|
||||
startBackend();
|
||||
@@ -69,13 +78,15 @@ void ClangRefactoringPlugin::extensionsInitialized()
|
||||
|
||||
ExtensionSystem::IPlugin::ShutdownFlag ClangRefactoringPlugin::aboutToShutdown()
|
||||
{
|
||||
client->setRefactoringEngine(nullptr);
|
||||
ExtensionSystem::PluginManager::removeObject(qtCreatorfindFilter.get());
|
||||
refactoringClient->setRefactoringEngine(nullptr);
|
||||
|
||||
connectionClient->finishProcess();
|
||||
|
||||
qtCreatorfindFilter.reset();
|
||||
engine.reset();
|
||||
connectionClient.reset();
|
||||
client.reset();
|
||||
refactoringClient.reset();
|
||||
|
||||
return SynchronousShutdown;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "refactoringengine.h"
|
||||
#include "refactoringclient.h"
|
||||
#include "qtcreatorclangqueryfindfilter.h"
|
||||
#include "qtcreatorsearch.h"
|
||||
|
||||
#include <refactoringconnectionclient.h>
|
||||
#include <refactoringserverproxy.h>
|
||||
@@ -56,8 +58,11 @@ private:
|
||||
|
||||
private:
|
||||
static std::unique_ptr<ClangBackEnd::RefactoringConnectionClient> connectionClient;
|
||||
static std::unique_ptr<RefactoringClient> client;
|
||||
static std::unique_ptr<RefactoringClient> refactoringClient;
|
||||
static std::unique_ptr<RefactoringEngine> engine;
|
||||
static std::unique_ptr<QtCreatorClangQueryFindFilter> qtCreatorfindFilter;
|
||||
static std::unique_ptr<QtCreatorSearch> qtCreatorSearch;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
47
src/plugins/clangrefactoring/projectpartutilities.cpp
Normal file
47
src/plugins/clangrefactoring/projectpartutilities.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "projectpartutilities.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
CppTools::ProjectFile::Kind fileKindInProjectPart(CppTools::ProjectPart *projectPart,
|
||||
const QString &filePath)
|
||||
{
|
||||
const auto &projectFiles = projectPart->files;
|
||||
|
||||
auto comparePaths = [&] (const CppTools::ProjectFile &projectFile) {
|
||||
return projectFile.path == filePath;
|
||||
};
|
||||
|
||||
auto found = std::find_if(projectFiles.begin(), projectFiles.end(), comparePaths);
|
||||
|
||||
if (found != projectFiles.end())
|
||||
return found->kind;
|
||||
|
||||
return CppTools::ProjectFile::Unclassified;
|
||||
}
|
||||
|
||||
}
|
||||
35
src/plugins/clangrefactoring/projectpartutilities.h
Normal file
35
src/plugins/clangrefactoring/projectpartutilities.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <cpptools/projectpart.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
CppTools::ProjectFile::Kind fileKindInProjectPart(CppTools::ProjectPart *projectPart,
|
||||
const QString &filePath);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qtcreatorclangqueryfindfilter.h"
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/baseeditordocumentparser.h>
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
QtCreatorClangQueryFindFilter::QtCreatorClangQueryFindFilter(ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient)
|
||||
: ClangQueryCurrentFileFindFilter(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);
|
||||
}
|
||||
|
||||
void QtCreatorClangQueryFindFilter::prepareFind()
|
||||
{
|
||||
Core::IEditor *currentEditor = Core::EditorManager::currentEditor();
|
||||
|
||||
if (isCppEditor(currentEditor)) {
|
||||
Core::IDocument *currentDocument = currentEditor->document();
|
||||
auto currentTextDocument = static_cast<TextEditor::TextDocument*>(currentDocument);
|
||||
const QString filePath = currentDocument->filePath().toString();
|
||||
|
||||
setCurrentDocumentFilePath(filePath);
|
||||
setCurrentDocumentRevision(currentTextDocument->document()->revision());
|
||||
setProjectPart(projectPartForFile(filePath));
|
||||
|
||||
if (currentTextDocument->isModified())
|
||||
setUnsavedDocumentContent(currentTextDocument->document()->toPlainText());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
45
src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.h
Normal file
45
src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "clangquerycurrentfilefindfilter.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorClangQueryFindFilter final : public ClangQueryCurrentFileFindFilter
|
||||
{
|
||||
public:
|
||||
QtCreatorClangQueryFindFilter(ClangBackEnd::RefactoringServerInterface &server,
|
||||
SearchInterface &searchInterface,
|
||||
RefactoringClient &refactoringClient);
|
||||
|
||||
void findAll(const QString &queryText, Core::FindFlags findFlags = 0);
|
||||
|
||||
private:
|
||||
void prepareFind();
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
50
src/plugins/clangrefactoring/qtcreatorsearch.cpp
Normal file
50
src/plugins/clangrefactoring/qtcreatorsearch.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qtcreatorsearch.h"
|
||||
|
||||
#include "qtcreatorsearchhandle.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
QtCreatorSearch::QtCreatorSearch(Core::SearchResultWindow &searchResultWindow)
|
||||
: searchResultWindow(searchResultWindow)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<SearchHandleInterface> QtCreatorSearch::startNewSearch(const QString &searchLabel,
|
||||
const QString &searchTerm)
|
||||
{
|
||||
Core::SearchResult *searchResult = searchResultWindow.startNewSearch(
|
||||
searchLabel,
|
||||
{},
|
||||
searchTerm,
|
||||
Core::SearchResultWindow::SearchOnly,
|
||||
Core::SearchResultWindow::PreserveCaseEnabled);
|
||||
|
||||
return std::unique_ptr<SearchHandleInterface>(new QtCreatorSearchHandle(searchResult));
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
46
src/plugins/clangrefactoring/qtcreatorsearch.h
Normal file
46
src/plugins/clangrefactoring/qtcreatorsearch.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "searchinterface.h"
|
||||
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorSearch final : public SearchInterface
|
||||
{
|
||||
public:
|
||||
QtCreatorSearch(Core::SearchResultWindow &searchResultWindow);
|
||||
|
||||
std::unique_ptr<SearchHandleInterface> startNewSearch(const QString &searchLabel,
|
||||
const QString &searchTerm);
|
||||
|
||||
private:
|
||||
Core::SearchResultWindow &searchResultWindow;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
45
src/plugins/clangrefactoring/qtcreatorsearchhandle.cpp
Normal file
45
src/plugins/clangrefactoring/qtcreatorsearchhandle.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qtcreatorsearchhandle.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
QtCreatorSearchHandle::QtCreatorSearchHandle(Core::SearchResult *searchResult)
|
||||
: searchResult(searchResult)
|
||||
{
|
||||
}
|
||||
|
||||
void QtCreatorSearchHandle::addResult(const QString &fileName, int lineNumber, const QString &lineText, int searchTermStart, int searchTermLength)
|
||||
{
|
||||
searchResult->addResult(fileName, lineNumber, lineText, searchTermStart, searchTermLength);
|
||||
}
|
||||
|
||||
void QtCreatorSearchHandle::finishSearch()
|
||||
{
|
||||
searchResult->finishSearch(false);
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
51
src/plugins/clangrefactoring/qtcreatorsearchhandle.h
Normal file
51
src/plugins/clangrefactoring/qtcreatorsearchhandle.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <coreplugin/find/searchresultwindow.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class QtCreatorSearchHandle final : public SearchHandleInterface
|
||||
{
|
||||
public:
|
||||
QtCreatorSearchHandle(Core::SearchResult *searchResult);
|
||||
|
||||
void addResult(const QString &fileName,
|
||||
int lineNumber,
|
||||
const QString &lineText,
|
||||
int searchTermStart,
|
||||
int searchTermLength);
|
||||
|
||||
void finishSearch();
|
||||
|
||||
private:
|
||||
Core::SearchResult *searchResult;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "refactoringclient.h"
|
||||
|
||||
#include <sourcelocationsforrenamingmessage.h>
|
||||
#include <sourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
@@ -34,7 +35,8 @@ void RefactoringClient::alive()
|
||||
|
||||
}
|
||||
|
||||
void RefactoringClient::sourceLocationsForRenamingMessage(ClangBackEnd::SourceLocationsForRenamingMessage &&message)
|
||||
void RefactoringClient::sourceLocationsForRenamingMessage(
|
||||
ClangBackEnd::SourceLocationsForRenamingMessage &&message)
|
||||
{
|
||||
localRenamingCallback(message.symbolName().toQString(),
|
||||
message.sourceLocations(),
|
||||
@@ -43,7 +45,15 @@ void RefactoringClient::sourceLocationsForRenamingMessage(ClangBackEnd::SourceLo
|
||||
refactoringEngine->setUsable(true);
|
||||
}
|
||||
|
||||
void RefactoringClient::setLocalRenamingCallback(CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback)
|
||||
void RefactoringClient::sourceRangesAndDiagnosticsForQueryMessage(
|
||||
ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message)
|
||||
{
|
||||
addSearchResults(message.sourceRanges());
|
||||
sendSearchIsFinished();
|
||||
}
|
||||
|
||||
void RefactoringClient::setLocalRenamingCallback(
|
||||
CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback)
|
||||
{
|
||||
this->localRenamingCallback = std::move(localRenamingCallback);
|
||||
}
|
||||
@@ -53,9 +63,75 @@ void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngin
|
||||
this->refactoringEngine = refactoringEngine;
|
||||
}
|
||||
|
||||
void RefactoringClient::setSearchHandle(SearchHandleInterface *searchHandleInterface)
|
||||
{
|
||||
this->searchHandleInterface = searchHandleInterface;
|
||||
}
|
||||
|
||||
SearchHandleInterface *RefactoringClient::searchHandle() const
|
||||
{
|
||||
return searchHandleInterface;
|
||||
}
|
||||
|
||||
bool RefactoringClient::hasValidLocalRenamingCallback() const
|
||||
{
|
||||
return bool(localRenamingCallback);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Utils::SmallString concatenateFilePath(const ClangBackEnd::FilePath &filePath)
|
||||
{
|
||||
Utils::SmallString concatenatedFilePath = filePath.directory().clone();
|
||||
concatenatedFilePath.append("/");
|
||||
concatenatedFilePath.append(filePath.name().clone());
|
||||
|
||||
return concatenatedFilePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::unordered_map<uint, QString> RefactoringClient::convertFilePaths(
|
||||
const ClangBackEnd::FilePathDict &filePaths)
|
||||
{
|
||||
using Dict = std::unordered_map<uint, QString>;
|
||||
Dict qstringFilePaths;
|
||||
qstringFilePaths.reserve(filePaths.size());
|
||||
|
||||
auto convertFilePath = [] (const ClangBackEnd::FilePathDict::value_type &dictonaryEntry) {
|
||||
return std::make_pair(dictonaryEntry.first,
|
||||
concatenateFilePath(dictonaryEntry.second).toQString());
|
||||
};
|
||||
|
||||
std::transform(filePaths.begin(),
|
||||
filePaths.end(),
|
||||
std::inserter(qstringFilePaths, qstringFilePaths.begin()),
|
||||
convertFilePath);
|
||||
|
||||
return qstringFilePaths;
|
||||
}
|
||||
|
||||
void RefactoringClient::addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges)
|
||||
{
|
||||
auto filePaths = convertFilePaths(sourceRanges.filePaths());
|
||||
|
||||
for (const auto &sourceRangeWithText : sourceRanges.sourceRangeWithTextContainers())
|
||||
addSearchResult(sourceRangeWithText, filePaths);
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
void RefactoringClient::sendSearchIsFinished()
|
||||
{
|
||||
searchHandleInterface->finishSearch();
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -27,25 +27,48 @@
|
||||
|
||||
#include "refactoringengine.h"
|
||||
|
||||
#include <searchhandleinterface.h>
|
||||
|
||||
#include <refactoringclientinterface.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class FilePath;
|
||||
class SourceRangesContainer;
|
||||
class SourceRangeWithTextContainer;
|
||||
}
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class RefactoringClient : public ClangBackEnd::RefactoringClientInterface
|
||||
class RefactoringClient final : public ClangBackEnd::RefactoringClientInterface
|
||||
{
|
||||
public:
|
||||
void alive() final;
|
||||
void sourceLocationsForRenamingMessage(ClangBackEnd::SourceLocationsForRenamingMessage &&message) final;
|
||||
void sourceLocationsForRenamingMessage(
|
||||
ClangBackEnd::SourceLocationsForRenamingMessage &&message) final;
|
||||
void sourceRangesAndDiagnosticsForQueryMessage(
|
||||
ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message) final;
|
||||
|
||||
void setLocalRenamingCallback(CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback) final;
|
||||
void setLocalRenamingCallback(
|
||||
CppTools::RefactoringEngineInterface::RenameCallback &&localRenamingCallback) final;
|
||||
void setRefactoringEngine(ClangRefactoring::RefactoringEngine *refactoringEngine);
|
||||
void setSearchHandle(ClangRefactoring::SearchHandleInterface *searchHandleInterface);
|
||||
ClangRefactoring::SearchHandleInterface *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 addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRange,
|
||||
std::unordered_map<uint, QString> &filePaths);
|
||||
void sendSearchIsFinished();
|
||||
private:
|
||||
CppTools::RefactoringEngineInterface::RenameCallback localRenamingCallback;
|
||||
ClangRefactoring::SearchHandleInterface *searchHandleInterface = nullptr;
|
||||
ClangRefactoring::RefactoringEngine *refactoringEngine = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "refactoringengine.h"
|
||||
|
||||
#include "projectpartutilities.h"
|
||||
|
||||
#include <refactoringcompileroptionsbuilder.h>
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
@@ -46,55 +48,22 @@ RefactoringEngine::RefactoringEngine(ClangBackEnd::RefactoringServerInterface &s
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
ClangBackEnd::FilePath convertToClangBackEndFilePath(const Utils::FileName &filePath)
|
||||
{
|
||||
Utils::SmallString utf8FilePath = filePath.toString();
|
||||
|
||||
auto found = std::find(utf8FilePath.rbegin(), utf8FilePath.rend(), '/').base();
|
||||
|
||||
Utils::SmallString fileName(found, utf8FilePath.end());
|
||||
utf8FilePath.resize(std::size_t(std::distance(utf8FilePath.begin(), --found)));
|
||||
|
||||
return ClangBackEnd::FilePath(std::move(utf8FilePath), std::move(fileName));
|
||||
}
|
||||
|
||||
CppTools::ProjectFile::Kind fileKind(CppTools::ProjectPart *projectPart, const QString &filePath)
|
||||
{
|
||||
const auto &projectFiles = projectPart->files;
|
||||
|
||||
auto comparePaths = [&] (const CppTools::ProjectFile &projectFile) {
|
||||
return projectFile.path == filePath;
|
||||
};
|
||||
|
||||
auto found = std::find_if(projectFiles.begin(), projectFiles.end(), comparePaths);
|
||||
|
||||
if (found != projectFiles.end())
|
||||
return found->kind;
|
||||
|
||||
return CppTools::ProjectFile::Unclassified;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RefactoringEngine::startLocalRenaming(const QTextCursor &textCursor,
|
||||
const Utils::FileName &filePath,
|
||||
int revision,
|
||||
CppTools::ProjectPart *projectPart,
|
||||
RenameCallback &&renameSymbolsCallback)
|
||||
{
|
||||
isUsable_ = false;
|
||||
setUsable(false);
|
||||
|
||||
client.setLocalRenamingCallback(std::move(renameSymbolsCallback));
|
||||
|
||||
auto commandLine = RefactoringCompilerOptionsBuilder::build(projectPart,
|
||||
fileKind(projectPart, filePath.toString()));
|
||||
fileKindInProjectPart(projectPart, filePath.toString()));
|
||||
|
||||
commandLine.push_back(filePath.toString());
|
||||
qDebug() << commandLine.join(" ");
|
||||
|
||||
RequestSourceLocationsForRenamingMessage message(convertToClangBackEndFilePath(filePath),
|
||||
RequestSourceLocationsForRenamingMessage message(ClangBackEnd::FilePath(filePath.toString()),
|
||||
uint(textCursor.blockNumber() + 1),
|
||||
uint(textCursor.positionInBlock() + 1),
|
||||
textCursor.document()->toPlainText(),
|
||||
@@ -107,12 +76,12 @@ void RefactoringEngine::startLocalRenaming(const QTextCursor &textCursor,
|
||||
|
||||
bool RefactoringEngine::isUsable() const
|
||||
{
|
||||
return isUsable_;
|
||||
return server.isUsable();
|
||||
}
|
||||
|
||||
void RefactoringEngine::setUsable(bool isUsable)
|
||||
{
|
||||
isUsable_ = isUsable;
|
||||
server.setUsable(isUsable);
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
@@ -51,7 +51,6 @@ public:
|
||||
private:
|
||||
ClangBackEnd::RefactoringServerInterface &server;
|
||||
ClangBackEnd::RefactoringClientInterface &client;
|
||||
bool isUsable_ = false;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
||||
39
src/plugins/clangrefactoring/searchhandleinterface.cpp
Normal file
39
src/plugins/clangrefactoring/searchhandleinterface.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "searchhandleinterface.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
SearchHandleInterface::SearchHandleInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SearchHandleInterface::~SearchHandleInterface()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
47
src/plugins/clangrefactoring/searchhandleinterface.h
Normal file
47
src/plugins/clangrefactoring/searchhandleinterface.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QString>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class SearchHandleInterface
|
||||
{
|
||||
public:
|
||||
SearchHandleInterface();
|
||||
virtual ~SearchHandleInterface();
|
||||
|
||||
virtual void addResult(const QString &fileName,
|
||||
int lineNumber,
|
||||
const QString &lineText,
|
||||
int searchTermStart,
|
||||
int searchTermLength) = 0;
|
||||
|
||||
virtual void finishSearch() = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
31
src/plugins/clangrefactoring/searchinterface.cpp
Normal file
31
src/plugins/clangrefactoring/searchinterface.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "searchinterface.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
45
src/plugins/clangrefactoring/searchinterface.h
Normal file
45
src/plugins/clangrefactoring/searchinterface.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class SearchInterface
|
||||
{
|
||||
public:
|
||||
virtual ~SearchInterface() {}
|
||||
|
||||
virtual std::unique_ptr<SearchHandleInterface> startNewSearch(const QString &searchLabel,
|
||||
const QString &searchTerm) = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
Reference in New Issue
Block a user