Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 minor tidy-ups + fix for over-eager unused parameter error in function types #584

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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])) {
Expand Down
12 changes: 12 additions & 0 deletions src/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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{};
Expand Down