2013-12-10 14:37:32 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-12-10 14:37:32 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-12-10 14:37:32 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-12-10 14:37:32 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
#include "clangmodelmanagersupport.h"
|
|
|
|
|
|
2015-11-30 09:43:50 +01:00
|
|
|
#include "clangconstants.h"
|
2014-08-19 15:59:29 +02:00
|
|
|
#include "clangeditordocumentprocessor.h"
|
2015-05-08 15:48:17 +02:00
|
|
|
#include "clangutils.h"
|
2017-08-03 16:43:38 +02:00
|
|
|
#include "clangfollowsymbol.h"
|
2018-01-12 12:29:43 +01:00
|
|
|
#include "clanghoverhandler.h"
|
2018-01-22 16:31:05 +01:00
|
|
|
#include "clangprojectsettings.h"
|
2017-09-26 16:00:30 +02:00
|
|
|
#include "clangrefactoringengine.h"
|
2017-11-24 10:46:31 +01:00
|
|
|
#include "clangcurrentdocumentfilter.h"
|
2018-02-06 08:19:42 +01:00
|
|
|
#include "clangoverviewmodel.h"
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2018-02-02 13:01:07 +01:00
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
#include <cpptools/cppcodemodelsettings.h>
|
2017-09-18 10:19:27 +02:00
|
|
|
#include <cpptools/cppfollowsymbolundercursor.h>
|
2015-12-15 11:59:48 +01:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2018-01-19 16:57:18 +01:00
|
|
|
#include <cpptools/cpptoolsreuse.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <cpptools/editordocumenthandle.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
|
|
|
|
|
2015-12-15 11:59:48 +01:00
|
|
|
#include <texteditor/quickfix.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2018-01-22 16:31:05 +01:00
|
|
|
#include <projectexplorer/session.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
|
2017-08-24 12:28:01 +02:00
|
|
|
#include <clangsupport/cmbregisterprojectsforeditormessage.h>
|
|
|
|
|
#include <clangsupport/filecontainer.h>
|
|
|
|
|
#include <clangsupport/projectpartcontainer.h>
|
2018-01-19 16:57:18 +01:00
|
|
|
#include <utils/algorithm.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2015-08-24 18:26:09 +02:00
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QTextBlock>
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
using namespace ClangCodeModel;
|
|
|
|
|
using namespace ClangCodeModel::Internal;
|
|
|
|
|
|
2016-11-21 13:30:26 +01:00
|
|
|
static ModelManagerSupportClang *m_instance = 0;
|
2013-12-10 14:37:32 +01:00
|
|
|
|
2017-08-03 16:43:38 +02:00
|
|
|
static bool useClangFollowSymbol()
|
|
|
|
|
{
|
|
|
|
|
static bool use = qEnvironmentVariableIntValue("QTC_CLANG_FOLLOW_SYMBOL");
|
|
|
|
|
return use;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
static CppTools::CppModelManager *cppModelManager()
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2015-05-08 15:48:17 +02:00
|
|
|
return CppTools::CppModelManager::instance();
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
ModelManagerSupportClang::ModelManagerSupportClang()
|
2017-09-25 15:10:48 +02:00
|
|
|
: m_completionAssistProvider(m_communicator)
|
2017-09-26 16:00:30 +02:00
|
|
|
, m_refactoringEngine(new RefactoringEngine)
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2016-11-21 13:30:26 +01:00
|
|
|
QTC_CHECK(!m_instance);
|
|
|
|
|
m_instance = this;
|
2015-05-08 15:48:17 +02:00
|
|
|
|
2017-08-03 16:43:38 +02:00
|
|
|
if (useClangFollowSymbol())
|
|
|
|
|
m_followSymbol.reset(new ClangFollowSymbol);
|
2017-09-18 10:19:27 +02:00
|
|
|
else
|
|
|
|
|
m_followSymbol.reset(new CppTools::FollowSymbolUnderCursor);
|
2017-08-03 16:43:38 +02:00
|
|
|
|
2017-11-27 15:51:18 +01:00
|
|
|
CppTools::CppModelManager::instance()->setCurrentDocumentFilter(
|
|
|
|
|
std::make_unique<ClangCurrentDocumentFilter>());
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
2016-01-11 13:05:04 +01:00
|
|
|
connect(editorManager, &Core::EditorManager::editorOpened,
|
|
|
|
|
this, &ModelManagerSupportClang::onEditorOpened);
|
2015-05-08 15:48:17 +02:00
|
|
|
connect(editorManager, &Core::EditorManager::currentEditorChanged,
|
2015-12-01 11:57:08 +01:00
|
|
|
this, &ModelManagerSupportClang::onCurrentEditorChanged,
|
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
connect(editorManager, &Core::EditorManager::editorsClosed,
|
|
|
|
|
this, &ModelManagerSupportClang::onEditorClosed,
|
|
|
|
|
Qt::QueuedConnection);
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
CppTools::CppModelManager *modelManager = cppModelManager();
|
2015-06-04 11:38:59 +02:00
|
|
|
connect(modelManager, &CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
|
|
|
|
|
this, &ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated);
|
|
|
|
|
connect(modelManager, &CppTools::CppModelManager::abstractEditorSupportRemoved,
|
|
|
|
|
this, &ModelManagerSupportClang::onAbstractEditorSupportRemoved);
|
2015-05-08 15:48:17 +02:00
|
|
|
connect(modelManager, &CppTools::CppModelManager::projectPartsUpdated,
|
|
|
|
|
this, &ModelManagerSupportClang::onProjectPartsUpdated);
|
|
|
|
|
connect(modelManager, &CppTools::CppModelManager::projectPartsRemoved,
|
|
|
|
|
this, &ModelManagerSupportClang::onProjectPartsRemoved);
|
2016-07-11 14:57:25 +02:00
|
|
|
|
2018-01-22 16:31:05 +01:00
|
|
|
auto *sessionManager = ProjectExplorer::SessionManager::instance();
|
|
|
|
|
connect(sessionManager, &ProjectExplorer::SessionManager::projectAdded,
|
|
|
|
|
this, &ModelManagerSupportClang::onProjectAdded);
|
|
|
|
|
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
|
|
|
|
|
this, &ModelManagerSupportClang::onAboutToRemoveProject);
|
|
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings().data();
|
|
|
|
|
connect(settings, &CppTools::CppCodeModelSettings::clangDiagnosticConfigsInvalidated,
|
|
|
|
|
this, &ModelManagerSupportClang::onDiagnosticConfigsInvalidated);
|
|
|
|
|
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.registerFallbackProjectPart();
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
ModelManagerSupportClang::~ModelManagerSupportClang()
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2018-01-22 16:31:05 +01:00
|
|
|
QTC_CHECK(m_projectSettings.isEmpty());
|
2016-11-21 13:30:26 +01:00
|
|
|
m_instance = 0;
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
CppTools::CppCompletionAssistProvider *ModelManagerSupportClang::completionAssistProvider()
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2015-06-16 13:59:08 +02:00
|
|
|
return &m_completionAssistProvider;
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 17:06:26 +01:00
|
|
|
TextEditor::BaseHoverHandler *ModelManagerSupportClang::createHoverHandler()
|
|
|
|
|
{
|
2018-01-12 12:29:43 +01:00
|
|
|
return new Internal::ClangHoverHandler;
|
2018-01-11 17:06:26 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-18 10:19:27 +02:00
|
|
|
CppTools::FollowSymbolInterface &ModelManagerSupportClang::followSymbolInterface()
|
2017-08-03 16:43:38 +02:00
|
|
|
{
|
2017-09-18 10:19:27 +02:00
|
|
|
return *m_followSymbol;
|
2017-08-03 16:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-26 16:00:30 +02:00
|
|
|
CppTools::RefactoringEngineInterface &ModelManagerSupportClang::refactoringEngineInterface()
|
|
|
|
|
{
|
|
|
|
|
return *m_refactoringEngine;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 13:01:07 +01:00
|
|
|
std::unique_ptr<CppTools::AbstractOverviewModel> ModelManagerSupportClang::createOverviewModel()
|
|
|
|
|
{
|
2018-02-06 08:19:42 +01:00
|
|
|
return std::make_unique<OverviewModel>();
|
2018-02-02 13:01:07 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:46:45 +01:00
|
|
|
CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::createEditorDocumentProcessor(
|
2014-09-22 18:43:31 +02:00
|
|
|
TextEditor::TextDocument *baseTextDocument)
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2017-09-25 15:10:48 +02:00
|
|
|
return new ClangEditorDocumentProcessor(m_communicator, baseTextDocument);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-01 15:05:31 +01:00
|
|
|
void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateTranslationUnitVisiblity();
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
void ModelManagerSupportClang::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
// Handle externally changed documents
|
2015-09-15 16:24:52 +02:00
|
|
|
connect(textDocument, &Core::IDocument::aboutToReload,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentAboutToReloadOnTranslationUnit,
|
|
|
|
|
Qt::UniqueConnection);
|
2015-08-31 16:10:36 +02:00
|
|
|
connect(textDocument, &Core::IDocument::reloadFinished,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit,
|
|
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
|
|
|
|
|
// Handle changes from e.g. refactoring actions
|
2015-09-15 16:24:52 +02:00
|
|
|
connectToTextDocumentContentsChangedForTranslationUnit(textDocument);
|
2015-08-31 16:10:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::connectTextDocumentToUnsavedFiles(TextEditor::TextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
// Handle externally changed documents
|
2015-09-15 16:24:52 +02:00
|
|
|
connect(textDocument, &Core::IDocument::aboutToReload,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentAboutToReloadOnUnsavedFile,
|
|
|
|
|
Qt::UniqueConnection);
|
2015-08-31 16:10:36 +02:00
|
|
|
connect(textDocument, &Core::IDocument::reloadFinished,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentReloadFinishedOnUnsavedFile,
|
|
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
|
|
|
|
|
// Handle changes from e.g. refactoring actions
|
2015-09-15 16:24:52 +02:00
|
|
|
connectToTextDocumentContentsChangedForUnsavedFile(textDocument);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::connectToTextDocumentContentsChangedForTranslationUnit(
|
|
|
|
|
TextEditor::TextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
connect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentContentsChangedOnTranslationUnit,
|
|
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::connectToTextDocumentContentsChangedForUnsavedFile(
|
|
|
|
|
TextEditor::TextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
connect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
2015-08-31 16:10:36 +02:00
|
|
|
this, &ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile,
|
|
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 18:26:09 +02:00
|
|
|
void ModelManagerSupportClang::connectToWidgetsMarkContextMenuRequested(QWidget *editorWidget)
|
|
|
|
|
{
|
|
|
|
|
const auto widget = qobject_cast<TextEditor::TextEditorWidget *>(editorWidget);
|
|
|
|
|
if (widget) {
|
|
|
|
|
connect(widget, &TextEditor::TextEditorWidget::markContextMenuRequested,
|
|
|
|
|
this, &ModelManagerSupportClang::onTextMarkContextMenuRequested);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
void ModelManagerSupportClang::onEditorOpened(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(editor, return);
|
|
|
|
|
Core::IDocument *document = editor->document();
|
|
|
|
|
QTC_ASSERT(document, return);
|
|
|
|
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(document);
|
|
|
|
|
|
2015-07-08 15:08:13 +02:00
|
|
|
if (textDocument && cppModelManager()->isCppEditor(editor)) {
|
2015-11-11 10:47:27 +01:00
|
|
|
connectTextDocumentToTranslationUnit(textDocument);
|
|
|
|
|
connectToWidgetsMarkContextMenuRequested(editor->widget());
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
// TODO: Ensure that not fully loaded documents are updated?
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-01 11:57:08 +01:00
|
|
|
void ModelManagerSupportClang::onEditorClosed(const QList<Core::IEditor *> &)
|
|
|
|
|
{
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateTranslationUnitVisiblity();
|
2015-12-01 11:57:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-15 16:24:52 +02:00
|
|
|
void ModelManagerSupportClang::onCppDocumentAboutToReloadOnTranslationUnit()
|
|
|
|
|
{
|
|
|
|
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
|
|
|
|
disconnect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentContentsChangedOnTranslationUnit);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
void ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool success)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2015-08-31 16:10:36 +02:00
|
|
|
if (success) {
|
2015-09-15 16:24:52 +02:00
|
|
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
|
|
|
|
connectToTextDocumentContentsChangedForTranslationUnit(textDocument);
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateTranslationUnitWithRevisionCheck(textDocument);
|
2015-08-31 16:10:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-05-08 15:48:17 +02:00
|
|
|
|
2015-11-25 15:11:23 +01:00
|
|
|
namespace {
|
|
|
|
|
void clearDiagnosticFixIts(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
auto processor = ClangEditorDocumentProcessor::get(filePath);
|
|
|
|
|
if (processor)
|
|
|
|
|
processor->clearDiagnosticsWithFixIts();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-28 17:42:43 +02:00
|
|
|
void ModelManagerSupportClang::onCppDocumentContentsChangedOnTranslationUnit(int position,
|
|
|
|
|
int /*charsRemoved*/,
|
|
|
|
|
int /*charsAdded*/)
|
2015-08-31 16:10:36 +02:00
|
|
|
{
|
2015-05-08 15:48:17 +02:00
|
|
|
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
|
2015-09-28 17:42:43 +02:00
|
|
|
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateChangeContentStartPosition(document->filePath().toString(),
|
2015-09-28 17:42:43 +02:00
|
|
|
position);
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateTranslationUnitIfNotCurrentDocument(document);
|
2015-11-25 15:11:23 +01:00
|
|
|
|
|
|
|
|
clearDiagnosticFixIts(document->filePath().toString());
|
2015-08-31 16:10:36 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-15 16:24:52 +02:00
|
|
|
void ModelManagerSupportClang::onCppDocumentAboutToReloadOnUnsavedFile()
|
|
|
|
|
{
|
|
|
|
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
|
|
|
|
disconnect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
|
|
|
|
this, &ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
void ModelManagerSupportClang::onCppDocumentReloadFinishedOnUnsavedFile(bool success)
|
|
|
|
|
{
|
|
|
|
|
if (success) {
|
2015-09-15 16:24:52 +02:00
|
|
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
|
|
|
|
connectToTextDocumentContentsChangedForUnsavedFile(textDocument);
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateUnsavedFile(textDocument);
|
2015-08-31 16:10:36 +02:00
|
|
|
}
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
void ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateUnsavedFile(document);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QString &filePath,
|
|
|
|
|
const QByteArray &content)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return);
|
2016-11-21 13:30:26 +01:00
|
|
|
|
|
|
|
|
const QString mappedPath = m_uiHeaderOnDiskManager.createIfNeeded(filePath);
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.updateUnsavedFile(mappedPath, content, 0);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return);
|
2016-11-21 13:30:26 +01:00
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
if (!cppModelManager()->cppEditorDocument(filePath)) {
|
2016-11-21 13:30:26 +01:00
|
|
|
const QString mappedPath = m_uiHeaderOnDiskManager.remove(filePath);
|
2015-07-14 17:30:17 +02:00
|
|
|
const QString projectPartId = Utils::projectPartIdForFile(filePath);
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.unregisterUnsavedFilesForEditor({{mappedPath, projectPartId}});
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 18:26:09 +02:00
|
|
|
void addFixItsActionsToMenu(QMenu *menu, const TextEditor::QuickFixOperations &fixItOperations)
|
|
|
|
|
{
|
|
|
|
|
foreach (const auto &fixItOperation, fixItOperations) {
|
|
|
|
|
QAction *action = menu->addAction(fixItOperation->description());
|
|
|
|
|
QObject::connect(action, &QAction::triggered, [fixItOperation]() {
|
|
|
|
|
fixItOperation->perform();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int lineToPosition(const QTextDocument *textDocument, int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(textDocument, return 0);
|
|
|
|
|
const QTextBlock textBlock = textDocument->findBlockByLineNumber(lineNumber);
|
|
|
|
|
return textBlock.isValid() ? textBlock.position() - 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static TextEditor::AssistInterface createAssistInterface(TextEditor::TextEditorWidget *widget,
|
|
|
|
|
int lineNumber)
|
|
|
|
|
{
|
|
|
|
|
return TextEditor::AssistInterface(widget->document(),
|
|
|
|
|
lineToPosition(widget->document(), lineNumber),
|
|
|
|
|
widget->textDocument()->filePath().toString(),
|
|
|
|
|
TextEditor::IdleEditor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::onTextMarkContextMenuRequested(TextEditor::TextEditorWidget *widget,
|
|
|
|
|
int lineNumber,
|
|
|
|
|
QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(widget, return);
|
|
|
|
|
QTC_ASSERT(lineNumber >= 1, return);
|
|
|
|
|
QTC_ASSERT(menu, return);
|
|
|
|
|
|
|
|
|
|
const auto filePath = widget->textDocument()->filePath().toString();
|
|
|
|
|
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(filePath);
|
|
|
|
|
if (processor) {
|
|
|
|
|
const auto assistInterface = createAssistInterface(widget, lineNumber);
|
|
|
|
|
const auto fixItOperations = processor->extraRefactoringOperations(assistInterface);
|
|
|
|
|
|
|
|
|
|
addFixItsActionsToMenu(menu, fixItOperations);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
using ClangEditorDocumentProcessors = QVector<ClangEditorDocumentProcessor *>;
|
|
|
|
|
static ClangEditorDocumentProcessors clangProcessors()
|
|
|
|
|
{
|
|
|
|
|
ClangEditorDocumentProcessors result;
|
|
|
|
|
foreach (auto *editorDocument, cppModelManager()->cppEditorDocuments())
|
|
|
|
|
result.append(qobject_cast<ClangEditorDocumentProcessor *>(editorDocument->processor()));
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ClangEditorDocumentProcessors
|
|
|
|
|
clangProcessorsWithProject(const ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
return ::Utils::filtered(clangProcessors(), [project](ClangEditorDocumentProcessor *p) {
|
|
|
|
|
return p->hasProjectPart() && p->projectPart()->project == project;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void updateProcessors(const ClangEditorDocumentProcessors &processors)
|
|
|
|
|
{
|
|
|
|
|
CppTools::CppModelManager *modelManager = cppModelManager();
|
|
|
|
|
for (ClangEditorDocumentProcessor *processor : processors)
|
|
|
|
|
modelManager->cppEditorDocument(processor->filePath())->resetProcessor();
|
|
|
|
|
modelManager->updateCppEditorDocuments(/*projectsUpdated=*/ false);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 16:31:05 +01:00
|
|
|
void ModelManagerSupportClang::onProjectAdded(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_projectSettings.value(project), return);
|
|
|
|
|
|
|
|
|
|
auto *settings = new Internal::ClangProjectSettings(project);
|
2018-01-19 16:57:18 +01:00
|
|
|
connect(settings, &Internal::ClangProjectSettings::changed, [project]() {
|
|
|
|
|
updateProcessors(clangProcessorsWithProject(project));
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-22 16:31:05 +01:00
|
|
|
m_projectSettings.insert(project, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::onAboutToRemoveProject(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
ClangProjectSettings * const settings = m_projectSettings.value(project);
|
|
|
|
|
QTC_ASSERT(settings, return);
|
|
|
|
|
m_projectSettings.remove(project);
|
|
|
|
|
delete settings;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
void ModelManagerSupportClang::onProjectPartsUpdated(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(project, return);
|
|
|
|
|
const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project);
|
|
|
|
|
QTC_ASSERT(projectInfo.isValid(), return);
|
2015-11-06 16:58:24 +01:00
|
|
|
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.registerProjectsParts(projectInfo.projectParts());
|
|
|
|
|
m_communicator.registerFallbackProjectPart();
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 17:30:17 +02:00
|
|
|
void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectPartIds)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2015-09-18 12:19:46 +02:00
|
|
|
if (!projectPartIds.isEmpty()) {
|
|
|
|
|
unregisterTranslationUnitsWithProjectParts(projectPartIds);
|
2017-09-25 15:10:48 +02:00
|
|
|
m_communicator.unregisterProjectPartsForEditor(projectPartIds);
|
|
|
|
|
m_communicator.registerFallbackProjectPart();
|
2015-09-18 12:19:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
static ClangEditorDocumentProcessors clangProcessorsWithDiagnosticConfig(
|
|
|
|
|
const QVector<Core::Id> &configIds)
|
2015-09-18 12:19:46 +02:00
|
|
|
{
|
2018-01-19 16:57:18 +01:00
|
|
|
return ::Utils::filtered(clangProcessors(), [configIds](ClangEditorDocumentProcessor *p) {
|
|
|
|
|
return configIds.contains(p->diagnosticConfigId());
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-18 12:19:46 +02:00
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
void ModelManagerSupportClang::onDiagnosticConfigsInvalidated(const QVector<Core::Id> &configIds)
|
|
|
|
|
{
|
|
|
|
|
updateProcessors(clangProcessorsWithDiagnosticConfig(configIds));
|
|
|
|
|
}
|
2015-09-18 12:19:46 +02:00
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
static ClangEditorDocumentProcessors
|
|
|
|
|
clangProcessorsWithProjectParts(const QStringList &projectPartIds)
|
|
|
|
|
{
|
|
|
|
|
return ::Utils::filtered(clangProcessors(), [projectPartIds](ClangEditorDocumentProcessor *p) {
|
|
|
|
|
return p->hasProjectPart() && projectPartIds.contains(p->projectPart()->id());
|
|
|
|
|
});
|
2015-09-18 12:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
|
|
|
|
|
const QStringList &projectPartIds)
|
|
|
|
|
{
|
|
|
|
|
const auto processors = clangProcessorsWithProjectParts(projectPartIds);
|
|
|
|
|
foreach (ClangEditorDocumentProcessor *processor, processors) {
|
2018-01-19 14:51:37 +01:00
|
|
|
processor->unregisterTranslationUnitForEditor();
|
2015-09-18 12:19:46 +02:00
|
|
|
processor->clearProjectPart();
|
|
|
|
|
processor->run();
|
|
|
|
|
}
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-21 13:30:26 +01:00
|
|
|
ModelManagerSupportClang *ModelManagerSupportClang::instance()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2016-11-21 13:30:26 +01:00
|
|
|
return m_instance;
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-25 15:10:48 +02:00
|
|
|
BackendCommunicator &ModelManagerSupportClang::communicator()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2017-09-25 15:10:48 +02:00
|
|
|
return m_communicator;
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-21 13:30:26 +01:00
|
|
|
QString ModelManagerSupportClang::dummyUiHeaderOnDiskPath(const QString &filePath) const
|
|
|
|
|
{
|
|
|
|
|
return m_uiHeaderOnDiskManager.mapPath(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 16:31:05 +01:00
|
|
|
ClangProjectSettings &ModelManagerSupportClang::projectSettings(
|
|
|
|
|
ProjectExplorer::Project *project) const
|
|
|
|
|
{
|
|
|
|
|
return *m_projectSettings.value(project);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 13:30:26 +01:00
|
|
|
QString ModelManagerSupportClang::dummyUiHeaderOnDiskDirPath() const
|
|
|
|
|
{
|
|
|
|
|
return m_uiHeaderOnDiskManager.directoryPath();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
QString ModelManagerSupportProviderClang::id() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(Constants::CLANG_MODELMANAGERSUPPORT_ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ModelManagerSupportProviderClang::displayName() const
|
|
|
|
|
{
|
|
|
|
|
//: Display name
|
|
|
|
|
return QCoreApplication::translate("ClangCodeModel::Internal::ModelManagerSupport",
|
|
|
|
|
"Clang");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppTools::ModelManagerSupport::Ptr ModelManagerSupportProviderClang::createModelManagerSupport()
|
|
|
|
|
{
|
|
|
|
|
return CppTools::ModelManagerSupport::Ptr(new ModelManagerSupportClang);
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|