CppEditor: refactor FollowSymbol

Create an interface to get the ability to use
another FollowSymbol implementation

Change-Id: I5802f62523ff3ee47b8a14e487adf43edcb6c9b1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2017-08-03 16:43:38 +02:00
parent 76d12dc2d5
commit a137b08eaa
26 changed files with 442 additions and 164 deletions

View File

@@ -23,6 +23,7 @@ SOURCES += \
clangeditordocumentprocessor.cpp \
clangfixitoperation.cpp \
clangfixitoperationsextractor.cpp \
clangfollowsymbol.cpp \
clangfunctionhintmodel.cpp \
clanghighlightingmarksreporter.cpp \
clangmodelmanagersupport.cpp \
@@ -54,6 +55,7 @@ HEADERS += \
clangeditordocumentprocessor.h \
clangfixitoperation.h \
clangfixitoperationsextractor.h \
clangfollowsymbol.h \
clangfunctionhintmodel.h \
clanghighlightingmarksreporter.h \
clangisdiagnosticrelatedtolocation.h \

View File

@@ -71,6 +71,8 @@ QtcPlugin {
"clangfixitoperation.h",
"clangfixitoperationsextractor.cpp",
"clangfixitoperationsextractor.h",
"clangfollowsymbol.cpp",
"clangfollowsymbol.h",
"clangfunctionhintmodel.cpp",
"clangfunctionhintmodel.h",
"clanghighlightingmarksreporter.cpp",

View File

@@ -0,0 +1,83 @@
/****************************************************************************
**
** Copyright (C) 2017 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 "clangfollowsymbol.h"
#include "clangeditordocumentprocessor.h"
#include "texteditor/texteditor.h"
#include "texteditor/convenience.h"
namespace ClangCodeModel {
namespace Internal {
TextEditor::TextEditorWidget::Link ClangFollowSymbol::findLink(
const CppTools::CursorInEditor &data,
bool resolveTarget,
const CPlusPlus::Snapshot &,
const CPlusPlus::Document::Ptr &,
CppTools::SymbolFinder *,
bool)
{
Link link;
int lineNumber = 0, positionInBlock = 0;
QTextCursor cursor = TextEditor::Convenience::wordStartCursor(data.cursor());
TextEditor::Convenience::convertPosition(cursor.document(), cursor.position(), &lineNumber,
&positionInBlock);
const unsigned line = lineNumber;
const unsigned column = positionInBlock + 1;
if (!resolveTarget)
return link;
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(
data.filePath().toString());
if (!processor)
return link;
QFuture<CppTools::SymbolInfo> info
= processor->requestFollowSymbol(static_cast<int>(line),
static_cast<int>(column),
resolveTarget);
if (info.isCanceled())
return link;
while (!info.isFinished()) {
if (info.isCanceled())
return link;
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
CppTools::SymbolInfo result = info.result();
if (result.failedToFollow)
return link;
// We did not fail but the result is empty
if (result.fileName.isEmpty())
return link;
return Link(result.fileName, result.startLine, result.startColumn - 1);
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -0,0 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2017 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/followsymbolinterface.h>
namespace ClangCodeModel {
namespace Internal {
class ClangFollowSymbol : public CppTools::FollowSymbolInterface
{
public:
Link findLink(const CppTools::CursorInEditor &data,
bool resolveTarget,
const CPlusPlus::Snapshot &,
const CPlusPlus::Document::Ptr &,
CppTools::SymbolFinder *,
bool) override;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -28,6 +28,7 @@
#include "clangconstants.h"
#include "clangeditordocumentprocessor.h"
#include "clangutils.h"
#include "clangfollowsymbol.h"
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanager.h>
@@ -52,6 +53,12 @@ using namespace ClangCodeModel::Internal;
static ModelManagerSupportClang *m_instance = 0;
static bool useClangFollowSymbol()
{
static bool use = qEnvironmentVariableIntValue("QTC_CLANG_FOLLOW_SYMBOL");
return use;
}
static CppTools::CppModelManager *cppModelManager()
{
return CppTools::CppModelManager::instance();
@@ -63,6 +70,9 @@ ModelManagerSupportClang::ModelManagerSupportClang()
QTC_CHECK(!m_instance);
m_instance = this;
if (useClangFollowSymbol())
m_followSymbol.reset(new ClangFollowSymbol);
Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager, &Core::EditorManager::editorOpened,
this, &ModelManagerSupportClang::onEditorOpened);
@@ -96,6 +106,11 @@ CppTools::CppCompletionAssistProvider *ModelManagerSupportClang::completionAssis
return &m_completionAssistProvider;
}
CppTools::FollowSymbolInterface *ModelManagerSupportClang::followSymbolInterface()
{
return m_followSymbol.get();
}
CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::editorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument)
{

View File

@@ -33,6 +33,8 @@
#include <QObject>
#include <QScopedPointer>
#include <memory>
QT_BEGIN_NAMESPACE
class QMenu;
class QWidget;
@@ -44,6 +46,8 @@ namespace TextEditor { class TextEditorWidget; }
namespace ClangCodeModel {
namespace Internal {
class ClangFollowSymbol;
class ModelManagerSupportClang:
public QObject,
public CppTools::ModelManagerSupport
@@ -57,6 +61,7 @@ public:
CppTools::CppCompletionAssistProvider *completionAssistProvider() override;
CppTools::BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) override;
CppTools::FollowSymbolInterface *followSymbolInterface() override;
IpcCommunicator &ipcCommunicator();
QString dummyUiHeaderOnDiskDirPath() const;
@@ -100,6 +105,7 @@ private:
UiHeaderOnDiskManager m_uiHeaderOnDiskManager;
IpcCommunicator m_ipcCommunicator;
ClangCompletionAssistProvider m_completionAssistProvider;
std::unique_ptr<ClangFollowSymbol> m_followSymbol;
};
class ModelManagerSupportProviderClang : public CppTools::ModelManagerSupportProvider