Added offsetEncoding clangd extension support
This commit is contained in:
parent
9bed369797
commit
f6df9d4c0a
23
src/main.zig
23
src/main.zig
@ -88,10 +88,12 @@ const ClientCapabilities = struct {
|
|||||||
var client_capabilities = ClientCapabilities{};
|
var client_capabilities = ClientCapabilities{};
|
||||||
var offset_encoding = offsets.Encoding.utf16;
|
var offset_encoding = offsets.Encoding.utf16;
|
||||||
|
|
||||||
const initialize_response =
|
const initialize_capabilities =
|
||||||
\\,"result": {"capabilities": {"signatureHelpProvider": {"triggerCharacters": ["(",","]},"textDocumentSync": 1,"renameProvider":true,"completionProvider": {"resolveProvider": false,"triggerCharacters": [".",":","@"]},"documentHighlightProvider": false,"hoverProvider": true,"codeActionProvider": false,"declarationProvider": true,"definitionProvider": true,"typeDefinitionProvider": true,"implementationProvider": false,"referencesProvider": false,"documentSymbolProvider": true,"colorProvider": false,"documentFormattingProvider": true,"documentRangeFormattingProvider": false,"foldingRangeProvider": false,"selectionRangeProvider": false,"workspaceSymbolProvider": false,"rangeProvider": false,"documentProvider": true,"workspace": {"workspaceFolders": {"supported": true,"changeNotifications": true}},"semanticTokensProvider": {"documentProvider": true,"legend": {"tokenTypes": ["namespace","type","struct","enum","union","parameter","variable","tagField","field","errorTag","function","keyword","comment","string","number","operator","builtin","label"],"tokenModifiers": ["definition","async","documentation", "generic"]}}}}}
|
\\"capabilities": {"signatureHelpProvider": {"triggerCharacters": ["(",","]},"textDocumentSync": 1,"renameProvider":true,"completionProvider": {"resolveProvider": false,"triggerCharacters": [".",":","@"]},"documentHighlightProvider": false,"hoverProvider": true,"codeActionProvider": false,"declarationProvider": true,"definitionProvider": true,"typeDefinitionProvider": true,"implementationProvider": false,"referencesProvider": false,"documentSymbolProvider": true,"colorProvider": false,"documentFormattingProvider": true,"documentRangeFormattingProvider": false,"foldingRangeProvider": false,"selectionRangeProvider": false,"workspaceSymbolProvider": false,"rangeProvider": false,"documentProvider": true,"workspace": {"workspaceFolders": {"supported": true,"changeNotifications": true}},"semanticTokensProvider": {"documentProvider": true,"legend": {"tokenTypes": ["namespace","type","struct","enum","union","parameter","variable","tagField","field","errorTag","function","keyword","comment","string","number","operator","builtin","label"],"tokenModifiers": ["definition","async","documentation", "generic"]}}}}}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
const initialize_response = ",\"result\": {" ++ initialize_capabilities;
|
||||||
|
|
||||||
const not_implemented_response =
|
const not_implemented_response =
|
||||||
\\,"error":{"code":-32601,"message":"NotImplemented"}}
|
\\,"error":{"code":-32601,"message":"NotImplemented"}}
|
||||||
;
|
;
|
||||||
@ -957,6 +959,13 @@ fn configFromUriOr(uri: []const u8, default: Config) Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Initialize, config: Config) !void {
|
fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Initialize, config: Config) !void {
|
||||||
|
var send_encoding = req.params.capabilities.offsetEncoding.value.len != 0;
|
||||||
|
for (req.params.capabilities.offsetEncoding.value) |encoding| {
|
||||||
|
if (std.mem.eql(u8, encoding, "utf-8")) {
|
||||||
|
offset_encoding = .utf8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (req.params.capabilities.workspace) |workspace| {
|
if (req.params.capabilities.workspace) |workspace| {
|
||||||
client_capabilities.supports_workspace_folders = workspace.workspaceFolders.value;
|
client_capabilities.supports_workspace_folders = workspace.workspaceFolders.value;
|
||||||
}
|
}
|
||||||
@ -995,7 +1004,17 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std.log.debug(.main, "{}\n", .{client_capabilities});
|
std.log.debug(.main, "{}\n", .{client_capabilities});
|
||||||
|
std.log.debug(.main, "Using offset encoding: {}\n", .{std.meta.tagName(offset_encoding)});
|
||||||
|
if (!send_encoding) {
|
||||||
try respondGeneric(id, initialize_response);
|
try respondGeneric(id, initialize_response);
|
||||||
|
} else {
|
||||||
|
const response_str = try std.fmt.allocPrint(&arena.allocator, ",\"result\": {{\"offsetEncoding\":\"{}\",{}", .{
|
||||||
|
if (offset_encoding == .utf8) @as([]const u8, "utf-8")
|
||||||
|
else @as([]const u8, "utf-16"),
|
||||||
|
initialize_capabilities
|
||||||
|
});
|
||||||
|
try respondGeneric(id, response_str);
|
||||||
|
}
|
||||||
std.log.notice(.main, "zls initialized", .{});
|
std.log.notice(.main, "zls initialized", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +140,7 @@ pub const Initialize = struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
offsetEncoding: MaybeStringArray,
|
||||||
};
|
};
|
||||||
|
|
||||||
params: struct {
|
params: struct {
|
||||||
|
@ -114,3 +114,14 @@ test "Requesting a completion with no trailing whitespace" {
|
|||||||
try consumeOutputAndWait(process);
|
try consumeOutputAndWait(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initialize_message_offs = \\{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":6896,"clientInfo":{"name":"vscode","version":"1.46.1"},"rootPath":null,"rootUri":null,"capabilities":{"offsetEncoding":["utf-16", "utf-8"],"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"complexDiagnosticCodeSupport":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]}},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["comment","keyword","number","regexp","operator","namespace","type","struct","class","interface","enum","typeParameter","function","member","macro","variable","parameter","property","label"],"tokenModifiers":["declaration","documentation","static","abstract","deprecated","readonly"]}},"window":{"workDoneProgress":true}},"trace":"off","workspaceFolders":null}}
|
||||||
|
;
|
||||||
|
|
||||||
|
test "Requesting utf-8 offset encoding" {
|
||||||
|
var process = try startZls();
|
||||||
|
try sendRequest(initialize_message_offs, process);
|
||||||
|
try sendRequest(initialized_message, process);
|
||||||
|
|
||||||
|
try sendRequest(shutdown_message, process);
|
||||||
|
try consumeOutputAndWait(process);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user