diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 1d794b1898c70f..b0aba886edbe48 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 CB) { +void ClangdLSPServer::onSemanticTokensDelta( + const SemanticTokensDeltaParams &Params, + Callback CB) { Server->semanticHighlights( Params.textDocument.uri.file(), [this, PrevResultID(Params.previousResultId), @@ -1323,7 +1323,7 @@ void ClangdLSPServer::onSemanticTokensEdits( return CB(HT.takeError()); std::vector Toks = toSemanticTokens(*HT); - SemanticTokensOrEdits Result; + SemanticTokensOrDelta Result; { std::lock_guard Lock(SemanticTokensMutex); auto &Last = LastSemanticTokens[File]; @@ -1331,8 +1331,8 @@ void ClangdLSPServer::onSemanticTokensEdits( if (PrevResultID == Last.resultId) { Result.edits = diffTokens(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 6ccef9500679c1..a779e9036c4a86 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>); void onSemanticTokens(const SemanticTokensParams &, Callback); - void onSemanticTokensEdits(const SemanticTokensEditsParams &, - Callback); + void onSemanticTokensDelta(const SemanticTokensDeltaParams &, + Callback); std::vector getFixes(StringRef File, const clangd::Diagnostic &D); diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index ecae65336e5b1b..23960371578536 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 0177ee262ae347..77d402a6a9ba1f 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 tokens; + /// The actual tokens. + std::vector 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 tokens; + std::vector 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> edits; /// Set if we computed a fresh set of tokens. - llvm::Optional> tokens; + llvm::Optional> 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 f1f5312d100968..f0a0f791c2f685 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 6fab10362b2854..ed0c0d09a13ed6 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" }}