Merge pull request #163 from tadeokondrak/lsp-3.16-semantic-tokens
LSP 3.16 semantic tokens
This commit is contained in:
commit
789f3b1781
@ -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);
|
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 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 {
|
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);
|
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);
|
const this_config = configFromUriOr(req.params.textDocument.uri, config);
|
||||||
if (this_config.enable_semantic_tokens) {
|
if (this_config.enable_semantic_tokens) {
|
||||||
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
|
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{
|
return try send(arena, types.Response{
|
||||||
.id = id,
|
.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/didChange", requests.ChangeDocument, changeDocumentHandler },
|
||||||
.{ "textDocument/didSave", requests.SaveDocument, saveDocumentHandler },
|
.{ "textDocument/didSave", requests.SaveDocument, saveDocumentHandler },
|
||||||
.{ "textDocument/didClose", requests.CloseDocument, closeDocumentHandler },
|
.{ "textDocument/didClose", requests.CloseDocument, closeDocumentHandler },
|
||||||
.{ "textDocument/semanticTokens", requests.SemanticTokens, semanticTokensHandler },
|
.{ "textDocument/semanticTokens/full", requests.SemanticTokensFull, semanticTokensFullHandler },
|
||||||
.{ "textDocument/completion", requests.Completion, completionHandler },
|
.{ "textDocument/completion", requests.Completion, completionHandler },
|
||||||
.{ "textDocument/signatureHelp", void, signatureHelperHandler },
|
.{ "textDocument/signatureHelp", void, signatureHelperHandler },
|
||||||
.{ "textDocument/definition", requests.GotoDefinition, gotoDefinitionHandler },
|
.{ "textDocument/definition", requests.GotoDefinition, gotoDefinitionHandler },
|
||||||
@ -1482,6 +1482,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
|
|||||||
.{"textDocument/prepareRename"},
|
.{"textDocument/prepareRename"},
|
||||||
.{"textDocument/foldingRange"},
|
.{"textDocument/foldingRange"},
|
||||||
.{"textDocument/selectionRange"},
|
.{"textDocument/selectionRange"},
|
||||||
|
.{"textDocument/semanticTokens/range"},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (unimplemented_map.has(method)) {
|
if (unimplemented_map.has(method)) {
|
||||||
|
@ -186,7 +186,7 @@ const TextDocumentIdentifierRequest = struct {
|
|||||||
|
|
||||||
pub const SaveDocument = TextDocumentIdentifierRequest;
|
pub const SaveDocument = TextDocumentIdentifierRequest;
|
||||||
pub const CloseDocument = TextDocumentIdentifierRequest;
|
pub const CloseDocument = TextDocumentIdentifierRequest;
|
||||||
pub const SemanticTokens = TextDocumentIdentifierRequest;
|
pub const SemanticTokensFull = TextDocumentIdentifierRequest;
|
||||||
|
|
||||||
const TextDocumentIdentifierPositionRequest = struct {
|
const TextDocumentIdentifierPositionRequest = struct {
|
||||||
params: struct {
|
params: struct {
|
||||||
|
@ -32,7 +32,16 @@ const TokenModifiers = packed struct {
|
|||||||
generic: bool = false,
|
generic: bool = false,
|
||||||
|
|
||||||
fn toInt(self: TokenModifiers) u32 {
|
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 {
|
inline fn set(self: *TokenModifiers, comptime field: []const u8) void {
|
||||||
|
@ -56,7 +56,7 @@ pub const ResponseParams = union(enum) {
|
|||||||
Location: Location,
|
Location: Location,
|
||||||
Hover: Hover,
|
Hover: Hover,
|
||||||
DocumentSymbols: []DocumentSymbol,
|
DocumentSymbols: []DocumentSymbol,
|
||||||
SemanticTokens: struct { data: []const u32 },
|
SemanticTokensFull: struct { data: []const u32 },
|
||||||
TextEdits: []TextEdit,
|
TextEdits: []TextEdit,
|
||||||
Locations: []Location,
|
Locations: []Location,
|
||||||
WorkspaceEdit: WorkspaceEdit,
|
WorkspaceEdit: WorkspaceEdit,
|
||||||
|
@ -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\");"}}}
|
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);
|
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(sem_toks_req, process);
|
||||||
try sendRequest(shutdown_message, process);
|
try sendRequest(shutdown_message, process);
|
||||||
|
Loading…
Reference in New Issue
Block a user