ClangCodeModel: Fix issue pane management for clangd diagnostics

We basically forgot to implement this. A task in the issues pane was
created for every text mark, but there was no code to deal with handling
editor switches, resulting in seemingly random behavior.

Fixes: QTCREATORBUG-27260
Change-Id: Ifcc1e04db4c37dde7e80f0e1646dc7c557cd7481
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-05-11 12:30:57 +02:00
parent 7881a49e7d
commit 35963fd2b8
5 changed files with 61 additions and 17 deletions

View File

@@ -1285,6 +1285,7 @@ public:
QHash<TextDocument *, HighlightingData> highlightingData;
QHash<Utils::FilePath, CppEditor::BaseEditorDocumentParser::Configuration> parserConfigs;
QHash<Utils::FilePath, Tasks> issuePaneEntries;
VersionedDataCache<const TextDocument *, AstNode> astCache;
VersionedDataCache<Utils::FilePath, AstNode> 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<ClangdClient *>(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<Diagnostic> filteredDiagnostics(const QList<Diagnostic> &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<Location> &locations)
{
const auto refData = runningFindUsages.find(key);