Merge pull request #351 from leecannon/moved_backwards

Handle tag moved backwards without logging
This commit is contained in:
Alexandros Naskos 2021-06-27 10:57:57 +03:00 committed by GitHub
commit 3feba5ec0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -68,15 +68,10 @@ const Builder = struct {
fn add(self: *Builder, token: ast.TokenIndex, token_type: TokenType, token_modifiers: TokenModifiers) !void { fn add(self: *Builder, token: ast.TokenIndex, token_type: TokenType, token_modifiers: TokenModifiers) !void {
const tree = self.handle.tree; const tree = self.handle.tree;
const starts = tree.tokens.items(.start); const starts = tree.tokens.items(.start);
const tags = tree.tokens.items(.tag);
const next_start = starts[token]; const next_start = starts[token];
if (next_start < self.previous_position) { if (next_start < self.previous_position) {
log.err( return error.MovedBackwards;
"Moved backwards from {} at position {} to {} at {}.",
.{ tags[self.previous_token orelse 0], self.previous_position, tags[token], next_start },
);
return;
} }
if (self.previous_token) |prev| { if (self.previous_token) |prev| {
@ -259,6 +254,7 @@ const WriteTokensError = error{
Utf8OverlongEncoding, Utf8OverlongEncoding,
Utf8EncodesSurrogateHalf, Utf8EncodesSurrogateHalf,
Utf8CodepointTooLarge, Utf8CodepointTooLarge,
MovedBackwards,
}; };
fn writeNodeTokens( fn writeNodeTokens(
@ -1048,7 +1044,10 @@ pub fn writeAllSemanticTokens(
// reverse the ast from the root declarations // reverse the ast from the root declarations
var buf: [2]ast.Node.Index = undefined; var buf: [2]ast.Node.Index = undefined;
for (declMembers(handle.tree, 0, &buf)) |child| { for (declMembers(handle.tree, 0, &buf)) |child| {
try writeNodeTokens(&builder, arena, store, child); writeNodeTokens(&builder, arena, store, child) catch |err| switch (err) {
error.MovedBackwards => break,
else => |e| return e,
};
} }
try builder.finish(); try builder.finish();
return builder.toOwnedSlice(); return builder.toOwnedSlice();

View File

@ -100,7 +100,7 @@ const Server = struct {
fn shutdown(self: *Server) void { fn shutdown(self: *Server) void {
self.request("shutdown", "{}", null) catch @panic("Could not send shutdown request"); self.request("shutdown", "{}", null) catch @panic("Could not send shutdown request");
waitNoError(self.process) catch |err| @panic("Server error"); waitNoError(self.process) catch @panic("Server error");
self.process.deinit(); self.process.deinit();
} }
}; };