@@ -92,14 +92,12 @@ var stdout: std.io.BufferedOutStream(4096, std.fs.File.OutStream) = undefined;
92
92
var allocator : * std.mem.Allocator = undefined ;
93
93
94
94
var document_store : DocumentStore = undefined ;
95
- var workspace_folder_configs : std .StringHashMap (? Config ) = undefined ;
96
95
97
96
const ClientCapabilities = struct {
98
97
supports_snippets : bool = false ,
99
98
supports_semantic_tokens : bool = false ,
100
99
hover_supports_md : bool = false ,
101
100
completion_doc_supports_md : bool = false ,
102
- supports_workspace_folders : bool = false ,
103
101
};
104
102
105
103
var client_capabilities = ClientCapabilities {};
@@ -1055,40 +1053,13 @@ fn loadConfig(folder_path: []const u8) ?Config {
1055
1053
return config ;
1056
1054
}
1057
1055
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
-
1081
1056
fn initializeHandler (arena : * std.heap.ArenaAllocator , id : types.RequestId , req : requests.Initialize , config : Config ) ! void {
1082
1057
for (req .params .capabilities .offsetEncoding .value ) | encoding | {
1083
1058
if (std .mem .eql (u8 , encoding , "utf-8" )) {
1084
1059
offset_encoding = .utf8 ;
1085
1060
}
1086
1061
}
1087
1062
1088
- if (req .params .capabilities .workspace ) | workspace | {
1089
- client_capabilities .supports_workspace_folders = workspace .workspaceFolders .value ;
1090
- }
1091
-
1092
1063
if (req .params .capabilities .textDocument ) | textDocument | {
1093
1064
client_capabilities .supports_semantic_tokens = textDocument .semanticTokens .exists ;
1094
1065
if (textDocument .hover ) | hover | {
@@ -1110,18 +1081,6 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
1110
1081
}
1111
1082
}
1112
1083
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
-
1125
1084
try send (arena , types.Response {
1126
1085
.id = id ,
1127
1086
.result = .{
@@ -1163,8 +1122,8 @@ fn initializeHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
1163
1122
.documentProvider = true ,
1164
1123
.workspace = .{
1165
1124
.workspaceFolders = .{
1166
- .supported = true ,
1167
- .changeNotifications = true ,
1125
+ .supported = false ,
1126
+ .changeNotifications = false ,
1168
1127
},
1169
1128
},
1170
1129
.semanticTokensProvider = .{
@@ -1208,32 +1167,9 @@ fn shutdownHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, config:
1208
1167
try respondGeneric (id , null_result_response );
1209
1168
}
1210
1169
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
-
1234
1170
fn openDocumentHandler (arena : * std.heap.ArenaAllocator , id : types.RequestId , req : requests.OpenDocument , config : Config ) ! void {
1235
1171
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 );
1237
1173
1238
1174
try semanticTokensFullHandler (arena , id , .{ .params = .{ .textDocument = .{ .uri = req .params .textDocument .uri } } }, config );
1239
1175
}
@@ -1244,9 +1180,8 @@ fn changeDocumentHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, r
1244
1180
return ;
1245
1181
};
1246
1182
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 );
1250
1185
}
1251
1186
1252
1187
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
1262
1197
}
1263
1198
1264
1199
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 ) {
1267
1201
const handle = document_store .getHandle (req .params .textDocument .uri ) orelse {
1268
1202
logger .warn ("Trying to get semantic tokens of non existent document {}" , .{req .params .textDocument .uri });
1269
1203
return try respondGeneric (id , no_semantic_tokens_response );
@@ -1289,12 +1223,11 @@ fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
1289
1223
const doc_position = try offsets .documentPosition (handle .document , req .params .position , offset_encoding );
1290
1224
const pos_context = try analysis .documentPositionContext (arena , handle .document , doc_position );
1291
1225
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 ;
1294
1227
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 ),
1298
1231
.global_error_set = > try send (arena , types.Response {
1299
1232
.id = id ,
1300
1233
.result = .{
@@ -1313,7 +1246,7 @@ fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
1313
1246
},
1314
1247
},
1315
1248
}),
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 ),
1317
1250
else = > try respondGeneric (id , no_completions_response ),
1318
1251
}
1319
1252
} else {
@@ -1338,12 +1271,11 @@ fn gotoHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: reques
1338
1271
const doc_position = try offsets .documentPosition (handle .document , req .params .position , offset_encoding );
1339
1272
const pos_context = try analysis .documentPositionContext (arena , handle .document , doc_position );
1340
1273
1341
- const this_config = configFromUriOr (req .params .textDocument .uri , config );
1342
1274
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 ),
1345
1277
.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 ),
1347
1279
else = > try respondGeneric (id , null_result_response ),
1348
1280
}
1349
1281
} else {
@@ -1369,12 +1301,11 @@ fn hoverHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: reque
1369
1301
const doc_position = try offsets .documentPosition (handle .document , req .params .position , offset_encoding );
1370
1302
const pos_context = try analysis .documentPositionContext (arena , handle .document , doc_position );
1371
1303
1372
- const this_config = configFromUriOr (req .params .textDocument .uri , config );
1373
1304
switch (pos_context ) {
1374
1305
.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 ),
1378
1309
else = > try respondGeneric (id , null_result_response ),
1379
1310
}
1380
1311
} else {
@@ -1443,10 +1374,9 @@ fn renameHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requ
1443
1374
const doc_position = try offsets .documentPosition (handle .document , req .params .position , offset_encoding );
1444
1375
const pos_context = try analysis .documentPositionContext (arena , handle .document , doc_position );
1445
1376
1446
- const this_config = configFromUriOr (req .params .textDocument .uri , config );
1447
1377
switch (pos_context ) {
1448
1378
.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 ),
1450
1380
.label = > try renameDefinitionLabel (arena , id , handle , doc_position .absolute_index , req .params .newName ),
1451
1381
else = > try respondGeneric (id , null_result_response ),
1452
1382
}
@@ -1465,11 +1395,10 @@ fn referencesHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
1465
1395
const doc_position = try offsets .documentPosition (handle .document , req .params .position , offset_encoding );
1466
1396
const pos_context = try analysis .documentPositionContext (arena , handle .document , doc_position );
1467
1397
1468
- const this_config = configFromUriOr (req .params .textDocument .uri , config );
1469
1398
const include_decl = req .params .context .includeDeclaration ;
1470
1399
switch (pos_context ) {
1471
1400
.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 ),
1473
1402
.label = > try referencesDefinitionLabel (arena , id , handle , doc_position .absolute_index , include_decl ),
1474
1403
else = > try respondGeneric (id , null_result_response ),
1475
1404
}
@@ -1509,7 +1438,6 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
1509
1438
.{"textDocument/willSave" },
1510
1439
.{ "initialize" , requests .Initialize , initializeHandler },
1511
1440
.{ "shutdown" , void , shutdownHandler },
1512
- .{ "workspace/didChangeWorkspaceFolders" , requests .WorkspaceFoldersChange , workspaceFoldersChangeHandler },
1513
1441
.{ "textDocument/didOpen" , requests .OpenDocument , openDocumentHandler },
1514
1442
.{ "textDocument/didChange" , requests .ChangeDocument , changeDocumentHandler },
1515
1443
.{ "textDocument/didSave" , requests .SaveDocument , saveDocumentHandler },
@@ -1570,6 +1498,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
1570
1498
.{"textDocument/foldingRange" },
1571
1499
.{"textDocument/selectionRange" },
1572
1500
.{"textDocument/semanticTokens/range" },
1501
+ .{"workspace/didChangeWorkspaceFolders" },
1573
1502
});
1574
1503
1575
1504
if (unimplemented_map .has (method )) {
@@ -1708,18 +1637,6 @@ pub fn main() anyerror!void {
1708
1637
}
1709
1638
defer document_store .deinit ();
1710
1639
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
-
1723
1640
// This JSON parser is passed to processJsonRpc and reset.
1724
1641
var json_parser = std .json .Parser .init (allocator , false );
1725
1642
defer json_parser .deinit ();
0 commit comments