diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 7125bdbe65d..a241d1c63e5 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -1285,6 +1285,7 @@ public: QHash highlightingData; QHash parserConfigs; + QHash issuePaneEntries; VersionedDataCache astCache; VersionedDataCache externalAstCache; @@ -1717,13 +1718,30 @@ const LanguageClient::Client::CustomInspectorTabs ClangdClient::createCustomInsp class ClangdDiagnosticManager : public LanguageClient::DiagnosticManager { -public: using LanguageClient::DiagnosticManager::DiagnosticManager; + ClangdClient *getClient() const { return qobject_cast(client()); } + + bool isCurrentDocument(const Utils::FilePath &filePath) const + { + const IDocument * const doc = EditorManager::currentDocument(); + return doc && doc->filePath() == filePath; + } + + void showDiagnostics(const DocumentUri &uri, int version) override + { + const Utils::FilePath filePath = uri.toFilePath(); + getClient()->clearTasks(filePath); + DiagnosticManager::showDiagnostics(uri, version); + if (isCurrentDocument(filePath)) + getClient()->switchIssuePaneEntries(filePath); + } + void hideDiagnostics(const Utils::FilePath &filePath) override { DiagnosticManager::hideDiagnostics(filePath); - TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS); + if (isCurrentDocument(filePath)) + TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS); } QList filteredDiagnostics(const QList &diagnostics) const override @@ -1739,7 +1757,7 @@ public: const Diagnostic &diagnostic, bool isProjectFile) const override { - return new ClangdTextMark(filePath, diagnostic, isProjectFile, client()); + return new ClangdTextMark(filePath, diagnostic, isProjectFile, getClient()); } }; @@ -1937,6 +1955,24 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, sendContent(DidChangeConfigurationNotification(configChangeParams)); } +void ClangdClient::switchIssuePaneEntries(const Utils::FilePath &filePath) +{ + TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS); + const Tasks tasks = d->issuePaneEntries.value(filePath); + for (const Task &t : tasks) + TaskHub::addTask(t); +} + +void ClangdClient::addTask(const ProjectExplorer::Task &task) +{ + d->issuePaneEntries[task.file] << task; +} + +void ClangdClient::clearTasks(const Utils::FilePath &filePath) +{ + d->issuePaneEntries[filePath].clear(); +} + void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList &locations) { const auto refData = runningFindUsages.find(key); diff --git a/src/plugins/clangcodemodel/clangdclient.h b/src/plugins/clangcodemodel/clangdclient.h index 5532b4fed29..70f5d906652 100644 --- a/src/plugins/clangcodemodel/clangdclient.h +++ b/src/plugins/clangcodemodel/clangdclient.h @@ -37,7 +37,10 @@ namespace Core { class SearchResultItem; } namespace CppEditor { class CppEditorWidget; } namespace LanguageServerProtocol { class Range; } -namespace ProjectExplorer { class Project; } +namespace ProjectExplorer { +class Project; +class Task; +} namespace TextEditor { class BaseTextEditor; } namespace ClangCodeModel { @@ -93,6 +96,9 @@ public: void updateParserConfig(const Utils::FilePath &filePath, const CppEditor::BaseEditorDocumentParser::Configuration &config); + void switchIssuePaneEntries(const Utils::FilePath &filePath); + void addTask(const ProjectExplorer::Task &task); + void clearTasks(const Utils::FilePath &filePath); signals: void indexingFinished(); diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 701f0b99807..917fee3bae3 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -282,8 +282,10 @@ void ClangModelManagerSupport::onCurrentEditorChanged(Core::IEditor *editor) const ::Utils::FilePath filePath = editor->document()->filePath(); if (auto processor = ClangEditorDocumentProcessor::get(filePath.toString())) { processor->semanticRehighlight(); - if (const auto client = clientForFile(filePath)) + if (const auto client = clientForFile(filePath)) { client->updateParserConfig(filePath, processor->parserConfig()); + client->switchIssuePaneEntries(filePath); + } } } diff --git a/src/plugins/clangcodemodel/clangtextmark.cpp b/src/plugins/clangcodemodel/clangtextmark.cpp index 3545e48b2d8..bbd3074c1a4 100644 --- a/src/plugins/clangcodemodel/clangtextmark.cpp +++ b/src/plugins/clangcodemodel/clangtextmark.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -279,7 +279,7 @@ ClangDiagnostic convertDiagnostic(const ClangdDiagnostic &src, const FilePath &f return target; } -void addTask(const ClangDiagnostic &diagnostic) +Task createTask(const ClangDiagnostic &diagnostic) { Task::TaskType taskType = Task::TaskType::Unknown; QIcon icon; @@ -298,13 +298,13 @@ void addTask(const ClangDiagnostic &diagnostic) break; } - TaskHub::addTask(Task(taskType, - diagnosticCategoryPrefixRemoved(diagnostic.text), - FilePath::fromString(diagnostic.location.targetFilePath.toString()), - diagnostic.location.targetLine, - Constants::TASK_CATEGORY_DIAGNOSTICS, - icon, - Task::NoOptions)); + return Task(taskType, + diagnosticCategoryPrefixRemoved(diagnostic.text), + FilePath::fromString(diagnostic.location.targetFilePath.toString()), + diagnostic.location.targetLine, + Constants::TASK_CATEGORY_DIAGNOSTICS, + icon, + Task::NoOptions); } } // anonymous namespace @@ -312,7 +312,7 @@ void addTask(const ClangDiagnostic &diagnostic) ClangdTextMark::ClangdTextMark(const FilePath &filePath, const Diagnostic &diagnostic, bool isProjectFile, - const Client *client) + Client *client) : TextEditor::TextMark(filePath, int(diagnostic.range().start().line() + 1), client->id()) , m_lspDiagnostic(diagnostic) , m_diagnostic(convertDiagnostic(ClangdDiagnostic(diagnostic), filePath)) @@ -330,7 +330,7 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath, setLineAnnotation(diagnostic.message()); setColor(isError ? Theme::CodeModel_Error_TextMarkColor : Theme::CodeModel_Warning_TextMarkColor); - addTask(m_diagnostic); + qobject_cast(client)->addTask(createTask(m_diagnostic)); } // Copy to clipboard action diff --git a/src/plugins/clangcodemodel/clangtextmark.h b/src/plugins/clangcodemodel/clangtextmark.h index 7a35452681b..0db460ed62a 100644 --- a/src/plugins/clangcodemodel/clangtextmark.h +++ b/src/plugins/clangcodemodel/clangtextmark.h @@ -47,7 +47,7 @@ public: ClangdTextMark(const ::Utils::FilePath &filePath, const LanguageServerProtocol::Diagnostic &diagnostic, bool isProjectFile, - const LanguageClient::Client *client); + LanguageClient::Client *client); private: bool addToolTipContent(QLayout *target) const override;