Scope fixes + semantic token colors:

- Creates a scope for errdefer and adds the payload as a declaration
  (Previously lhs was a token index meaning we had an out of bounds error due too high of an integer)
- Semantic highlighting corrected for error payloads in loops/ifs and errdefers
This commit is contained in:
Luuk de Gram
2021-03-11 20:45:05 +01:00
parent ef1b3c95f1
commit 7a2cd418a8
2 changed files with 49 additions and 8 deletions

View File

@@ -1202,7 +1202,7 @@ fn maybeCollectImport(tree: ast.Tree, builtin_call: ast.Node.Index, arr: *std.Ar
&[_]ast.Node.Index{ data.lhs, data.rhs },
else => unreachable,
};
if (params.len > 1) return;
if (params.len != 1) return;
if (tags[params[0]] != .string_literal) return;
@@ -3171,6 +3171,29 @@ fn makeScopeInternal(
if (slice.ast.sentinel != 0)
try makeScopeInternal(allocator, scopes, error_completions, enum_completions, tree, slice.ast.sentinel);
},
.@"errdefer" => {
const expr = data[node_idx].rhs;
if (data[node_idx].lhs != 0) {
const payload_token = data[node_idx].lhs;
var scope = try scopes.addOne(allocator);
scope.* = .{
.range = .{
.start = offsets.tokenLocation(tree, payload_token).start,
.end = offsets.tokenLocation(tree, tree.lastToken(expr)).end,
},
.decls = std.StringHashMap(Declaration).init(allocator),
.uses = &.{},
.tests = &.{},
.data = .other,
};
errdefer scope.decls.deinit();
const name = tree.tokenSlice(payload_token);
try scope.decls.putNoClobber(name, .{ .ast_node = expr });
}
try makeScopeInternal(allocator, scopes, error_completions, enum_completions, tree, expr);
},
// no scope
.@"asm",