forked from qt-creator/qt-creator
ClangCodeModel: prevent text mark annotations in non project files
Since non project files get opened in project specific clients now, the check whether we should add annotations needs to make sure that the marks file is part of the client project. Change-Id: I2790d0f7feb39162686efd06bb3542684d289b95 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -1315,10 +1315,10 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
|
|||||||
setDocumentChangeUpdateThreshold(d->settings.documentUpdateThreshold);
|
setDocumentChangeUpdateThreshold(d->settings.documentUpdateThreshold);
|
||||||
|
|
||||||
const auto textMarkCreator = [this](const Utils::FilePath &filePath,
|
const auto textMarkCreator = [this](const Utils::FilePath &filePath,
|
||||||
const Diagnostic &diag) {
|
const Diagnostic &diag, bool isProjectFile) {
|
||||||
if (d->isTesting)
|
if (d->isTesting)
|
||||||
emit textMarkCreated(filePath);
|
emit textMarkCreated(filePath);
|
||||||
return new ClangdTextMark(filePath, diag, this);
|
return new ClangdTextMark(filePath, diag, isProjectFile, this);
|
||||||
};
|
};
|
||||||
const auto hideDiagsHandler = []{ ClangDiagnosticManager::clearTaskHubIssues(); };
|
const auto hideDiagsHandler = []{ ClangDiagnosticManager::clearTaskHubIssues(); };
|
||||||
setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler);
|
setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler);
|
||||||
|
@@ -385,6 +385,7 @@ ClangBackEnd::DiagnosticContainer convertDiagnostic(const ClangdDiagnostic &src,
|
|||||||
|
|
||||||
ClangdTextMark::ClangdTextMark(const FilePath &filePath,
|
ClangdTextMark::ClangdTextMark(const FilePath &filePath,
|
||||||
const Diagnostic &diagnostic,
|
const Diagnostic &diagnostic,
|
||||||
|
bool isProjectFile,
|
||||||
const Client *client)
|
const Client *client)
|
||||||
: TextEditor::TextMark(filePath, int(diagnostic.range().start().line() + 1), client->id())
|
: TextEditor::TextMark(filePath, int(diagnostic.range().start().line() + 1), client->id())
|
||||||
, m_lspDiagnostic(diagnostic)
|
, m_lspDiagnostic(diagnostic)
|
||||||
@@ -399,7 +400,7 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath,
|
|||||||
setPriority(isError ? TextEditor::TextMark::HighPriority
|
setPriority(isError ? TextEditor::TextMark::HighPriority
|
||||||
: TextEditor::TextMark::NormalPriority);
|
: TextEditor::TextMark::NormalPriority);
|
||||||
setIcon(isError ? Icons::CODEMODEL_ERROR.icon() : Icons::CODEMODEL_WARNING.icon());
|
setIcon(isError ? Icons::CODEMODEL_ERROR.icon() : Icons::CODEMODEL_WARNING.icon());
|
||||||
if (client->project()) {
|
if (isProjectFile) {
|
||||||
setLineAnnotation(diagnostic.message());
|
setLineAnnotation(diagnostic.message());
|
||||||
setColor(isError ? Theme::CodeModel_Error_TextMarkColor
|
setColor(isError ? Theme::CodeModel_Error_TextMarkColor
|
||||||
: Theme::CodeModel_Warning_TextMarkColor);
|
: Theme::CodeModel_Warning_TextMarkColor);
|
||||||
|
@@ -72,6 +72,7 @@ class ClangdTextMark : public TextEditor::TextMark
|
|||||||
public:
|
public:
|
||||||
ClangdTextMark(const ::Utils::FilePath &filePath,
|
ClangdTextMark(const ::Utils::FilePath &filePath,
|
||||||
const LanguageServerProtocol::Diagnostic &diagnostic,
|
const LanguageServerProtocol::Diagnostic &diagnostic,
|
||||||
|
bool isProjectFile,
|
||||||
const LanguageClient::Client *client);
|
const LanguageClient::Client *client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/documentmodel.h>
|
#include <coreplugin/editormanager/documentmodel.h>
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
@@ -74,7 +75,7 @@ private:
|
|||||||
DiagnosticManager::DiagnosticManager(Client *client)
|
DiagnosticManager::DiagnosticManager(Client *client)
|
||||||
: m_client(client)
|
: m_client(client)
|
||||||
{
|
{
|
||||||
m_textMarkCreator = [this](const FilePath &filePath, const Diagnostic &diagnostic) {
|
m_textMarkCreator = [this](const FilePath &filePath, const Diagnostic &diagnostic, bool /*isProjectFile*/) {
|
||||||
return createTextMark(filePath, diagnostic);
|
return createTextMark(filePath, diagnostic);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -125,9 +126,11 @@ void DiagnosticManager::showDiagnostics(const DocumentUri &uri, int version)
|
|||||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||||
const VersionedDiagnostics &versionedDiagnostics = m_diagnostics.value(uri);
|
const VersionedDiagnostics &versionedDiagnostics = m_diagnostics.value(uri);
|
||||||
if (versionedDiagnostics.version.value_or(version) == version) {
|
if (versionedDiagnostics.version.value_or(version) == version) {
|
||||||
|
const bool isProjectFile = m_client->project()
|
||||||
|
&& m_client->project()->isKnownFile(filePath);
|
||||||
for (const Diagnostic &diagnostic : versionedDiagnostics.diagnostics) {
|
for (const Diagnostic &diagnostic : versionedDiagnostics.diagnostics) {
|
||||||
extraSelections << toDiagnosticsSelections(diagnostic, doc->document());
|
extraSelections << toDiagnosticsSelections(diagnostic, doc->document());
|
||||||
m_marks[filePath].append(m_textMarkCreator(filePath, diagnostic));
|
m_marks[filePath].append(m_textMarkCreator(filePath, diagnostic, isProjectFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ namespace LanguageClient {
|
|||||||
class Client;
|
class Client;
|
||||||
|
|
||||||
using TextMarkCreator = std::function<TextEditor::TextMark *(const Utils::FilePath &,
|
using TextMarkCreator = std::function<TextEditor::TextMark *(const Utils::FilePath &,
|
||||||
const LanguageServerProtocol::Diagnostic &)>;
|
const LanguageServerProtocol::Diagnostic &, bool)>;
|
||||||
using HideDiagnosticsHandler = std::function<void()>;
|
using HideDiagnosticsHandler = std::function<void()>;
|
||||||
|
|
||||||
class DiagnosticManager
|
class DiagnosticManager
|
||||||
|
Reference in New Issue
Block a user