forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@
|
||||
#include <cppeditor/cpptoolsreuse.h>
|
||||
#include <cppeditor/cppcodemodelsettings.h>
|
||||
|
||||
#include <projectexplorer/taskhub.h>
|
||||
#include <projectexplorer/task.h>
|
||||
|
||||
#include <utils/fadingindicator.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -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<ClangdClient *>(client)->addTask(createTask(m_diagnostic));
|
||||
}
|
||||
|
||||
// Copy to clipboard action
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user