Author: Sam McCall Date: 2020-07-10T16:52:57+02:00 New Revision: 5fea54bc05a71e81e843fd9284d258cd38d7fe23
URL: https://github.com/llvm/llvm-project/commit/5fea54bc05a71e81e843fd9284d258cd38d7fe23 DIFF: https://github.com/llvm/llvm-project/commit/5fea54bc05a71e81e843fd9284d258cd38d7fe23.diff LOG: [clangd] Update semanticTokens support to reflect latest LSP draft Summary: Mostly a few methods and message names have been renamed. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83556 Added: Modified: clang-tools-extra/clangd/ClangdLSPServer.cpp clang-tools-extra/clangd/ClangdLSPServer.h clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h clang-tools-extra/clangd/test/initialize-params.test clang-tools-extra/clangd/test/semantic-tokens.test Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 1d794b1898c7..b0aba886edbe 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -599,8 +599,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params, }}, {"semanticTokensProvider", llvm::json::Object{ - {"documentProvider", llvm::json::Object{{"edits", true}}}, - {"rangeProvider", false}, + {"full", llvm::json::Object{{"delta", true}}}, + {"range", false}, {"legend", llvm::json::Object{{"tokenTypes", semanticTokenTypes()}, {"tokenModifiers", llvm::json::Array()}}}, @@ -1311,9 +1311,9 @@ void ClangdLSPServer::onSemanticTokens(const SemanticTokensParams &Params, }); } -void ClangdLSPServer::onSemanticTokensEdits( - const SemanticTokensEditsParams &Params, - Callback<SemanticTokensOrEdits> CB) { +void ClangdLSPServer::onSemanticTokensDelta( + const SemanticTokensDeltaParams &Params, + Callback<SemanticTokensOrDelta> CB) { Server->semanticHighlights( Params.textDocument.uri.file(), [this, PrevResultID(Params.previousResultId), @@ -1323,7 +1323,7 @@ void ClangdLSPServer::onSemanticTokensEdits( return CB(HT.takeError()); std::vector<SemanticToken> Toks = toSemanticTokens(*HT); - SemanticTokensOrEdits Result; + SemanticTokensOrDelta Result; { std::lock_guard<std::mutex> Lock(SemanticTokensMutex); auto &Last = LastSemanticTokens[File]; @@ -1331,8 +1331,8 @@ void ClangdLSPServer::onSemanticTokensEdits( if (PrevResultID == Last.resultId) { Result.edits = diff Tokens(Last.tokens, Toks); } else { - vlog("semanticTokens/edits: wanted edits vs {0} but last result " - "had ID {1}. Returning full token list.", + vlog("semanticTokens/full/delta: wanted edits vs {0} but last " + "result had ID {1}. Returning full token list.", PrevResultID, Last.resultId); Result.tokens = Toks; } @@ -1393,8 +1393,8 @@ ClangdLSPServer::ClangdLSPServer( MsgHandler->bind("typeHierarchy/resolve", &ClangdLSPServer::onResolveTypeHierarchy); MsgHandler->bind("textDocument/selectionRange", &ClangdLSPServer::onSelectionRange); MsgHandler->bind("textDocument/documentLink", &ClangdLSPServer::onDocumentLink); - MsgHandler->bind("textDocument/semanticTokens", &ClangdLSPServer::onSemanticTokens); - MsgHandler->bind("textDocument/semanticTokens/edits", &ClangdLSPServer::onSemanticTokensEdits); + MsgHandler->bind("textDocument/semanticTokens/full", &ClangdLSPServer::onSemanticTokens); + MsgHandler->bind("textDocument/semanticTokens/full/delta", &ClangdLSPServer::onSemanticTokensDelta); // clang-format on } diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 6ccef9500679..a779e9036c4a 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -121,8 +121,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks { void onDocumentLink(const DocumentLinkParams &, Callback<std::vector<DocumentLink>>); void onSemanticTokens(const SemanticTokensParams &, Callback<SemanticTokens>); - void onSemanticTokensEdits(const SemanticTokensEditsParams &, - Callback<SemanticTokensOrEdits>); + void onSemanticTokensDelta(const SemanticTokensDeltaParams &, + Callback<SemanticTokensOrDelta>); std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D); diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index ecae65336e5b..239603715785 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -1029,7 +1029,7 @@ llvm::json::Value toJSON(const SemanticTokensEdit &Edit) { {"data", encodeTokens(Edit.tokens)}}; } -llvm::json::Value toJSON(const SemanticTokensOrEdits &TE) { +llvm::json::Value toJSON(const SemanticTokensOrDelta &TE) { llvm::json::Object Result{{"resultId", TE.resultId}}; if (TE.edits) Result["edits"] = *TE.edits; @@ -1043,7 +1043,7 @@ bool fromJSON(const llvm::json::Value &Params, SemanticTokensParams &R) { return O && O.map("textDocument", R.textDocument); } -bool fromJSON(const llvm::json::Value &Params, SemanticTokensEditsParams &R) { +bool fromJSON(const llvm::json::Value &Params, SemanticTokensDeltaParams &R) { llvm::json::ObjectMapper O(Params); return O && O.map("textDocument", R.textDocument) && O.map("previousResultId", R.previousResultId); diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index 0177ee262ae3..77d402a6a9ba 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -1384,27 +1384,27 @@ struct SemanticTokens { // send a delta. std::string resultId; - /// The actual tokens. For a detailed description about how the data is - /// structured pls see - /// https://github.com/microsoft/vscode-extension-samples/blob/5ae1f7787122812dcc84e37427ca90af5ee09f14/semantic-tokens-sample/vscode.proposed.d.ts#L71 - std::vector<SemanticToken> tokens; + /// The actual tokens. + std::vector<SemanticToken> tokens; // encoded as a flat integer array. }; llvm::json::Value toJSON(const SemanticTokens &); +/// Body of textDocument/semanticTokens/full request. struct SemanticTokensParams { /// The text document. TextDocumentIdentifier textDocument; }; bool fromJSON(const llvm::json::Value &, SemanticTokensParams &); +/// Body of textDocument/semanticTokens/full/delta request. /// Requests the changes in semantic tokens since a previous response. -struct SemanticTokensEditsParams { +struct SemanticTokensDeltaParams { /// The text document. TextDocumentIdentifier textDocument; /// The previous result id. std::string previousResultId; }; -bool fromJSON(const llvm::json::Value &Params, SemanticTokensEditsParams &R); +bool fromJSON(const llvm::json::Value &Params, SemanticTokensDeltaParams &R); /// Describes a a replacement of a contiguous range of semanticTokens. struct SemanticTokensEdit { @@ -1413,20 +1413,20 @@ struct SemanticTokensEdit { // We use token counts instead, and translate when serializing this struct. unsigned startToken = 0; unsigned deleteTokens = 0; - std::vector<SemanticToken> tokens; + std::vector<SemanticToken> tokens; // encoded as a flat integer array }; llvm::json::Value toJSON(const SemanticTokensEdit &); -/// This models LSP SemanticTokensEdits | SemanticTokens, which is the result of -/// textDocument/semanticTokens/edits. -struct SemanticTokensOrEdits { +/// This models LSP SemanticTokensDelta | SemanticTokens, which is the result of +/// textDocument/semanticTokens/full/delta. +struct SemanticTokensOrDelta { std::string resultId; /// Set if we computed edits relative to a previous set of tokens. llvm::Optional<std::vector<SemanticTokensEdit>> edits; /// Set if we computed a fresh set of tokens. - llvm::Optional<std::vector<SemanticToken>> tokens; + llvm::Optional<std::vector<SemanticToken>> tokens; // encoded as integer array }; -llvm::json::Value toJSON(const SemanticTokensOrEdits &); +llvm::json::Value toJSON(const SemanticTokensOrDelta &); /// Represents a semantic highlighting information that has to be applied on a /// specific line of the text document. diff --git a/clang-tools-extra/clangd/test/initialize-params.test b/clang-tools-extra/clangd/test/initialize-params.test index f1f5312d1009..f0a0f791c2f6 100644 --- a/clang-tools-extra/clangd/test/initialize-params.test +++ b/clang-tools-extra/clangd/test/initialize-params.test @@ -42,8 +42,8 @@ # CHECK-NEXT: "renameProvider": true, # CHECK-NEXT: "selectionRangeProvider": true, # CHECK-NEXT: "semanticTokensProvider": { -# CHECK-NEXT: "documentProvider": { -# CHECK-NEXT: "edits": true +# CHECK-NEXT: "full": { +# CHECK-NEXT: "delta": true # CHECK-NEXT: }, # CHECK-NEXT: "legend": { # CHECK-NEXT: "tokenModifiers": [], @@ -51,7 +51,7 @@ # CHECK-NEXT: "variable", # CHECK: ] # CHECK-NEXT: }, -# CHECK-NEXT: "rangeProvider": false +# CHECK-NEXT: "range": false # CHECK-NEXT: }, # CHECK-NEXT: "signatureHelpProvider": { # CHECK-NEXT: "triggerCharacters": [ diff --git a/clang-tools-extra/clangd/test/semantic-tokens.test b/clang-tools-extra/clangd/test/semantic-tokens.test index 6fab10362b28..ed0c0d09a13e 100644 --- a/clang-tools-extra/clangd/test/semantic-tokens.test +++ b/clang-tools-extra/clangd/test/semantic-tokens.test @@ -13,7 +13,7 @@ }}} --- # Non-incremental token request. -{"jsonrpc":"2.0","id":1,"method":"textDocument/semanticTokens","params":{"textDocument":{"uri":"test:///foo.cpp"}}} +{"jsonrpc":"2.0","id":1,"method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"test:///foo.cpp"}}} # CHECK: "id": 1, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": { @@ -34,7 +34,7 @@ }} --- # Incremental token request, based on previous response. -{"jsonrpc":"2.0","id":2,"method":"textDocument/semanticTokens/edits","params":{ +{"jsonrpc":"2.0","id":2,"method":"textDocument/semanticTokens/full/delta","params":{ "textDocument": {"uri":"test:///foo.cpp"}, "previousResultId": "1" }} @@ -60,7 +60,7 @@ # CHECK-NEXT: } --- # Incremental token request with incorrect baseline => full tokens list. -{"jsonrpc":"2.0","id":2,"method":"textDocument/semanticTokens/edits","params":{ +{"jsonrpc":"2.0","id":2,"method":"textDocument/semanticTokens/full/delta","params":{ "textDocument": {"uri":"test:///foo.cpp"}, "previousResultId": "bogus" }} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits