forked from qt-creator/qt-creator
Clang: use local renaming based on ClangCodeModel
Provide refactoring engine for ClangCodeModel and implement missing methods. Change-Id: If5c913e0c5a7941cd2ced54d0fcfa4d625eadc93 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -377,7 +377,19 @@ QFuture<CppTools::CursorInfo> BackendCommunicator::requestReferences(
|
||||
m_sender->requestReferences(message);
|
||||
|
||||
return m_receiver.addExpectedReferencesMessage(message.ticketNumber(), textDocument,
|
||||
localUses);
|
||||
localUses);
|
||||
}
|
||||
|
||||
QFuture<CppTools::CursorInfo> BackendCommunicator::requestLocalReferences(
|
||||
const FileContainer &fileContainer,
|
||||
quint32 line,
|
||||
quint32 column,
|
||||
QTextDocument *textDocument)
|
||||
{
|
||||
const RequestReferencesMessage message(fileContainer, line, column, true);
|
||||
m_sender->requestReferences(message);
|
||||
|
||||
return m_receiver.addExpectedReferencesMessage(message.ticketNumber(), textDocument);
|
||||
}
|
||||
|
||||
QFuture<CppTools::SymbolInfo> BackendCommunicator::requestFollowSymbol(
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
using FileContainer = ClangBackEnd::FileContainer;
|
||||
using FileContainers = QVector<ClangBackEnd::FileContainer>;
|
||||
using ProjectPartContainers = QVector<ClangBackEnd::ProjectPartContainer>;
|
||||
using LocalUseMap = CppTools::SemanticInfo::LocalUseMap;
|
||||
|
||||
public:
|
||||
BackendCommunicator();
|
||||
@@ -75,7 +76,12 @@ public:
|
||||
quint32 line,
|
||||
quint32 column,
|
||||
QTextDocument *textDocument,
|
||||
const CppTools::SemanticInfo::LocalUseMap &localUses);
|
||||
const LocalUseMap &localUses);
|
||||
QFuture<CppTools::CursorInfo> requestLocalReferences(
|
||||
const FileContainer &fileContainer,
|
||||
quint32 line,
|
||||
quint32 column,
|
||||
QTextDocument *textDocument);
|
||||
QFuture<CppTools::SymbolInfo> requestFollowSymbol(const FileContainer &curFileContainer,
|
||||
const QVector<Utf8String> &dependentFiles,
|
||||
quint32 line,
|
||||
|
||||
@@ -56,7 +56,8 @@ public:
|
||||
QFuture<CppTools::CursorInfo>
|
||||
addExpectedReferencesMessage(quint64 ticket,
|
||||
QTextDocument *textDocument,
|
||||
const CppTools::SemanticInfo::LocalUseMap &localUses);
|
||||
const CppTools::SemanticInfo::LocalUseMap &localUses
|
||||
= CppTools::SemanticInfo::LocalUseMap());
|
||||
QFuture<CppTools::SymbolInfo> addExpectedRequestFollowSymbolMessage(quint64 ticket);
|
||||
bool isExpectingCodeCompletedMessage() const;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ SOURCES += \
|
||||
clangpreprocessorassistproposalitem.cpp \
|
||||
clangprojectsettings.cpp \
|
||||
clangprojectsettingswidget.cpp \
|
||||
clangrefactoringengine.cpp \
|
||||
clangtextmark.cpp \
|
||||
clanguiheaderondiskmanager.cpp \
|
||||
clangutils.cpp
|
||||
@@ -69,6 +70,7 @@ HEADERS += \
|
||||
clangpreprocessorassistproposalitem.h \
|
||||
clangprojectsettings.h \
|
||||
clangprojectsettingswidget.h \
|
||||
clangrefactoringengine.h \
|
||||
clangtextmark.h \
|
||||
clanguiheaderondiskmanager.h \
|
||||
clangutils.h
|
||||
|
||||
@@ -92,6 +92,8 @@ QtcPlugin {
|
||||
"clangprojectsettingswidget.cpp",
|
||||
"clangprojectsettingswidget.h",
|
||||
"clangprojectsettingswidget.ui",
|
||||
"clangrefactoringengine.cpp",
|
||||
"clangrefactoringengine.h",
|
||||
"clangtextmark.cpp",
|
||||
"clangtextmark.h",
|
||||
"clanguiheaderondiskmanager.cpp",
|
||||
|
||||
@@ -350,6 +350,23 @@ ClangEditorDocumentProcessor::cursorInfo(const CppTools::CursorInfoParams ¶m
|
||||
localUses);
|
||||
}
|
||||
|
||||
QFuture<CppTools::CursorInfo> ClangEditorDocumentProcessor::requestLocalReferences(
|
||||
const QTextCursor &cursor)
|
||||
{
|
||||
int line, column;
|
||||
convertPosition(cursor, &line, &column);
|
||||
++column; // for 1-based columns
|
||||
|
||||
// TODO: check that by highlighting items
|
||||
if (!isCursorOnIdentifier(cursor))
|
||||
return defaultCursorInfoFuture();
|
||||
|
||||
return m_communicator.requestLocalReferences(simpleFileContainer(),
|
||||
static_cast<quint32>(line),
|
||||
static_cast<quint32>(column),
|
||||
textDocument());
|
||||
}
|
||||
|
||||
static QVector<Utf8String> prioritizeByBaseName(const QString &curPath,
|
||||
const ::Utils::FileNameList &fileDeps)
|
||||
{
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
void setParserConfig(const CppTools::BaseEditorDocumentParser::Configuration config) override;
|
||||
|
||||
QFuture<CppTools::CursorInfo> cursorInfo(const CppTools::CursorInfoParams ¶ms) override;
|
||||
QFuture<CppTools::CursorInfo> requestLocalReferences(const QTextCursor &cursor) override;
|
||||
QFuture<CppTools::SymbolInfo> requestFollowSymbol(int line, int column) override;
|
||||
|
||||
ClangBackEnd::FileContainer fileContainerWithArguments() const;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "clangutils.h"
|
||||
#include "clangfollowsymbol.h"
|
||||
#include "clangrefactoringengine.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <cpptools/cppfollowsymbolundercursor.h>
|
||||
@@ -67,6 +68,7 @@ static CppTools::CppModelManager *cppModelManager()
|
||||
|
||||
ModelManagerSupportClang::ModelManagerSupportClang()
|
||||
: m_completionAssistProvider(m_communicator)
|
||||
, m_refactoringEngine(new RefactoringEngine)
|
||||
{
|
||||
QTC_CHECK(!m_instance);
|
||||
m_instance = this;
|
||||
@@ -114,6 +116,11 @@ CppTools::FollowSymbolInterface &ModelManagerSupportClang::followSymbolInterface
|
||||
return *m_followSymbol;
|
||||
}
|
||||
|
||||
CppTools::RefactoringEngineInterface &ModelManagerSupportClang::refactoringEngineInterface()
|
||||
{
|
||||
return *m_refactoringEngine;
|
||||
}
|
||||
|
||||
CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::editorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,10 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class IDocument; }
|
||||
namespace TextEditor { class TextEditorWidget; }
|
||||
namespace CppTools { class FollowSymbolInterface; }
|
||||
namespace CppTools {
|
||||
class FollowSymbolInterface;
|
||||
class RefactoringEngineInterface;
|
||||
} // namespace CppTools
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
@@ -61,6 +64,7 @@ public:
|
||||
CppTools::BaseEditorDocumentProcessor *editorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument) override;
|
||||
CppTools::FollowSymbolInterface &followSymbolInterface() override;
|
||||
CppTools::RefactoringEngineInterface &refactoringEngineInterface() override;
|
||||
|
||||
BackendCommunicator &communicator();
|
||||
QString dummyUiHeaderOnDiskDirPath() const;
|
||||
@@ -105,6 +109,7 @@ private:
|
||||
BackendCommunicator m_communicator;
|
||||
ClangCompletionAssistProvider m_completionAssistProvider;
|
||||
std::unique_ptr<CppTools::FollowSymbolInterface> m_followSymbol;
|
||||
std::unique_ptr<CppTools::RefactoringEngineInterface> m_refactoringEngine;
|
||||
};
|
||||
|
||||
class ModelManagerSupportProviderClang : public CppTools::ModelManagerSupportProvider
|
||||
|
||||
78
src/plugins/clangcodemodel/clangrefactoringengine.cpp
Normal file
78
src/plugins/clangcodemodel/clangrefactoringengine.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "clangrefactoringengine.h"
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
||||
CppTools::ProjectPart *projectPart,
|
||||
RenameCallback &&renameSymbolsCallback)
|
||||
{
|
||||
Internal::ClangEditorDocumentProcessor *processor = Internal::ClangEditorDocumentProcessor::get(
|
||||
data.filePath().toString());
|
||||
const int startRevision = data.cursor().document()->revision();
|
||||
|
||||
using ClangBackEnd::SourceLocationsContainer;
|
||||
auto defaultCallback = [renameSymbolsCallback, startRevision]() {
|
||||
return renameSymbolsCallback(QString(), SourceLocationsContainer{}, startRevision);
|
||||
};
|
||||
|
||||
if (!processor)
|
||||
return defaultCallback();
|
||||
|
||||
QFuture<CppTools::CursorInfo> future = processor->requestLocalReferences(data.cursor());
|
||||
if (future.isCanceled())
|
||||
return defaultCallback();
|
||||
|
||||
// QFuture::waitForFinished seems to block completely, not even
|
||||
// allowing to process events from QLocalSocket.
|
||||
while (!future.isFinished()) {
|
||||
if (future.isCanceled())
|
||||
return defaultCallback();
|
||||
|
||||
QTC_ASSERT(startRevision == data.cursor().document()->revision(), return;);
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
|
||||
const CppTools::CursorInfo info = future.result();
|
||||
if (info.useRanges.empty())
|
||||
return defaultCallback();
|
||||
|
||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
|
||||
info.useRanges.first().length);
|
||||
const QString symbolName = cursor.selectedText();
|
||||
ClangBackEnd::SourceLocationsContainer container;
|
||||
for (auto& use : info.useRanges)
|
||||
container.insertSourceLocation(ClangBackEnd::FilePathId(), use.line, use.column, use.length);
|
||||
renameSymbolsCallback(symbolName, container, data.cursor().document()->revision());
|
||||
}
|
||||
|
||||
}
|
||||
48
src/plugins/clangcodemodel/clangrefactoringengine.h
Normal file
48
src/plugins/clangcodemodel/clangrefactoringengine.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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/refactoringengineinterface.h>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class RefactoringClientInterface;
|
||||
class RefactoringServerInterface;
|
||||
}
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
class RefactoringEngine : public CppTools::RefactoringEngineInterface
|
||||
{
|
||||
public:
|
||||
void startLocalRenaming(const CppTools::CursorInEditor &data,
|
||||
CppTools::ProjectPart *projectPart,
|
||||
RenameCallback &&renameSymbolsCallback) override;
|
||||
void globalRename(const CppTools::CursorInEditor &, CppTools::UsagesCallback &&,
|
||||
const QString &) override {}
|
||||
void findUsages(const CppTools::CursorInEditor &, CppTools::UsagesCallback &&) const override {}
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
Reference in New Issue
Block a user