From d38771a37e14d1455a5cc3d03481666b7fe93adb Mon Sep 17 00:00:00 2001 From: Techatrix Date: Thu, 19 Dec 2024 01:23:18 +0100 Subject: [PATCH] switch back to the rootDecls from the standard library --- src/ast.zig | 10 +--------- src/features/code_actions.zig | 2 +- src/features/diagnostics.zig | 4 ++-- src/features/semantic_tokens.zig | 4 ++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/ast.zig b/src/ast.zig index 871f85c15..972a26496 100644 --- a/src/ast.zig +++ b/src/ast.zig @@ -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, @@ -1581,7 +1573,7 @@ fn iterateChildrenTypeErased( }, .root => { - for (rootDecls(tree)) |child| { + for (tree.rootDecls()) |child| { try callback(context, tree, child); } }, diff --git a/src/features/code_actions.zig b/src/features/code_actions.zig index 18c4431ca..c5c494a10 100644 --- a/src/features/code_actions.zig +++ b/src/features/code_actions.zig @@ -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); diff --git a/src/features/diagnostics.zig b/src/features/diagnostics.zig index 1db80efdc..c27392b4c 100644 --- a/src/features/diagnostics.zig +++ b/src/features/diagnostics.zig @@ -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, @@ -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]; diff --git a/src/features/semantic_tokens.zig b/src/features/semantic_tokens.zig index f66dbd5e3..382d4871d 100644 --- a/src/features/semantic_tokens.zig +++ b/src/features/semantic_tokens.zig @@ -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