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"
|
2021-06-22 14:40:19 +02:00
|
|
|
#include "clangcurrentdocumentfilter.h"
|
2021-04-20 14:42:29 +02:00
|
|
|
#include "clangdclient.h"
|
2021-06-22 14:40:19 +02:00
|
|
|
#include "clangdquickfixfactory.h"
|
2014-08-19 15:59:29 +02:00
|
|
|
#include "clangeditordocumentprocessor.h"
|
2017-08-03 16:43:38 +02:00
|
|
|
#include "clangfollowsymbol.h"
|
2021-06-22 14:40:19 +02:00
|
|
|
#include "clanggloballocatorfilters.h"
|
2018-01-12 12:29:43 +01:00
|
|
|
#include "clanghoverhandler.h"
|
2021-06-22 14:40:19 +02:00
|
|
|
#include "clangoverviewmodel.h"
|
2018-01-22 16:31:05 +01:00
|
|
|
#include "clangprojectsettings.h"
|
2017-09-26 16:00:30 +02:00
|
|
|
#include "clangrefactoringengine.h"
|
2021-06-22 14:40:19 +02:00
|
|
|
#include "clangutils.h"
|
2015-05-08 15:48:17 +02:00
|
|
|
|
2021-04-29 16:09:07 +02:00
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2021-02-23 13:51:41 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/messagemanager.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>
|
|
|
|
|
|
2021-02-23 13:51:41 +01:00
|
|
|
#include <languageclient/languageclientmanager.h>
|
|
|
|
|
|
2015-12-15 11:59:48 +01:00
|
|
|
#include <texteditor/quickfix.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
|
2021-02-23 13:51:41 +01:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2021-02-23 13:51:41 +01:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
2018-01-22 16:31:05 +01:00
|
|
|
#include <projectexplorer/session.h>
|
2021-02-23 13:51:41 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
|
2017-08-24 12:28:01 +02:00
|
|
|
#include <clangsupport/filecontainer.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>
|
2021-02-23 13:51:41 +01:00
|
|
|
#include <utils/runextensions.h>
|
2013-12-10 14:37:32 +01:00
|
|
|
|
2018-10-10 14:32:00 +02:00
|
|
|
#include <QApplication>
|
2015-08-24 18:26:09 +02:00
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QTextBlock>
|
2018-10-19 10:20:27 +02:00
|
|
|
#include <QTimer>
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
using namespace ClangCodeModel;
|
|
|
|
|
using namespace ClangCodeModel::Internal;
|
2021-02-23 13:51:41 +01:00
|
|
|
using namespace LanguageClient;
|
2013-12-10 14:37:32 +01:00
|
|
|
|
2018-11-04 21:44:21 +01:00
|
|
|
static ClangModelManagerSupport *m_instance = nullptr;
|
2013-12-10 14:37:32 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
ClangModelManagerSupport::ClangModelManagerSupport()
|
2020-07-31 16:50:03 +02:00
|
|
|
: m_completionAssistProvider(m_communicator, CompletionType::Other)
|
|
|
|
|
, m_functionHintAssistProvider(m_communicator, CompletionType::FunctionHint)
|
2018-01-05 10:50:37 +01:00
|
|
|
, m_followSymbol(new ClangFollowSymbol)
|
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-11-27 15:51:18 +01:00
|
|
|
CppTools::CppModelManager::instance()->setCurrentDocumentFilter(
|
|
|
|
|
std::make_unique<ClangCurrentDocumentFilter>());
|
2021-02-23 13:51:41 +01:00
|
|
|
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
|
|
|
|
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
|
|
|
|
|
cppModelManager()->setFunctionsFilter(std::make_unique<ClangFunctionsFilter>());
|
2017-11-27 15:51:18 +01:00
|
|
|
|
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,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onEditorOpened);
|
2015-05-08 15:48:17 +02:00
|
|
|
connect(editorManager, &Core::EditorManager::currentEditorChanged,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCurrentEditorChanged);
|
2015-12-01 11:57:08 +01:00
|
|
|
connect(editorManager, &Core::EditorManager::editorsClosed,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onEditorClosed);
|
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,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onAbstractEditorSupportContentsUpdated);
|
2015-06-04 11:38:59 +02:00
|
|
|
connect(modelManager, &CppTools::CppModelManager::abstractEditorSupportRemoved,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onAbstractEditorSupportRemoved);
|
2015-05-08 15:48:17 +02:00
|
|
|
connect(modelManager, &CppTools::CppModelManager::projectPartsUpdated,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onProjectPartsUpdated);
|
2015-05-08 15:48:17 +02:00
|
|
|
connect(modelManager, &CppTools::CppModelManager::projectPartsRemoved,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::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,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onProjectAdded);
|
2018-01-22 16:31:05 +01:00
|
|
|
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onAboutToRemoveProject);
|
2018-01-22 16:31:05 +01:00
|
|
|
|
2021-06-25 16:50:52 +02:00
|
|
|
CppTools::ClangdSettings::setDefaultClangdPath(Utils::FilePath::fromString(
|
2021-02-23 13:51:41 +01:00
|
|
|
Core::ICore::clangdExecutable(CLANG_BINDIR)));
|
2021-07-01 04:17:54 +02:00
|
|
|
connect(&CppTools::ClangdSettings::instance(), &CppTools::ClangdSettings::changed,
|
|
|
|
|
this, &ClangModelManagerSupport::onClangdSettingsChanged);
|
2020-02-03 11:13:27 +01:00
|
|
|
CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings();
|
2018-01-19 16:57:18 +01:00
|
|
|
connect(settings, &CppTools::CppCodeModelSettings::clangDiagnosticConfigsInvalidated,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onDiagnosticConfigsInvalidated);
|
2021-02-23 13:51:41 +01:00
|
|
|
|
|
|
|
|
// TODO: Enable this once we do document-level stuff with clangd (highlighting etc)
|
|
|
|
|
// createClient(nullptr, {});
|
2021-05-05 17:59:33 +02:00
|
|
|
m_generatorSynchronizer.setCancelOnWait(true);
|
2021-06-22 14:40:19 +02:00
|
|
|
new ClangdQuickFixFactory(); // memory managed by CppEditor::g_cppQuickFixFactories
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
ClangModelManagerSupport::~ClangModelManagerSupport()
|
2013-12-10 14:37:32 +01:00
|
|
|
{
|
2018-01-22 16:31:05 +01:00
|
|
|
QTC_CHECK(m_projectSettings.isEmpty());
|
2021-05-05 17:59:33 +02:00
|
|
|
m_generatorSynchronizer.waitForFinished();
|
2018-11-04 21:44:21 +01:00
|
|
|
m_instance = nullptr;
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
CppTools::CppCompletionAssistProvider *ClangModelManagerSupport::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
|
|
|
}
|
|
|
|
|
|
2020-07-31 16:50:03 +02:00
|
|
|
CppTools::CppCompletionAssistProvider *ClangModelManagerSupport::functionHintAssistProvider()
|
|
|
|
|
{
|
|
|
|
|
return &m_functionHintAssistProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
TextEditor::BaseHoverHandler *ClangModelManagerSupport::createHoverHandler()
|
2018-01-11 17:06:26 +01:00
|
|
|
{
|
2018-01-12 12:29:43 +01:00
|
|
|
return new Internal::ClangHoverHandler;
|
2018-01-11 17:06:26 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
CppTools::FollowSymbolInterface &ClangModelManagerSupport::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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
CppTools::RefactoringEngineInterface &ClangModelManagerSupport::refactoringEngineInterface()
|
2017-09-26 16:00:30 +02:00
|
|
|
{
|
|
|
|
|
return *m_refactoringEngine;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
std::unique_ptr<CppTools::AbstractOverviewModel> ClangModelManagerSupport::createOverviewModel()
|
2018-02-02 13:01:07 +01:00
|
|
|
{
|
2018-02-06 08:19:42 +01:00
|
|
|
return std::make_unique<OverviewModel>();
|
2018-02-02 13:01:07 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 14:28:25 +02:00
|
|
|
bool ClangModelManagerSupport::supportsOutline(const TextEditor::TextDocument *document) const
|
|
|
|
|
{
|
|
|
|
|
return !clientForFile(document->filePath());
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
CppTools::BaseEditorDocumentProcessor *ClangModelManagerSupport::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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCurrentEditorChanged(Core::IEditor *editor)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.documentVisibilityChanged();
|
2018-04-12 14:49:07 +02:00
|
|
|
|
|
|
|
|
// Update task hub issues for current CppEditorDocument
|
2018-04-20 13:55:49 +02:00
|
|
|
ClangEditorDocumentProcessor::clearTaskHubIssues();
|
|
|
|
|
if (!editor || !editor->document() || !cppModelManager()->isCppEditor(editor))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const ::Utils::FilePath filePath = editor->document()->filePath();
|
2020-07-15 16:11:26 +02:00
|
|
|
if (auto processor = ClangEditorDocumentProcessor::get(filePath.toString())) {
|
|
|
|
|
processor->semanticRehighlight();
|
2018-04-12 14:49:07 +02:00
|
|
|
processor->generateTaskHubIssues();
|
2020-07-15 16:11:26 +02:00
|
|
|
}
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)
|
2015-08-31 16:10:36 +02:00
|
|
|
{
|
|
|
|
|
// Handle externally changed documents
|
2015-09-15 16:24:52 +02:00
|
|
|
connect(textDocument, &Core::IDocument::aboutToReload,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentAboutToReloadOnTranslationUnit,
|
2015-09-15 16:24:52 +02:00
|
|
|
Qt::UniqueConnection);
|
2015-08-31 16:10:36 +02:00
|
|
|
connect(textDocument, &Core::IDocument::reloadFinished,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentReloadFinishedOnTranslationUnit,
|
2015-08-31 16:10:36 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::connectTextDocumentToUnsavedFiles(TextEditor::TextDocument *textDocument)
|
2015-08-31 16:10:36 +02:00
|
|
|
{
|
|
|
|
|
// Handle externally changed documents
|
2015-09-15 16:24:52 +02:00
|
|
|
connect(textDocument, &Core::IDocument::aboutToReload,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentAboutToReloadOnUnsavedFile,
|
2015-09-15 16:24:52 +02:00
|
|
|
Qt::UniqueConnection);
|
2015-08-31 16:10:36 +02:00
|
|
|
connect(textDocument, &Core::IDocument::reloadFinished,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentReloadFinishedOnUnsavedFile,
|
2015-08-31 16:10:36 +02:00
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
|
|
|
|
|
// Handle changes from e.g. refactoring actions
|
2015-09-15 16:24:52 +02:00
|
|
|
connectToTextDocumentContentsChangedForUnsavedFile(textDocument);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::connectToTextDocumentContentsChangedForTranslationUnit(
|
2015-09-15 16:24:52 +02:00
|
|
|
TextEditor::TextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
connect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentContentsChangedOnTranslationUnit,
|
2015-09-15 16:24:52 +02:00
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::connectToTextDocumentContentsChangedForUnsavedFile(
|
2015-09-15 16:24:52 +02:00
|
|
|
TextEditor::TextDocument *textDocument)
|
|
|
|
|
{
|
|
|
|
|
connect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentContentsChangedOnUnsavedFile,
|
2015-08-31 16:10:36 +02:00
|
|
|
Qt::UniqueConnection);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget *editorWidget)
|
2015-08-24 18:26:09 +02:00
|
|
|
{
|
|
|
|
|
const auto widget = qobject_cast<TextEditor::TextEditorWidget *>(editorWidget);
|
|
|
|
|
if (widget) {
|
|
|
|
|
connect(widget, &TextEditor::TextEditorWidget::markContextMenuRequested,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onTextMarkContextMenuRequested);
|
2015-08-24 18:26:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 13:51:41 +01:00
|
|
|
void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project,
|
|
|
|
|
const CppTools::ProjectInfo &projectInfo)
|
|
|
|
|
{
|
2021-07-01 04:17:54 +02:00
|
|
|
if (!CppTools::ClangdProjectSettings(project).settings().useClangd)
|
2021-02-23 13:51:41 +01:00
|
|
|
return;
|
|
|
|
|
const auto getJsonDbDir = [project] {
|
|
|
|
|
if (const ProjectExplorer::Target * const target = project->activeTarget()) {
|
|
|
|
|
if (const ProjectExplorer::BuildConfiguration * const bc
|
|
|
|
|
= target->activeBuildConfiguration()) {
|
|
|
|
|
return bc->buildDirectory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Utils::FilePath();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Utils::FilePath jsonDbDir = getJsonDbDir();
|
|
|
|
|
if (jsonDbDir.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
const auto generatorWatcher = new QFutureWatcher<GenerateCompilationDbResult>;
|
|
|
|
|
connect(generatorWatcher, &QFutureWatcher<GenerateCompilationDbResult>::finished,
|
|
|
|
|
[this, project, projectInfo, getJsonDbDir, jsonDbDir, generatorWatcher] {
|
|
|
|
|
generatorWatcher->deleteLater();
|
|
|
|
|
if (!ProjectExplorer::SessionManager::hasProject(project))
|
|
|
|
|
return;
|
2021-07-01 04:17:54 +02:00
|
|
|
if (!CppTools::ClangdProjectSettings(project).settings().useClangd)
|
2021-06-28 14:55:54 +02:00
|
|
|
return;
|
2021-02-23 13:51:41 +01:00
|
|
|
if (cppModelManager()->projectInfo(project) != projectInfo)
|
|
|
|
|
return;
|
|
|
|
|
if (getJsonDbDir() != jsonDbDir)
|
|
|
|
|
return;
|
|
|
|
|
const GenerateCompilationDbResult result = generatorWatcher->result();
|
|
|
|
|
if (!result.error.isEmpty()) {
|
|
|
|
|
Core::MessageManager::writeDisrupting(
|
|
|
|
|
tr("Cannot use clangd: Failed to generate compilation database:\n%1")
|
|
|
|
|
.arg(result.error));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Client * const oldClient = clientForProject(project))
|
|
|
|
|
LanguageClientManager::shutdownClient(oldClient);
|
2021-04-21 14:29:49 +02:00
|
|
|
ClangdClient * const client = createClient(project, jsonDbDir);
|
2021-02-23 13:51:41 +01:00
|
|
|
connect(client, &Client::initialized, this, [client, project, projectInfo, jsonDbDir] {
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
if (!SessionManager::hasProject(project))
|
|
|
|
|
return;
|
2021-07-01 04:17:54 +02:00
|
|
|
if (!CppTools::ClangdProjectSettings(project).settings().useClangd)
|
2021-06-28 14:55:54 +02:00
|
|
|
return;
|
2021-02-23 13:51:41 +01:00
|
|
|
if (cppModelManager()->projectInfo(project) != projectInfo)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-04-29 16:09:07 +02:00
|
|
|
// Acquaint the client with all open C++ documents for this project.
|
|
|
|
|
bool hasDocuments = false;
|
|
|
|
|
for (const Core::DocumentModel::Entry * const entry : Core::DocumentModel::entries()) {
|
|
|
|
|
const auto textDocument = qobject_cast<TextEditor::TextDocument *>(entry->document);
|
|
|
|
|
if (!textDocument)
|
|
|
|
|
continue;
|
|
|
|
|
const bool isCppDocument = Utils::contains(
|
|
|
|
|
Core::DocumentModel::editorsForDocument(textDocument),
|
|
|
|
|
[](Core::IEditor *editor) {
|
|
|
|
|
return CppTools::CppModelManager::isCppEditor(editor);
|
|
|
|
|
});
|
|
|
|
|
if (!isCppDocument)
|
|
|
|
|
continue;
|
|
|
|
|
if (!project->isKnownFile(entry->fileName()))
|
|
|
|
|
continue;
|
|
|
|
|
client->openDocument(textDocument);
|
|
|
|
|
hasDocuments = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasDocuments)
|
|
|
|
|
return;
|
2021-02-23 13:51:41 +01:00
|
|
|
|
|
|
|
|
// clangd oddity: Background indexing only starts after opening a random file.
|
|
|
|
|
// TODO: changes to the compilation db do not seem to trigger re-indexing.
|
|
|
|
|
// How to force it?
|
|
|
|
|
ProjectNode * const rootNode = project->rootProjectNode();
|
|
|
|
|
if (!rootNode)
|
|
|
|
|
return;
|
|
|
|
|
const Node * const cxxNode = rootNode->findNode([](Node *n) {
|
|
|
|
|
const FileNode * const fileNode = n->asFileNode();
|
|
|
|
|
return fileNode && (fileNode->fileType() == FileType::Source
|
|
|
|
|
|| fileNode->fileType() == FileType::Header)
|
|
|
|
|
&& fileNode->filePath().exists();
|
|
|
|
|
});
|
|
|
|
|
if (!cxxNode)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-04-21 14:29:49 +02:00
|
|
|
client->openExtraFile(cxxNode->filePath());
|
|
|
|
|
client->closeExtraFile(cxxNode->filePath());
|
2021-02-23 13:51:41 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
2021-05-05 17:59:33 +02:00
|
|
|
auto future = Utils::runAsync(&Internal::generateCompilationDB, projectInfo,
|
|
|
|
|
CompilationDbPurpose::CodeModel);
|
|
|
|
|
generatorWatcher->setFuture(future);
|
2021-05-12 15:12:48 +02:00
|
|
|
m_generatorSynchronizer.addFuture(future);
|
2021-02-23 13:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-20 15:46:35 +02:00
|
|
|
ClangdClient *ClangModelManagerSupport::clientForProject(
|
2021-06-08 14:28:25 +02:00
|
|
|
const ProjectExplorer::Project *project) const
|
2021-02-23 13:51:41 +01:00
|
|
|
{
|
|
|
|
|
const QList<Client *> clients = Utils::filtered(
|
|
|
|
|
LanguageClientManager::clientsForProject(project),
|
|
|
|
|
[](const LanguageClient::Client *c) {
|
2021-04-20 14:42:29 +02:00
|
|
|
return qobject_cast<const ClangdClient *>(c)
|
2021-02-23 13:51:41 +01:00
|
|
|
&& c->state() != Client::ShutdownRequested
|
|
|
|
|
&& c->state() != Client::Shutdown;
|
|
|
|
|
});
|
|
|
|
|
QTC_CHECK(clients.size() <= 1);
|
2021-04-20 15:46:35 +02:00
|
|
|
return clients.empty() ? nullptr : qobject_cast<ClangdClient *>(clients.first());
|
2021-02-23 13:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 14:28:25 +02:00
|
|
|
ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &file) const
|
2021-05-19 13:08:01 +02:00
|
|
|
{
|
|
|
|
|
return clientForProject(ProjectExplorer::SessionManager::projectForFile(file));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 15:46:35 +02:00
|
|
|
ClangdClient *ClangModelManagerSupport::createClient(ProjectExplorer::Project *project,
|
|
|
|
|
const Utils::FilePath &jsonDbDir)
|
2021-02-23 13:51:41 +01:00
|
|
|
{
|
2021-04-21 14:29:49 +02:00
|
|
|
const auto client = new ClangdClient(project, jsonDbDir);
|
|
|
|
|
emit createdClient(client);
|
|
|
|
|
return client;
|
2021-02-23 13:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(editor, return);
|
|
|
|
|
Core::IDocument *document = editor->document();
|
|
|
|
|
QTC_ASSERT(document, return);
|
2018-11-04 21:44:21 +01:00
|
|
|
auto textDocument = qobject_cast<TextEditor::TextDocument *>(document);
|
2015-05-08 15:48:17 +02:00
|
|
|
|
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?
|
2021-02-23 13:51:41 +01:00
|
|
|
|
|
|
|
|
ProjectExplorer::Project * const project
|
|
|
|
|
= ProjectExplorer::SessionManager::projectForFile(document->filePath());
|
|
|
|
|
if (Client * const client = clientForProject(project))
|
|
|
|
|
client->openDocument(textDocument);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onEditorClosed(const QList<Core::IEditor *> &)
|
2015-12-01 11:57:08 +01:00
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.documentVisibilityChanged();
|
2015-12-01 11:57:08 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCppDocumentAboutToReloadOnTranslationUnit()
|
2015-09-15 16:24:52 +02:00
|
|
|
{
|
2018-11-04 21:44:21 +01:00
|
|
|
auto textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
2015-09-15 16:24:52 +02:00
|
|
|
disconnect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentContentsChangedOnTranslationUnit);
|
2015-09-15 16:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCppDocumentReloadFinishedOnTranslationUnit(bool success)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2015-08-31 16:10:36 +02:00
|
|
|
if (success) {
|
2018-11-04 21:44:21 +01:00
|
|
|
auto textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
2015-09-15 16:24:52 +02:00
|
|
|
connectToTextDocumentContentsChangedForTranslationUnit(textDocument);
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.documentsChangedWithRevisionCheck(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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCppDocumentContentsChangedOnTranslationUnit(int position,
|
2015-09-28 17:42:43 +02:00
|
|
|
int /*charsRemoved*/,
|
|
|
|
|
int /*charsAdded*/)
|
2015-08-31 16:10:36 +02:00
|
|
|
{
|
2018-11-04 21:44:21 +01:00
|
|
|
auto 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);
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.documentsChangedIfNotCurrentDocument(document);
|
2015-11-25 15:11:23 +01:00
|
|
|
|
|
|
|
|
clearDiagnosticFixIts(document->filePath().toString());
|
2015-08-31 16:10:36 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCppDocumentAboutToReloadOnUnsavedFile()
|
2015-09-15 16:24:52 +02:00
|
|
|
{
|
2018-11-04 21:44:21 +01:00
|
|
|
auto textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
2015-09-15 16:24:52 +02:00
|
|
|
disconnect(textDocument, &TextEditor::TextDocument::contentsChangedWithPosition,
|
2018-10-18 09:21:35 +02:00
|
|
|
this, &ClangModelManagerSupport::onCppDocumentContentsChangedOnUnsavedFile);
|
2015-09-15 16:24:52 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCppDocumentReloadFinishedOnUnsavedFile(bool success)
|
2015-08-31 16:10:36 +02:00
|
|
|
{
|
|
|
|
|
if (success) {
|
2018-11-04 21:44:21 +01:00
|
|
|
auto textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
|
2015-09-15 16:24:52 +02:00
|
|
|
connectToTextDocumentContentsChangedForUnsavedFile(textDocument);
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.unsavedFilesUpdated(textDocument);
|
2015-08-31 16:10:36 +02:00
|
|
|
}
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onCppDocumentContentsChangedOnUnsavedFile()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2018-11-04 21:44:21 +01:00
|
|
|
auto document = qobject_cast<Core::IDocument *>(sender());
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.unsavedFilesUpdated(document);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onAbstractEditorSupportContentsUpdated(const QString &filePath,
|
2019-01-23 13:14:50 +01:00
|
|
|
const QString &,
|
2015-05-08 15:48:17 +02:00
|
|
|
const QByteArray &content)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return);
|
2016-11-21 13:30:26 +01:00
|
|
|
|
2018-10-19 10:20:27 +02:00
|
|
|
if (content.size() == 0)
|
|
|
|
|
return; // Generation not yet finished.
|
|
|
|
|
|
|
|
|
|
const QString mappedPath = m_uiHeaderOnDiskManager.write(filePath, content);
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.unsavedFilesUpdated(mappedPath, content, 0);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onAbstractEditorSupportRemoved(const QString &filePath)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
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);
|
2020-07-06 15:49:35 +02:00
|
|
|
const QString projectPartId = projectPartIdForFile(filePath);
|
2018-05-31 15:21:53 +02:00
|
|
|
m_communicator.unsavedFilesRemoved({{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),
|
2020-09-02 12:29:23 +02:00
|
|
|
widget->textDocument()->filePath(),
|
2015-08-24 18:26:09 +02:00
|
|
|
TextEditor::IdleEditor);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onTextMarkContextMenuRequested(TextEditor::TextEditorWidget *widget,
|
2015-08-24 18:26:09 +02:00
|
|
|
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-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onProjectAdded(ProjectExplorer::Project *project)
|
2018-01-22 16:31:05 +01:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onAboutToRemoveProject(ProjectExplorer::Project *project)
|
2018-01-22 16:31:05 +01:00
|
|
|
{
|
|
|
|
|
ClangProjectSettings * const settings = m_projectSettings.value(project);
|
|
|
|
|
QTC_ASSERT(settings, return);
|
|
|
|
|
m_projectSettings.remove(project);
|
|
|
|
|
delete settings;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onProjectPartsUpdated(ProjectExplorer::Project *project)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(project, return);
|
|
|
|
|
const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project);
|
|
|
|
|
QTC_ASSERT(projectInfo.isValid(), return);
|
2015-11-06 16:58:24 +01:00
|
|
|
|
2021-02-23 13:51:41 +01:00
|
|
|
updateLanguageClient(project, projectInfo);
|
|
|
|
|
|
2018-09-25 09:41:32 +02:00
|
|
|
QStringList projectPartIds;
|
|
|
|
|
for (const CppTools::ProjectPart::Ptr &projectPart : projectInfo.projectParts())
|
|
|
|
|
projectPartIds.append(projectPart->id());
|
|
|
|
|
onProjectPartsRemoved(projectPartIds);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::onProjectPartsRemoved(const QStringList &projectPartIds)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2018-09-25 09:41:32 +02:00
|
|
|
if (!projectPartIds.isEmpty())
|
|
|
|
|
reinitializeBackendDocuments(projectPartIds);
|
2015-09-18 12:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-01 04:17:54 +02:00
|
|
|
void ClangModelManagerSupport::onClangdSettingsChanged()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Handle also project-less client
|
|
|
|
|
for (ProjectExplorer::Project * const project : ProjectExplorer::SessionManager::projects()) {
|
|
|
|
|
const CppTools::ClangdSettings settings(
|
|
|
|
|
CppTools::ClangdProjectSettings(project).settings());
|
|
|
|
|
ClangdClient * const client = clientForProject(project);
|
|
|
|
|
if (!client) {
|
|
|
|
|
if (settings.useClangd())
|
|
|
|
|
updateLanguageClient(project, cppModelManager()->projectInfo(project));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!settings.useClangd()) {
|
|
|
|
|
LanguageClientManager::shutdownClient(client);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (client->settingsData() != settings.data())
|
|
|
|
|
updateLanguageClient(project, cppModelManager()->projectInfo(project));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 16:57:18 +01:00
|
|
|
static ClangEditorDocumentProcessors clangProcessorsWithDiagnosticConfig(
|
2020-06-26 13:59:38 +02:00
|
|
|
const QVector<::Utils::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
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
void ClangModelManagerSupport::onDiagnosticConfigsInvalidated(const QVector<::Utils::Id> &configIds)
|
2018-01-19 16:57:18 +01:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
void ClangModelManagerSupport::reinitializeBackendDocuments(const QStringList &projectPartIds)
|
2015-09-18 12:19:46 +02:00
|
|
|
{
|
|
|
|
|
const auto processors = clangProcessorsWithProjectParts(projectPartIds);
|
|
|
|
|
foreach (ClangEditorDocumentProcessor *processor, processors) {
|
2018-05-31 15:21:53 +02:00
|
|
|
processor->closeBackendDocument();
|
2015-09-18 12:19:46 +02:00
|
|
|
processor->clearProjectPart();
|
|
|
|
|
processor->run();
|
|
|
|
|
}
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
ClangModelManagerSupport *ClangModelManagerSupport::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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
BackendCommunicator &ClangModelManagerSupport::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
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
QString ClangModelManagerSupport::dummyUiHeaderOnDiskPath(const QString &filePath) const
|
2016-11-21 13:30:26 +01:00
|
|
|
{
|
|
|
|
|
return m_uiHeaderOnDiskManager.mapPath(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
ClangProjectSettings &ClangModelManagerSupport::projectSettings(
|
2018-01-22 16:31:05 +01:00
|
|
|
ProjectExplorer::Project *project) const
|
|
|
|
|
{
|
|
|
|
|
return *m_projectSettings.value(project);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
QString ClangModelManagerSupport::dummyUiHeaderOnDiskDirPath() const
|
2016-11-21 13:30:26 +01:00
|
|
|
{
|
|
|
|
|
return m_uiHeaderOnDiskManager.directoryPath();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
QString ClangModelManagerSupportProvider::id() const
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
return QLatin1String(Constants::CLANG_MODELMANAGERSUPPORT_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
QString ClangModelManagerSupportProvider::displayName() const
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
//: Display name
|
|
|
|
|
return QCoreApplication::translate("ClangCodeModel::Internal::ModelManagerSupport",
|
|
|
|
|
"Clang");
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:21:35 +02:00
|
|
|
CppTools::ModelManagerSupport::Ptr ClangModelManagerSupportProvider::createModelManagerSupport()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2018-10-18 09:21:35 +02:00
|
|
|
return CppTools::ModelManagerSupport::Ptr(new ClangModelManagerSupport);
|
2013-12-10 14:37:32 +01:00
|
|
|
}
|