Skip to content

Commit

Permalink
switch back to the rootDecls from the standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Dec 19, 2024
1 parent 3707088 commit d38771a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
10 changes: 1 addition & 9 deletions src/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1217,14 +1217,6 @@ pub fn isContainer(tree: Ast, node: Ast.Node.Index) bool {
};
}

pub fn rootDecls(tree: Ast) []const Node.Index {
const nodes_data = tree.nodes.items(.data);
switch (tree.mode) {
.zig => return tree.extra_data[nodes_data[0].lhs..nodes_data[0].rhs],
.zon => return (&nodes_data[0].lhs)[0..1],
}
}

pub fn isBuiltinCall(tree: Ast, node: Ast.Node.Index) bool {
return switch (tree.nodes.items(.tag)[node]) {
.builtin_call,
Expand Down Expand Up @@ -1581,7 +1573,7 @@ fn iterateChildrenTypeErased(
},

.root => {
for (rootDecls(tree)) |child| {
for (tree.rootDecls()) |child| {
try callback(context, tree, child);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/features/code_actions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ pub fn getImportsDecls(builder: *Builder, allocator: std.mem.Allocator) error{Ou
const node_data = tree.nodes.items(.data);
const node_tokens = tree.nodes.items(.main_token);

const root_decls = ast.rootDecls(tree);
const root_decls = tree.rootDecls();

var skip_set = try std.DynamicBitSetUnmanaged.initEmpty(allocator, root_decls.len);
defer skip_set.deinit(allocator);
Expand Down
4 changes: 2 additions & 2 deletions src/features/diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn generateDiagnostics(server: *Server, arena: std.mem.Allocator, handle: *D

// TODO: style warnings for types, values and declarations below root scope
if (tree.errors.len == 0) {
for (ast.rootDecls(tree)) |decl_idx| {
for (tree.rootDecls()) |decl_idx| {
const decl = tree.nodes.items(.tag)[decl_idx];
switch (decl) {
.fn_proto,
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn generateDiagnostics(server: *Server, arena: std.mem.Allocator, handle: *D

const main_tokens = tree.nodes.items(.main_token);
const tags = tree.tokens.items(.tag);
for (ast.rootDecls(tree)) |decl| {
for (tree.rootDecls()) |decl| {
const decl_tag = tree.nodes.items(.tag)[decl];
const decl_main_token = tree.nodes.items(.main_token)[decl];

Expand Down
4 changes: 2 additions & 2 deletions src/features/semantic_tokens.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,9 @@ pub fn writeSemanticTokens(
.limited = limited,
};

var nodes = if (loc) |l| try ast.nodesAtLoc(arena, handle.tree, l) else ast.rootDecls(handle.tree);
var nodes = if (loc) |l| try ast.nodesAtLoc(arena, handle.tree, l) else handle.tree.rootDecls();
if (nodes.len == 1 and nodes[0] == 0) {
nodes = ast.rootDecls(handle.tree);
nodes = handle.tree.rootDecls();
}

// reverse the ast from the root declarations
Expand Down

0 comments on commit d38771a

Please sign in to comment.