Bug stream fixes (#818)

* Fix glaring inlay hint issue; thanks for the report Nameless

* Fix label references; closes #728
This commit is contained in:
Auguste Rame 2022-12-13 22:07:36 -05:00 committed by GitHub
parent 5dca821eb6
commit 0ab34abc0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 27 deletions

View File

@ -876,7 +876,7 @@ fn hoverSymbol(server: *Server, decl_handle: analysis.DeclWithHandle) error{OutO
.array_payload => |payload| handle.tree.tokenSlice(payload.identifier),
.array_index => |payload| handle.tree.tokenSlice(payload),
.switch_payload => |payload| tree.tokenSlice(payload.node),
.label_decl => |label_decl| tree.tokenSlice(label_decl),
.label_decl => |label_decl| tree.tokenSlice(label_decl.label),
};
var bound_type_params = analysis.BoundTypeParams{};
@ -1194,9 +1194,9 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: analysis.Decl
},
.label_decl => |label_decl| {
try context.completions.append(allocator, .{
.label = tree.tokenSlice(label_decl),
.label = tree.tokenSlice(label_decl.label),
.kind = .Variable,
.insertText = tree.tokenSlice(label_decl),
.insertText = tree.tokenSlice(label_decl.label),
.insertTextFormat = .PlainText,
});
},
@ -2313,9 +2313,7 @@ fn generalReferencesHandler(server: *Server, writer: anytype, id: types.RequestI
};
const locations = if (pos_context == .label)
// FIXME https://github.com/zigtools/zls/issues/728
// try references.labelReferences(allocator, decl, server.offset_encoding, include_decl)
std.ArrayListUnmanaged(types.Location){}
try references.labelReferences(allocator, decl, server.offset_encoding, include_decl)
else
try references.symbolReferences(
&server.arena,

View File

@ -795,15 +795,15 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl
return null;
};
const ti = val.@"type".getTypeInfo();
if (ti != .@"type") {
const ti = val.type.getTypeInfo();
if (ti != .type) {
log.err("Not a type: { }", .{interpreter.formatTypeInfo(ti)});
return null;
}
return TypeWithHandle{
.type = .{
.data = .{ .@"comptime" = .{ .interpreter = interpreter, .type = val.value_data.@"type" } },
.data = .{ .@"comptime" = .{ .interpreter = interpreter, .type = val.value_data.type } },
.is_type_val = true,
},
.handle = node_handle.handle,
@ -1956,7 +1956,10 @@ pub const Declaration = union(enum) {
switch_expr: Ast.Node.Index,
items: []const Ast.Node.Index,
},
label_decl: Ast.TokenIndex,
label_decl: struct {
label: Ast.TokenIndex,
block: Ast.Node.Index,
},
};
pub const DeclWithHandle = struct {
@ -1972,7 +1975,7 @@ pub const DeclWithHandle = struct {
.array_payload => |ap| ap.identifier,
.array_index => |ai| ai,
.switch_payload => |sp| sp.node,
.label_decl => |ld| ld,
.label_decl => |ld| ld.label,
};
}
@ -2696,7 +2699,10 @@ fn makeScopeInternal(allocator: std.mem.Allocator, context: ScopeContext, node_i
},
.data = .other,
};
try scope.decls.putNoClobber(allocator, tree.tokenSlice(first_token), .{ .label_decl = first_token });
try scope.decls.putNoClobber(allocator, tree.tokenSlice(first_token), .{ .label_decl = .{
.label = first_token,
.block = node_idx,
} });
}
try scopes.append(allocator, .{
@ -2817,7 +2823,10 @@ fn makeScopeInternal(allocator: std.mem.Allocator, context: ScopeContext, node_i
.data = .other,
};
try scope.decls.putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = label });
try scope.decls.putNoClobber(allocator, tree.tokenSlice(label), .{ .label_decl = .{
.label = label,
.block = while_node.ast.then_expr,
} });
}
if (while_node.payload_token) |payload| {

View File

@ -243,16 +243,16 @@ fn writeCallNodeHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store:
/// HACK self-hosted has not implemented async yet
fn callWriteNodeInlayHint(allocator: std.mem.Allocator, args: anytype) error{OutOfMemory}!void {
if (zig_builtin.zig_backend == .other or zig_builtin.zig_backend == .stage1) {
const FrameSize = @sizeOf(@Frame(writeNodeInlayHint));
var child_frame = try allocator.alignedAlloc(u8, std.Target.stack_align, FrameSize);
defer allocator.free(child_frame);
return await @asyncCall(child_frame, {}, writeNodeInlayHint, args);
} else {
// TODO find a non recursive solution
return @call(.{}, writeNodeInlayHint, args);
}
_ = allocator;
// if (zig_builtin.zig_backend == .other or zig_builtin.zig_backend == .stage1) {
// const FrameSize = @sizeOf(@Frame(writeNodeInlayHint));
// var child_frame = try allocator.alignedAlloc(u8, std.Target.stack_align, FrameSize);
// defer allocator.free(child_frame);
// return await @asyncCall(child_frame, {}, writeNodeInlayHint, args);
// } else {
// TODO find a non recursive solution
return @call(.{}, writeNodeInlayHint, args);
// }
}
/// iterates over the ast and writes parameter hints into `builder.hints` for every function call and builtin call
@ -266,7 +266,11 @@ fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store:
const node_data = tree.nodes.items(.data);
const main_tokens = tree.nodes.items(.main_token);
if (node == 0 or node > node_data.len) return;
// std.log.info("max: {d} | curr: {d}", .{ node_data.len, node });
// if (node == 0 or node >= node_data.len) return;
if (node == 0) return;
// std.log.info("tag: {any}", .{node_tags[node]});
// std.log.info("src: {s}", .{tree.getNodeSource(node)});
var allocator = arena.allocator();
@ -452,7 +456,6 @@ fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store:
.bool_or,
.array_access,
.switch_range,
.error_value,
.error_union,
=> {
try callWriteNodeInlayHint(allocator, .{ builder, arena, store, node_data[node].lhs, range });
@ -679,6 +682,8 @@ fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store:
try callWriteNodeInlayHint(allocator, .{ builder, arena, store, asm_node.ast.template, range });
},
.error_value => {},
}
}

View File

@ -20,8 +20,8 @@ pub fn labelReferences(
// Find while / for / block from label -> iterate over children nodes, find break and continues, change their labels if they match.
// This case can be implemented just by scanning tokens.
const first_tok = tree.firstToken(decl.decl.label_decl);
const last_tok = ast.lastToken(tree, decl.decl.label_decl);
const first_tok = tree.firstToken(decl.decl.label_decl.label);
const last_tok = ast.lastToken(tree, decl.decl.label_decl.block);
var locations = std.ArrayListUnmanaged(types.Location){};
errdefer locations.deinit(allocator);