diff --git a/src/Server.zig b/src/Server.zig index cb7df43..c0564ae 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -239,11 +239,7 @@ fn publishDiagnostics(server: *Server, writer: anytype, handle: DocumentStore.Ha scopes: for (handle.document_scope.scopes) |scope| { const scope_data = switch (scope.data) { .function => |f| b: { - var buf: [1]std.zig.Ast.Node.Index = undefined; - var proto = ast.fnProto(tree, f, &buf) orelse break :b f; - if (proto.extern_export_inline_token) |tok| { - if (std.mem.eql(u8, tree.tokenSlice(tok), "extern")) continue :scopes; - } + if (!ast.fnProtoHasBody(tree, f).?) continue :scopes; break :b f; }, .block => |b| b, @@ -2450,7 +2446,6 @@ pub fn processJsonRpc(server: *Server, writer: anytype, json: []const u8) !void return; } - std.debug.assert(tree.root.Object.get("method") != null); const method = tree.root.Object.get("method").?.String; const start_time = std.time.milliTimestamp(); @@ -2490,6 +2485,7 @@ pub fn processJsonRpc(server: *Server, writer: anytype, json: []const u8) !void }; // Hack to avoid `return`ing in the inline for, which causes bugs. + // TODO: Change once stage2 is shipped and more stable? var done: ?anyerror = null; inline for (method_map) |method_info| { if (done == null and std.mem.eql(u8, method, method_info[0])) { diff --git a/src/ast.zig b/src/ast.zig index b5b66ce..c895196 100644 --- a/src/ast.zig +++ b/src/ast.zig @@ -1037,6 +1037,18 @@ pub fn isBlock(tree: Ast, node: Ast.Node.Index) bool { }; } +pub fn fnProtoHasBody(tree: Ast, node: Ast.Node.Index) ?bool { + return switch (tree.nodes.items(.tag)[node]) { + .fn_proto, + .fn_proto_multi, + .fn_proto_one, + .fn_proto_simple, + => false, + .fn_decl => true, + else => null, + }; +} + pub fn fnProto(tree: Ast, node: Ast.Node.Index, buf: *[1]Ast.Node.Index) ?Ast.full.FnProto { return switch (tree.nodes.items(.tag)[node]) { .fn_proto => tree.fnProto(node), diff --git a/src/main.zig b/src/main.zig index 881f1a1..a462a87 100644 --- a/src/main.zig +++ b/src/main.zig @@ -32,8 +32,7 @@ fn loop(server: *Server) !void { try reader.readNoEof(buffer); - var writer = std.io.getStdOut().writer(); - + const writer = std.io.getStdOut().writer(); try server.processJsonRpc(writer, buffer); } } @@ -212,7 +211,7 @@ const stack_frames = switch (zig_builtin.mode) { else => 0, }; -pub fn main() anyerror!void { +pub fn main() !void { var gpa_state = std.heap.GeneralPurposeAllocator(.{ .stack_trace_frames = stack_frames }){}; defer _ = gpa_state.deinit(); var tracy_state = if (tracy.enable_allocation) tracy.tracyAllocator(gpa_state.allocator()) else void{};