Skip to content

Commit 892847d

Browse files
committed
Removed workspace specific zls.json support
1 parent 6e107e7 commit 892847d

File tree

1 file changed

+20
-103
lines changed

1 file changed

+20
-103
lines changed

src/main.zig

+20-103
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,12 @@ var stdout: std.io.BufferedOutStream(4096, std.fs.File.OutStream) = undefined;
9292
var allocator: *std.mem.Allocator = undefined;
9393

9494
var document_store: DocumentStore = undefined;
95-
var workspace_folder_configs: std.StringHashMap(?Config) = undefined;
9695

9796
const ClientCapabilities = struct {
9897
supports_snippets: bool = false,
9998
supports_semantic_tokens: bool = false,
10099
hover_supports_md: bool = false,
101100
completion_doc_supports_md: bool = false,
102-
supports_workspace_folders: bool = false,
103101
};
104102

105103
var client_capabilities = ClientCapabilities{};
@@ -1055,40 +1053,13 @@ fn loadConfig(folder_path: []const u8) ?Config {
10551053
return config;
10561054
}
10571055

1058-
fn loadWorkspaceConfigs() !void {
1059-
var folder_config_it = workspace_folder_configs.iterator();
1060-
while (folder_config_it.next()) |entry| {
1061-
if (entry.value) |_| continue;
1062-
1063-
const folder_path = try URI.parse(allocator, entry.key);
1064-
defer allocator.free(folder_path);
1065-
1066-
entry.value = loadConfig(folder_path);
1067-
}
1068-
}
1069-
1070-
fn configFromUriOr(uri: []const u8, default: Config) Config {
1071-
var folder_config_it = workspace_folder_configs.iterator();
1072-
while (folder_config_it.next()) |entry| {
1073-
if (std.mem.startsWith(u8, uri, entry.key)) {
1074-
return entry.value orelse default;
1075-
}
1076-
}
1077-
1078-
return default;
1079-
}
1080-
10811056
fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Initialize, config: Config) !void {
10821057
for (req.params.capabilities.offsetEncoding.value) |encoding| {
10831058
if (std.mem.eql(u8, encoding, "utf-8")) {
10841059
offset_encoding = .utf8;
10851060
}
10861061
}
10871062

1088-
if (req.params.capabilities.workspace) |workspace| {
1089-
client_capabilities.supports_workspace_folders = workspace.workspaceFolders.value;
1090-
}
1091-
10921063
if (req.params.capabilities.textDocument) |textDocument| {
10931064
client_capabilities.supports_semantic_tokens = textDocument.semanticTokens.exists;
10941065
if (textDocument.hover) |hover| {
@@ -1110,18 +1081,6 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
11101081
}
11111082
}
11121083

1113-
if (req.params.workspaceFolders) |workspaceFolders| {
1114-
if (workspaceFolders.len != 0) {
1115-
logger.debug("Got workspace folders in initialization.\n", .{});
1116-
}
1117-
for (workspaceFolders) |workspace_folder| {
1118-
logger.debug("Loaded folder {}\n", .{workspace_folder.uri});
1119-
const duped_uri = try std.mem.dupe(allocator, u8, workspace_folder.uri);
1120-
try workspace_folder_configs.putNoClobber(duped_uri, null);
1121-
}
1122-
try loadWorkspaceConfigs();
1123-
}
1124-
11251084
try send(arena, types.Response{
11261085
.id = id,
11271086
.result = .{
@@ -1163,8 +1122,8 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
11631122
.documentProvider = true,
11641123
.workspace = .{
11651124
.workspaceFolders = .{
1166-
.supported = true,
1167-
.changeNotifications = true,
1125+
.supported = false,
1126+
.changeNotifications = false,
11681127
},
11691128
},
11701129
.semanticTokensProvider = .{
@@ -1208,32 +1167,9 @@ fn shutdownHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, config:
12081167
try respondGeneric(id, null_result_response);
12091168
}
12101169

1211-
fn workspaceFoldersChangeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.WorkspaceFoldersChange, config: Config) !void {
1212-
for (req.params.event.removed) |rem| {
1213-
if (workspace_folder_configs.remove(rem.uri)) |entry| {
1214-
allocator.free(entry.key);
1215-
if (entry.value) |c| {
1216-
std.json.parseFree(Config, c, std.json.ParseOptions{ .allocator = allocator });
1217-
}
1218-
}
1219-
}
1220-
1221-
for (req.params.event.added) |add| {
1222-
const duped_uri = try std.mem.dupe(allocator, u8, add.uri);
1223-
if (try workspace_folder_configs.fetchPut(duped_uri, null)) |old| {
1224-
allocator.free(old.key);
1225-
if (old.value) |c| {
1226-
std.json.parseFree(Config, c, std.json.ParseOptions{ .allocator = allocator });
1227-
}
1228-
}
1229-
}
1230-
1231-
try loadWorkspaceConfigs();
1232-
}
1233-
12341170
fn openDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.OpenDocument, config: Config) !void {
12351171
const handle = try document_store.openDocument(req.params.textDocument.uri, req.params.textDocument.text);
1236-
try publishDiagnostics(arena, handle.*, configFromUriOr(req.params.textDocument.uri, config));
1172+
try publishDiagnostics(arena, handle.*, config);
12371173

12381174
try semanticTokensFullHandler(arena, id, .{ .params = .{ .textDocument = .{ .uri = req.params.textDocument.uri } } }, config);
12391175
}
@@ -1244,9 +1180,8 @@ fn changeDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, r
12441180
return;
12451181
};
12461182

1247-
const local_config = configFromUriOr(req.params.textDocument.uri, config);
1248-
try document_store.applyChanges(handle, req.params.contentChanges.Array, offset_encoding, local_config.zig_lib_path);
1249-
try publishDiagnostics(arena, handle.*, local_config);
1183+
try document_store.applyChanges(handle, req.params.contentChanges.Array, offset_encoding, config.zig_lib_path);
1184+
try publishDiagnostics(arena, handle.*, config);
12501185
}
12511186

12521187
fn saveDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.SaveDocument, config: Config) error{OutOfMemory}!void {
@@ -1262,8 +1197,7 @@ fn closeDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, re
12621197
}
12631198

12641199
fn semanticTokensFullHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.SemanticTokensFull, config: Config) (error{OutOfMemory} || std.fs.File.WriteError)!void {
1265-
const this_config = configFromUriOr(req.params.textDocument.uri, config);
1266-
if (this_config.enable_semantic_tokens) {
1200+
if (config.enable_semantic_tokens) {
12671201
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
12681202
logger.warn("Trying to get semantic tokens of non existent document {}", .{req.params.textDocument.uri});
12691203
return try respondGeneric(id, no_semantic_tokens_response);
@@ -1289,12 +1223,11 @@ fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
12891223
const doc_position = try offsets.documentPosition(handle.document, req.params.position, offset_encoding);
12901224
const pos_context = try analysis.documentPositionContext(arena, handle.document, doc_position);
12911225

1292-
const this_config = configFromUriOr(req.params.textDocument.uri, config);
1293-
const use_snippets = this_config.enable_snippets and client_capabilities.supports_snippets;
1226+
const use_snippets = config.enable_snippets and client_capabilities.supports_snippets;
12941227
switch (pos_context) {
1295-
.builtin => try completeBuiltin(arena, id, this_config),
1296-
.var_access, .empty => try completeGlobal(arena, id, doc_position.absolute_index, handle, this_config),
1297-
.field_access => |range| try completeFieldAccess(arena, id, handle, doc_position, range, this_config),
1228+
.builtin => try completeBuiltin(arena, id, config),
1229+
.var_access, .empty => try completeGlobal(arena, id, doc_position.absolute_index, handle, config),
1230+
.field_access => |range| try completeFieldAccess(arena, id, handle, doc_position, range, config),
12981231
.global_error_set => try send(arena, types.Response{
12991232
.id = id,
13001233
.result = .{
@@ -1313,7 +1246,7 @@ fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
13131246
},
13141247
},
13151248
}),
1316-
.label => try completeLabel(arena, id, doc_position.absolute_index, handle, this_config),
1249+
.label => try completeLabel(arena, id, doc_position.absolute_index, handle, config),
13171250
else => try respondGeneric(id, no_completions_response),
13181251
}
13191252
} else {
@@ -1338,12 +1271,11 @@ fn gotoHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: reques
13381271
const doc_position = try offsets.documentPosition(handle.document, req.params.position, offset_encoding);
13391272
const pos_context = try analysis.documentPositionContext(arena, handle.document, doc_position);
13401273

1341-
const this_config = configFromUriOr(req.params.textDocument.uri, config);
13421274
switch (pos_context) {
1343-
.var_access => try gotoDefinitionGlobal(arena, id, doc_position.absolute_index, handle, this_config, resolve_alias),
1344-
.field_access => |range| try gotoDefinitionFieldAccess(arena, id, handle, doc_position, range, this_config, resolve_alias),
1275+
.var_access => try gotoDefinitionGlobal(arena, id, doc_position.absolute_index, handle, config, resolve_alias),
1276+
.field_access => |range| try gotoDefinitionFieldAccess(arena, id, handle, doc_position, range, config, resolve_alias),
13451277
.string_literal => try gotoDefinitionString(arena, id, doc_position.absolute_index, handle, config),
1346-
.label => try gotoDefinitionLabel(arena, id, doc_position.absolute_index, handle, this_config),
1278+
.label => try gotoDefinitionLabel(arena, id, doc_position.absolute_index, handle, config),
13471279
else => try respondGeneric(id, null_result_response),
13481280
}
13491281
} else {
@@ -1369,12 +1301,11 @@ fn hoverHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: reque
13691301
const doc_position = try offsets.documentPosition(handle.document, req.params.position, offset_encoding);
13701302
const pos_context = try analysis.documentPositionContext(arena, handle.document, doc_position);
13711303

1372-
const this_config = configFromUriOr(req.params.textDocument.uri, config);
13731304
switch (pos_context) {
13741305
.builtin => try hoverDefinitionBuiltin(arena, id, doc_position.absolute_index, handle),
1375-
.var_access => try hoverDefinitionGlobal(arena, id, doc_position.absolute_index, handle, this_config),
1376-
.field_access => |range| try hoverDefinitionFieldAccess(arena, id, handle, doc_position, range, this_config),
1377-
.label => try hoverDefinitionLabel(arena, id, doc_position.absolute_index, handle, this_config),
1306+
.var_access => try hoverDefinitionGlobal(arena, id, doc_position.absolute_index, handle, config),
1307+
.field_access => |range| try hoverDefinitionFieldAccess(arena, id, handle, doc_position, range, config),
1308+
.label => try hoverDefinitionLabel(arena, id, doc_position.absolute_index, handle, config),
13781309
else => try respondGeneric(id, null_result_response),
13791310
}
13801311
} else {
@@ -1443,10 +1374,9 @@ fn renameHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requ
14431374
const doc_position = try offsets.documentPosition(handle.document, req.params.position, offset_encoding);
14441375
const pos_context = try analysis.documentPositionContext(arena, handle.document, doc_position);
14451376

1446-
const this_config = configFromUriOr(req.params.textDocument.uri, config);
14471377
switch (pos_context) {
14481378
.var_access => try renameDefinitionGlobal(arena, id, handle, doc_position.absolute_index, req.params.newName),
1449-
.field_access => |range| try renameDefinitionFieldAccess(arena, id, handle, doc_position, range, req.params.newName, this_config),
1379+
.field_access => |range| try renameDefinitionFieldAccess(arena, id, handle, doc_position, range, req.params.newName, config),
14501380
.label => try renameDefinitionLabel(arena, id, handle, doc_position.absolute_index, req.params.newName),
14511381
else => try respondGeneric(id, null_result_response),
14521382
}
@@ -1465,11 +1395,10 @@ fn referencesHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
14651395
const doc_position = try offsets.documentPosition(handle.document, req.params.position, offset_encoding);
14661396
const pos_context = try analysis.documentPositionContext(arena, handle.document, doc_position);
14671397

1468-
const this_config = configFromUriOr(req.params.textDocument.uri, config);
14691398
const include_decl = req.params.context.includeDeclaration;
14701399
switch (pos_context) {
14711400
.var_access => try referencesDefinitionGlobal(arena, id, handle, doc_position.absolute_index, include_decl),
1472-
.field_access => |range| try referencesDefinitionFieldAccess(arena, id, handle, doc_position, range, include_decl, this_config),
1401+
.field_access => |range| try referencesDefinitionFieldAccess(arena, id, handle, doc_position, range, include_decl, config),
14731402
.label => try referencesDefinitionLabel(arena, id, handle, doc_position.absolute_index, include_decl),
14741403
else => try respondGeneric(id, null_result_response),
14751404
}
@@ -1509,7 +1438,6 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
15091438
.{"textDocument/willSave"},
15101439
.{ "initialize", requests.Initialize, initializeHandler },
15111440
.{ "shutdown", void, shutdownHandler },
1512-
.{ "workspace/didChangeWorkspaceFolders", requests.WorkspaceFoldersChange, workspaceFoldersChangeHandler },
15131441
.{ "textDocument/didOpen", requests.OpenDocument, openDocumentHandler },
15141442
.{ "textDocument/didChange", requests.ChangeDocument, changeDocumentHandler },
15151443
.{ "textDocument/didSave", requests.SaveDocument, saveDocumentHandler },
@@ -1570,6 +1498,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
15701498
.{"textDocument/foldingRange"},
15711499
.{"textDocument/selectionRange"},
15721500
.{"textDocument/semanticTokens/range"},
1501+
.{"workspace/didChangeWorkspaceFolders"},
15731502
});
15741503

15751504
if (unimplemented_map.has(method)) {
@@ -1708,18 +1637,6 @@ pub fn main() anyerror!void {
17081637
}
17091638
defer document_store.deinit();
17101639

1711-
workspace_folder_configs = std.StringHashMap(?Config).init(allocator);
1712-
defer {
1713-
var it = workspace_folder_configs.iterator();
1714-
while (it.next()) |entry| {
1715-
allocator.free(entry.key);
1716-
if (entry.value) |c| {
1717-
std.json.parseFree(Config, c, std.json.ParseOptions{ .allocator = allocator });
1718-
}
1719-
}
1720-
workspace_folder_configs.deinit();
1721-
}
1722-
17231640
// This JSON parser is passed to processJsonRpc and reset.
17241641
var json_parser = std.json.Parser.init(allocator, false);
17251642
defer json_parser.deinit();

0 commit comments

Comments
 (0)