LanguageClient: add support for proposed semantic highlight

implements the current proposal for the semantic highlighting
via the language server protocol.
https://github.com/microsoft/vscode-languageserver-node/pull/367

Change-Id: I857d606fcf5c782e0ea8e18e5d098edd26286aed
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
David Schulz
2019-06-12 12:55:06 +02:00
parent b6a9f0245b
commit 307f1d8e6e
19 changed files with 515 additions and 27 deletions

View File

@@ -48,6 +48,7 @@ constexpr const char DocumentRangeFormattingRequest::methodName[];
constexpr const char DocumentOnTypeFormattingRequest::methodName[];
constexpr const char RenameRequest::methodName[];
constexpr const char SignatureHelpRequest::methodName[];
constexpr const char SemanticHighlightNotification::methodName[];
HoverContent LanguageServerProtocol::Hover::content() const
{
@@ -441,4 +442,59 @@ bool CodeAction::isValid(QStringList *error) const
&& checkOptional<Command>(error, commandKey);
}
Utils::optional<QList<SemanticHighlightToken>> SemanticHighlightingInformation::tokens() const
{
QList<SemanticHighlightToken> resultTokens;
const QByteArray tokensByteArray = QByteArray::fromBase64(
typedValue<QString>(tokensKey).toLocal8Bit());
constexpr int tokensByteSize = 8;
int index = 0;
while (index + tokensByteSize <= tokensByteArray.size()) {
resultTokens << SemanticHighlightToken(tokensByteArray.mid(index, tokensByteSize));
index += tokensByteSize;
}
return Utils::make_optional(resultTokens);
}
void SemanticHighlightingInformation::setTokens(const QList<SemanticHighlightToken> &tokens)
{
QByteArray byteArray;
byteArray.reserve(8 * tokens.size());
for (const SemanticHighlightToken &token : tokens)
token.appendToByteArray(byteArray);
insert(tokensKey, QString::fromLocal8Bit(byteArray.toBase64()));
}
SemanticHighlightToken::SemanticHighlightToken(const QByteArray &token)
{
QTC_ASSERT(token.size() == 8, return );
character = ( quint32(token.at(0)) << 24
| quint32(token.at(1)) << 16
| quint32(token.at(2)) << 8
| quint32(token.at(3)));
length = quint16(token.at(4) << 8 | token.at(5));
scope = quint16(token.at(6) << 8 | token.at(7));
}
void SemanticHighlightToken::appendToByteArray(QByteArray &byteArray) const
{
byteArray.append(char((character & 0xff000000) >> 24));
byteArray.append(char((character & 0x00ff0000) >> 16));
byteArray.append(char((character & 0x0000ff00) >> 8));
byteArray.append(char((character & 0x000000ff)));
byteArray.append(char((length & 0xff00) >> 8));
byteArray.append(char((length & 0x00ff)));
byteArray.append(char((scope & 0xff00) >> 8));
byteArray.append(char((scope & 0x00ff)));
}
bool SemanticHighlightingParams::isValid(QStringList *error) const
{
return check<VersionedTextDocumentIdentifier>(error, textDocumentKey)
&& checkArray<SemanticHighlightingInformation>(error, linesKey);
}
} // namespace LanguageServerProtocol