Update to LSP version 3.16 semantic tokens protocol

This commit is contained in:
Tadeo Kondrak 2020-09-25 15:24:10 -06:00
parent 2559f5c6fd
commit b52817cd8f
No known key found for this signature in database
GPG Key ID: D41E092CA43F1D8B
4 changed files with 8 additions and 7 deletions

View File

@ -1140,7 +1140,7 @@ fn openDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req
const handle = try document_store.openDocument(req.params.textDocument.uri, req.params.textDocument.text);
try publishDiagnostics(arena, handle.*, configFromUriOr(req.params.textDocument.uri, config));
try semanticTokensHandler(arena, id, .{ .params = .{ .textDocument = .{ .uri = req.params.textDocument.uri } } }, config);
try semanticTokensFullHandler(arena, id, .{ .params = .{ .textDocument = .{ .uri = req.params.textDocument.uri } } }, config);
}
fn changeDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.ChangeDocument, config: Config) !void {
@ -1166,7 +1166,7 @@ fn closeDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, re
document_store.closeDocument(req.params.textDocument.uri);
}
fn semanticTokensHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.SemanticTokens, config: Config) (error{OutOfMemory} || std.fs.File.WriteError)!void {
fn semanticTokensFullHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.SemanticTokensFull, config: Config) (error{OutOfMemory} || std.fs.File.WriteError)!void {
const this_config = configFromUriOr(req.params.textDocument.uri, config);
if (this_config.enable_semantic_tokens) {
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
@ -1180,7 +1180,7 @@ fn semanticTokensHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, r
return try send(arena, types.Response{
.id = id,
.result = .{ .SemanticTokens = .{ .data = token_array } },
.result = .{ .SemanticTokensFull = .{ .data = token_array } },
});
}
}
@ -1427,7 +1427,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
.{ "textDocument/didChange", requests.ChangeDocument, changeDocumentHandler },
.{ "textDocument/didSave", requests.SaveDocument, saveDocumentHandler },
.{ "textDocument/didClose", requests.CloseDocument, closeDocumentHandler },
.{ "textDocument/semanticTokens", requests.SemanticTokens, semanticTokensHandler },
.{ "textDocument/semanticTokens/full", requests.SemanticTokensFull, semanticTokensFullHandler },
.{ "textDocument/completion", requests.Completion, completionHandler },
.{ "textDocument/signatureHelp", void, signatureHelperHandler },
.{ "textDocument/definition", requests.GotoDefinition, gotoDefinitionHandler },
@ -1482,6 +1482,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
.{"textDocument/prepareRename"},
.{"textDocument/foldingRange"},
.{"textDocument/selectionRange"},
.{"textDocument/semanticTokens/range"},
});
if (unimplemented_map.has(method)) {

View File

@ -186,7 +186,7 @@ const TextDocumentIdentifierRequest = struct {
pub const SaveDocument = TextDocumentIdentifierRequest;
pub const CloseDocument = TextDocumentIdentifierRequest;
pub const SemanticTokens = TextDocumentIdentifierRequest;
pub const SemanticTokensFull = TextDocumentIdentifierRequest;
const TextDocumentIdentifierPositionRequest = struct {
params: struct {

View File

@ -56,7 +56,7 @@ pub const ResponseParams = union(enum) {
Location: Location,
Hover: Hover,
DocumentSymbols: []DocumentSymbol,
SemanticTokens: struct { data: []const u32 },
SemanticTokensFull: struct { data: []const u32 },
TextEdits: []TextEdit,
Locations: []Location,
WorkspaceEdit: WorkspaceEdit,

View File

@ -92,7 +92,7 @@ test "Open file, ask for semantic tokens" {
const new_file_req = \\{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://./tests/test.zig","languageId":"zig","version":420,"text":"const std = @import(\"std\");"}}}
;
try sendRequest(new_file_req, process);
const sem_toks_req = \\{"jsonrpc":"2.0","id":2,"method":"textDocument/semanticTokens","params":{"textDocument":{"uri":"file://./tests/test.zig"}}}
const sem_toks_req = \\{"jsonrpc":"2.0","id":2,"method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"file://./tests/test.zig"}}}
;
try sendRequest(sem_toks_req, process);
try sendRequest(shutdown_message, process);