Skip to content

Commit

Permalink
respect the preferred position offset encoding of the client
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Jan 22, 2025
1 parent 29356b6 commit 9fc45ca
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,26 +389,15 @@ fn initializeHandler(server: *Server, arena: std.mem.Allocator, request: types.I
}

if (request.capabilities.general) |general| {
var supports_utf8 = false;
var supports_utf16 = false;
var supports_utf32 = false;
if (general.positionEncodings) |position_encodings| {
for (position_encodings) |encoding| {
server.offset_encoding = outer: for (position_encodings) |encoding| {
switch (encoding) {
.@"utf-8" => supports_utf8 = true,
.@"utf-16" => supports_utf16 = true,
.@"utf-32" => supports_utf32 = true,
.@"utf-8" => break :outer .@"utf-8",
.@"utf-16" => break :outer .@"utf-16",
.@"utf-32" => break :outer .@"utf-32",
.custom_value => {},
}
}
}

if (supports_utf8) {
server.offset_encoding = .@"utf-8";
} else if (supports_utf32) {
server.offset_encoding = .@"utf-32";
} else {
server.offset_encoding = .@"utf-16";
} else server.offset_encoding;
}
}
server.diagnostics_collection.offset_encoding = server.offset_encoding;
Expand Down

0 comments on commit 9fc45ca

Please sign in to comment.