test and simplify semantic tokens on function call

This commit is contained in:
Techatrix 2023-03-31 20:49:25 +02:00
parent 3fefcfb398
commit ae5fa110b5
2 changed files with 36 additions and 6 deletions

View File

@ -44,7 +44,6 @@ const Builder = struct {
analyser: *Analyser,
handle: *const DocumentStore.Handle,
previous_source_index: usize = 0,
previous_token: ?Ast.TokenIndex = null,
token_buffer: std.ArrayListUnmanaged(u32) = .{},
encoding: offsets.Encoding,
limited: bool,
@ -595,11 +594,6 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v
try writeToken(builder, call.async_token, .keyword);
try callWriteNodeTokens(allocator, .{ builder, call.ast.fn_expr });
if (builder.previous_token) |prev| {
if (prev != ast.lastToken(tree, call.ast.fn_expr) and token_tags[ast.lastToken(tree, call.ast.fn_expr)] == .identifier) {
try writeToken(builder, ast.lastToken(tree, call.ast.fn_expr), .function);
}
}
for (call.ast.params) |param| try callWriteNodeTokens(allocator, .{ builder, param });
},
.slice,

View File

@ -226,6 +226,42 @@ test "semantic tokens - field access" {
});
}
test "semantic tokens - call" {
try testSemanticTokens(
\\fn foo() void {}
\\const alpha = foo();
, &.{
.{ "fn", .keyword, .{} },
.{ "foo", .function, .{ .declaration = true } },
.{ "void", .type, .{} },
.{ "const", .keyword, .{} },
.{ "alpha", .variable, .{ .declaration = true } },
.{ "=", .operator, .{} },
.{ "foo", .function, .{} },
});
try testSemanticTokens(
\\const ns = struct {
\\ fn foo() void {}
\\};
\\const alpha = ns.foo();
, &.{
.{ "const", .keyword, .{} },
.{ "ns", .type, .{ .namespace = true, .declaration = true } },
.{ "=", .operator, .{} },
.{ "struct", .keyword, .{} },
.{ "fn", .keyword, .{} },
.{ "foo", .function, .{ .declaration = true } },
.{ "void", .type, .{} },
.{ "const", .keyword, .{} },
.{ "alpha", .variable, .{ .declaration = true } },
.{ "=", .operator, .{} },
.{ "ns", .type, .{ .namespace = true } },
.{ "foo", .function, .{} },
});
}
test "semantic tokens - catch" {
try testSemanticTokens(
\\var alpha = a catch b;