forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/11.0'
Change-Id: I87b22a73427cf9fc1b96075dc0db769ed3d3621c
This commit is contained in:
@@ -230,14 +230,22 @@ public:
|
||||
void enableCodeActionsInline() {insert(u"codeActionsInline", true);}
|
||||
};
|
||||
|
||||
class InactiveRegionsCapabilities : public JsonObject
|
||||
{
|
||||
public:
|
||||
using JsonObject::JsonObject;
|
||||
void enableInactiveRegionsSupport() { insert(u"inactiveRegions", true); }
|
||||
};
|
||||
|
||||
class ClangdTextDocumentClientCapabilities : public TextDocumentClientCapabilities
|
||||
{
|
||||
public:
|
||||
using TextDocumentClientCapabilities::TextDocumentClientCapabilities;
|
||||
|
||||
|
||||
void setPublishDiagnostics(const DiagnosticsCapabilities &caps)
|
||||
{ insert(u"publishDiagnostics", caps); }
|
||||
void setInactiveRegionsCapabilities(const InactiveRegionsCapabilities &caps)
|
||||
{ insert(u"inactiveRegionsCapabilities", caps); }
|
||||
};
|
||||
|
||||
static qint64 getRevision(const TextDocument *doc)
|
||||
@@ -428,6 +436,9 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir, c
|
||||
diagnostics.enableCategorySupport();
|
||||
diagnostics.enableCodeActionsInline();
|
||||
clangdTextCaps.setPublishDiagnostics(diagnostics);
|
||||
InactiveRegionsCapabilities inactiveRegions;
|
||||
inactiveRegions.enableInactiveRegionsSupport();
|
||||
clangdTextCaps.setInactiveRegionsCapabilities(inactiveRegions);
|
||||
std::optional<TextDocumentClientCapabilities::CompletionCapabilities> completionCaps
|
||||
= textCaps->completion();
|
||||
if (completionCaps)
|
||||
@@ -456,6 +467,9 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir, c
|
||||
const Utils::FilePath &filePath) {
|
||||
gatherHelpItemForTooltip(response, filePath);
|
||||
});
|
||||
registerCustomMethod(inactiveRegionsMethodName(), [this](const JsonRpcMessage &msg) {
|
||||
handleInactiveRegions(this, msg);
|
||||
});
|
||||
|
||||
connect(this, &Client::workDone, this,
|
||||
[this, p = QPointer(project)](const ProgressToken &token) {
|
||||
@@ -692,7 +706,8 @@ class ClangdDiagnosticManager : public LanguageClient::DiagnosticManager
|
||||
return Utils::filtered(diagnostics, [](const Diagnostic &diag){
|
||||
const Diagnostic::Code code = diag.code().value_or(Diagnostic::Code());
|
||||
const QString * const codeString = std::get_if<QString>(&code);
|
||||
return !codeString || *codeString != "drv_unknown_argument";
|
||||
return !codeString || (*codeString != "drv_unknown_argument"
|
||||
&& !codeString->startsWith("drv_unsupported_opt"));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -330,6 +330,8 @@ void doSemanticHighlighting(
|
||||
styles.mainStyle = C_TYPE;
|
||||
} else if (token.type == "modifier") {
|
||||
styles.mainStyle = C_KEYWORD;
|
||||
} else if (token.type == "label") {
|
||||
styles.mainStyle = C_LABEL;
|
||||
} else if (token.type == "typeParameter") {
|
||||
// clangd reports both type and non-type template parameters as type parameters,
|
||||
// but the latter can be distinguished by the readonly modifier.
|
||||
@@ -396,7 +398,10 @@ void doSemanticHighlighting(
|
||||
}
|
||||
};
|
||||
auto results = QtConcurrent::blockingMapped<HighlightingResults>(tokens, safeToResult);
|
||||
const QList<BlockRange> ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents);
|
||||
const bool handleInactiveCode = clangdMajorVersion < 17;
|
||||
QList<BlockRange> ifdefedOutBlocks;
|
||||
if (handleInactiveCode)
|
||||
ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents);
|
||||
ExtraHighlightingResultsCollector(promise, results, filePath, ast, &doc, docContents,
|
||||
clangdVersion).collect();
|
||||
Utils::erase(results, [](const HighlightingResult &res) {
|
||||
@@ -405,10 +410,12 @@ void doSemanticHighlighting(
|
||||
});
|
||||
if (!promise.isCanceled()) {
|
||||
qCInfo(clangdLogHighlight) << "reporting" << results.size() << "highlighting results";
|
||||
QMetaObject::invokeMethod(textDocument, [textDocument, ifdefedOutBlocks, docRevision] {
|
||||
if (textDocument && textDocument->document()->revision() == docRevision)
|
||||
textDocument->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}, Qt::QueuedConnection);
|
||||
if (handleInactiveCode) {
|
||||
QMetaObject::invokeMethod(textDocument, [textDocument, ifdefedOutBlocks, docRevision] {
|
||||
if (textDocument && textDocument->document()->revision() == docRevision)
|
||||
textDocument->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
QList<Range> virtualRanges;
|
||||
for (const HighlightingResult &r : results) {
|
||||
if (r.textStyles.mainStyle != C_VIRTUAL_METHOD)
|
||||
@@ -953,4 +960,45 @@ void ExtraHighlightingResultsCollector::visitNode(const ClangdAstNode &node)
|
||||
m_currentFileStatus = prevFileStatus;
|
||||
}
|
||||
|
||||
class InactiveRegionsParams : public JsonObject
|
||||
{
|
||||
public:
|
||||
using JsonObject::JsonObject;
|
||||
|
||||
DocumentUri uri() const { return TextDocumentIdentifier(value(u"textDocument")).uri(); }
|
||||
QList<Range> inactiveRegions() const { return array<Range>(u"regions"); }
|
||||
};
|
||||
|
||||
class InactiveRegionsNotification : public Notification<InactiveRegionsParams>
|
||||
{
|
||||
public:
|
||||
explicit InactiveRegionsNotification(const InactiveRegionsParams ¶ms)
|
||||
: Notification(inactiveRegionsMethodName(), params) {}
|
||||
using Notification::Notification;
|
||||
};
|
||||
|
||||
void handleInactiveRegions(LanguageClient::Client *client, const JsonRpcMessage &msg)
|
||||
{
|
||||
const auto params = InactiveRegionsNotification(msg.toJsonObject()).params();
|
||||
if (!params)
|
||||
return;
|
||||
TextDocument * const doc = client->documentForFilePath(
|
||||
params->uri().toFilePath(client->hostPathMapper()));
|
||||
if (!doc)
|
||||
return;
|
||||
const QList<Range> inactiveRegions = params->inactiveRegions();
|
||||
QList<BlockRange> ifdefedOutBlocks;
|
||||
for (const Range &r : inactiveRegions) {
|
||||
const int startPos = r.start().toPositionInDocument(doc->document());
|
||||
const int endPos = r.end().toPositionInDocument(doc->document()) + 1;
|
||||
ifdefedOutBlocks.emplaceBack(startPos, endPos);
|
||||
}
|
||||
doc->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}
|
||||
|
||||
QString inactiveRegionsMethodName()
|
||||
{
|
||||
return "textDocument/inactiveRegions";
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel::Internal
|
||||
|
||||
@@ -12,7 +12,11 @@ template <typename T>
|
||||
class QPromise;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace LanguageClient { class ExpandedSemanticToken; }
|
||||
namespace LanguageClient {
|
||||
class Client;
|
||||
class ExpandedSemanticToken;
|
||||
}
|
||||
namespace LanguageServerProtocol { class JsonRpcMessage; }
|
||||
namespace TextEditor {
|
||||
class HighlightingResult;
|
||||
class TextDocument;
|
||||
@@ -36,4 +40,9 @@ void doSemanticHighlighting(
|
||||
const TaskTimer &taskTimer
|
||||
);
|
||||
|
||||
|
||||
QString inactiveRegionsMethodName();
|
||||
void handleInactiveRegions(LanguageClient::Client *client,
|
||||
const LanguageServerProtocol::JsonRpcMessage &msg);
|
||||
|
||||
} // namespace ClangCodeModel::Internal
|
||||
|
||||
@@ -230,7 +230,7 @@ QString DiagnosticTextInfo::option() const
|
||||
return QString();
|
||||
|
||||
const int index = m_squareBracketStartIndex + 1;
|
||||
return m_text.mid(index, m_text.count() - index - 1);
|
||||
return m_text.mid(index, m_text.size() - index - 1);
|
||||
}
|
||||
|
||||
QString DiagnosticTextInfo::category() const
|
||||
|
||||
@@ -1225,8 +1225,10 @@ void ClangdTestHighlighting::test_data()
|
||||
<< QList<int>{C_PUNCTUATION} << int(CppEditor::SemanticHighlighter::AngleBracketClose);
|
||||
QTest::newRow("macro in struct") << 795 << 9 << 795 << 14
|
||||
<< QList<int>{C_MACRO, C_DECLARATION} << 0;
|
||||
QTest::newRow("#ifdef'ed out code") << 800 << 1 << 800 << 17
|
||||
<< QList<int>{C_DISABLED_CODE} << 0;
|
||||
if (client()->versionNumber() < QVersionNumber(17)) {
|
||||
QTest::newRow("#ifdef'ed out code") << 800 << 1 << 800 << 17
|
||||
<< QList<int>{C_DISABLED_CODE} << 0;
|
||||
}
|
||||
QTest::newRow("static function call (object)") << 819 << 5 << 819 << 6
|
||||
<< QList<int>{C_LOCAL} << 0;
|
||||
QTest::newRow("static function call (argument)") << 819 << 18 << 819 << 19
|
||||
@@ -1302,6 +1304,9 @@ void ClangdTestHighlighting::test_data()
|
||||
QTest::newRow("concept definition") << 1053 << 30 << 1053 << 42
|
||||
<< QList<int>{C_TYPE, C_DECLARATION} << 0;
|
||||
QTest::newRow("concept use") << 1054 << 29 << 1054 << 41 << QList<int>{C_TYPE} << 0;
|
||||
QTest::newRow("label declaration") << 242 << 1 << 242 << 11
|
||||
<< QList<int>{C_LABEL, C_DECLARATION} << 0;
|
||||
QTest::newRow("label use") << 244 << 10 << 244 << 20 << QList<int>{C_LABEL} << 0;
|
||||
}
|
||||
|
||||
void ClangdTestHighlighting::test()
|
||||
|
||||
Reference in New Issue
Block a user