Skip to content

Commit 9fc45ca

Browse files
committed
respect the preferred position offset encoding of the client
1 parent 29356b6 commit 9fc45ca

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/Server.zig

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -389,26 +389,15 @@ fn initializeHandler(server: *Server, arena: std.mem.Allocator, request: types.I
389389
}
390390

391391
if (request.capabilities.general) |general| {
392-
var supports_utf8 = false;
393-
var supports_utf16 = false;
394-
var supports_utf32 = false;
395392
if (general.positionEncodings) |position_encodings| {
396-
for (position_encodings) |encoding| {
393+
server.offset_encoding = outer: for (position_encodings) |encoding| {
397394
switch (encoding) {
398-
.@"utf-8" => supports_utf8 = true,
399-
.@"utf-16" => supports_utf16 = true,
400-
.@"utf-32" => supports_utf32 = true,
395+
.@"utf-8" => break :outer .@"utf-8",
396+
.@"utf-16" => break :outer .@"utf-16",
397+
.@"utf-32" => break :outer .@"utf-32",
401398
.custom_value => {},
402399
}
403-
}
404-
}
405-
406-
if (supports_utf8) {
407-
server.offset_encoding = .@"utf-8";
408-
} else if (supports_utf32) {
409-
server.offset_encoding = .@"utf-32";
410-
} else {
411-
server.offset_encoding = .@"utf-16";
400+
} else server.offset_encoding;
412401
}
413402
}
414403
server.diagnostics_collection.offset_encoding = server.offset_encoding;

0 commit comments

Comments
 (0)