forked from qt-creator/qt-creator
LSP: allow non versioned text document in SemanticHighlightingParams
The proposal of SemanticHighlighting uses a versioned text document identifier, but there is a suggestion to be more coherent with other existing requests and use text document identifier instead (non versionned). See here: https://github.com/microsoft/vscode-languageserver-node/pull/367/files#r225879268 The clangd language server implements the non versioned version. Existing code was returning errors with clangd because SemanticHighlightingParams::isValid would return false because of the missing version field. Change-Id: I1c36151342437adad2405118ca6b303db0936e41 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -491,10 +491,24 @@ void SemanticHighlightToken::appendToByteArray(QByteArray &byteArray) const
|
|||||||
byteArray.append(char((scope & 0x00ff)));
|
byteArray.append(char((scope & 0x00ff)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::variant<VersionedTextDocumentIdentifier, TextDocumentIdentifier>
|
||||||
|
SemanticHighlightingParams::textDocument() const
|
||||||
|
{
|
||||||
|
VersionedTextDocumentIdentifier textDocument = fromJsonValue<VersionedTextDocumentIdentifier>(
|
||||||
|
value(textDocumentKey));
|
||||||
|
ErrorHierarchy error;
|
||||||
|
if (!textDocument.isValid(&error)) {
|
||||||
|
return TextDocumentIdentifier(textDocument);
|
||||||
|
} else {
|
||||||
|
return textDocument;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SemanticHighlightingParams::isValid(ErrorHierarchy *error) const
|
bool SemanticHighlightingParams::isValid(ErrorHierarchy *error) const
|
||||||
{
|
{
|
||||||
return check<VersionedTextDocumentIdentifier>(error, textDocumentKey)
|
return checkVariant<VersionedTextDocumentIdentifier, TextDocumentIdentifier>(error,
|
||||||
&& checkArray<SemanticHighlightingInformation>(error, linesKey);
|
textDocumentKey)
|
||||||
|
&& checkArray<SemanticHighlightingInformation>(error, linesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace LanguageServerProtocol
|
} // namespace LanguageServerProtocol
|
||||||
|
@@ -841,8 +841,9 @@ class LANGUAGESERVERPROTOCOL_EXPORT SemanticHighlightingParams : public JsonObje
|
|||||||
public:
|
public:
|
||||||
using JsonObject::JsonObject;
|
using JsonObject::JsonObject;
|
||||||
|
|
||||||
VersionedTextDocumentIdentifier textDocument() const
|
Utils::variant<VersionedTextDocumentIdentifier, TextDocumentIdentifier> textDocument() const;
|
||||||
{ return typedValue<VersionedTextDocumentIdentifier>(textDocumentKey); }
|
void setTextDocument(const TextDocumentIdentifier &textDocument)
|
||||||
|
{ insert(textDocumentKey, textDocument); }
|
||||||
void setTextDocument(const VersionedTextDocumentIdentifier &textDocument)
|
void setTextDocument(const VersionedTextDocumentIdentifier &textDocument)
|
||||||
{ insert(textDocumentKey, textDocument); }
|
{ insert(textDocumentKey, textDocument); }
|
||||||
|
|
||||||
|
@@ -1215,9 +1215,18 @@ void Client::handleDiagnostics(const PublishDiagnosticsParams ¶ms)
|
|||||||
|
|
||||||
void Client::handleSemanticHighlight(const SemanticHighlightingParams ¶ms)
|
void Client::handleSemanticHighlight(const SemanticHighlightingParams ¶ms)
|
||||||
{
|
{
|
||||||
const DocumentUri &uri = params.textDocument().uri();
|
DocumentUri uri;
|
||||||
|
LanguageClientValue<int> version;
|
||||||
|
auto textDocument = params.textDocument();
|
||||||
|
|
||||||
|
if (Utils::holds_alternative<VersionedTextDocumentIdentifier>(textDocument)) {
|
||||||
|
uri = Utils::get<VersionedTextDocumentIdentifier>(textDocument).uri();
|
||||||
|
version = Utils::get<VersionedTextDocumentIdentifier>(textDocument).version();
|
||||||
|
} else {
|
||||||
|
uri = Utils::get<TextDocumentIdentifier>(textDocument).uri();
|
||||||
|
}
|
||||||
|
|
||||||
m_highlights[uri].clear();
|
m_highlights[uri].clear();
|
||||||
const LanguageClientValue<int> &version = params.textDocument().version();
|
|
||||||
TextEditor::TextDocument *doc = TextEditor::TextDocument::textDocumentForFilePath(
|
TextEditor::TextDocument *doc = TextEditor::TextDocument::textDocumentForFilePath(
|
||||||
uri.toFilePath());
|
uri.toFilePath());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user