Merge pull request #163 from tadeokondrak/lsp-3.16-semantic-tokens

LSP 3.16 semantic tokens
This commit is contained in:
Alexandros Naskos 2020-09-27 14:29:43 +03:00 committed by GitHub
commit 789f3b1781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 8 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

@ -32,7 +32,16 @@ const TokenModifiers = packed struct {
generic: bool = false,
fn toInt(self: TokenModifiers) u32 {
return @as(u32, @bitCast(u4, self));
var res: u32 = 0;
if (self.definition)
res |= 1 << 0;
if (self.@"async")
res |= 1 << 1;
if (self.documentation)
res |= 1 << 2;
if (self.generic)
res |= 1 << 3;
return res;
}
inline fn set(self: *TokenModifiers, comptime field: []const u8) void {

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);