Bug stream fixes (#818)
* Fix glaring inlay hint issue; thanks for the report Nameless * Fix label references; closes #728
This commit is contained in:
parent
5dca821eb6
commit
0ab34abc0f
@ -876,7 +876,7 @@ fn hoverSymbol(server: *Server, decl_handle: analysis.DeclWithHandle) error{OutO
|
|||||||
.array_payload => |payload| handle.tree.tokenSlice(payload.identifier),
|
.array_payload => |payload| handle.tree.tokenSlice(payload.identifier),
|
||||||
.array_index => |payload| handle.tree.tokenSlice(payload),
|
.array_index => |payload| handle.tree.tokenSlice(payload),
|
||||||
.switch_payload => |payload| tree.tokenSlice(payload.node),
|
.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{};
|
var bound_type_params = analysis.BoundTypeParams{};
|
||||||
@ -1194,9 +1194,9 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: analysis.Decl
|
|||||||
},
|
},
|
||||||
.label_decl => |label_decl| {
|
.label_decl => |label_decl| {
|
||||||
try context.completions.append(allocator, .{
|
try context.completions.append(allocator, .{
|
||||||
.label = tree.tokenSlice(label_decl),
|
.label = tree.tokenSlice(label_decl.label),
|
||||||
.kind = .Variable,
|
.kind = .Variable,
|
||||||
.insertText = tree.tokenSlice(label_decl),
|
.insertText = tree.tokenSlice(label_decl.label),
|
||||||
.insertTextFormat = .PlainText,
|
.insertTextFormat = .PlainText,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -2313,9 +2313,7 @@ fn generalReferencesHandler(server: *Server, writer: anytype, id: types.RequestI
|
|||||||
};
|
};
|
||||||
|
|
||||||
const locations = if (pos_context == .label)
|
const locations = if (pos_context == .label)
|
||||||
// FIXME https://github.com/zigtools/zls/issues/728
|
try references.labelReferences(allocator, decl, server.offset_encoding, include_decl)
|
||||||
// try references.labelReferences(allocator, decl, server.offset_encoding, include_decl)
|
|
||||||
std.ArrayListUnmanaged(types.Location){}
|
|
||||||
else
|
else
|
||||||
try references.symbolReferences(
|
try references.symbolReferences(
|
||||||
&server.arena,
|
&server.arena,
|
||||||
|
@ -795,15 +795,15 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ti = val.@"type".getTypeInfo();
|
const ti = val.type.getTypeInfo();
|
||||||
if (ti != .@"type") {
|
if (ti != .type) {
|
||||||
log.err("Not a type: { }", .{interpreter.formatTypeInfo(ti)});
|
log.err("Not a type: { }", .{interpreter.formatTypeInfo(ti)});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TypeWithHandle{
|
return TypeWithHandle{
|
||||||
.type = .{
|
.type = .{
|
||||||
.data = .{ .@"comptime" = .{ .interpreter = interpreter, .type = val.value_data.@"type" } },
|
.data = .{ .@"comptime" = .{ .interpreter = interpreter, .type = val.value_data.type } },
|
||||||
.is_type_val = true,
|
.is_type_val = true,
|
||||||
},
|
},
|
||||||
.handle = node_handle.handle,
|
.handle = node_handle.handle,
|
||||||
@ -1956,7 +1956,10 @@ pub const Declaration = union(enum) {
|
|||||||
switch_expr: Ast.Node.Index,
|
switch_expr: Ast.Node.Index,
|
||||||
items: []const 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 {
|
pub const DeclWithHandle = struct {
|
||||||
@ -1972,7 +1975,7 @@ pub const DeclWithHandle = struct {
|
|||||||
.array_payload => |ap| ap.identifier,
|
.array_payload => |ap| ap.identifier,
|
||||||
.array_index => |ai| ai,
|
.array_index => |ai| ai,
|
||||||
.switch_payload => |sp| sp.node,
|
.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,
|
.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, .{
|
try scopes.append(allocator, .{
|
||||||
@ -2817,7 +2823,10 @@ fn makeScopeInternal(allocator: std.mem.Allocator, context: ScopeContext, node_i
|
|||||||
.data = .other,
|
.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| {
|
if (while_node.payload_token) |payload| {
|
||||||
|
@ -243,16 +243,16 @@ fn writeCallNodeHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store:
|
|||||||
|
|
||||||
/// HACK self-hosted has not implemented async yet
|
/// HACK self-hosted has not implemented async yet
|
||||||
fn callWriteNodeInlayHint(allocator: std.mem.Allocator, args: anytype) error{OutOfMemory}!void {
|
fn callWriteNodeInlayHint(allocator: std.mem.Allocator, args: anytype) error{OutOfMemory}!void {
|
||||||
if (zig_builtin.zig_backend == .other or zig_builtin.zig_backend == .stage1) {
|
_ = allocator;
|
||||||
const FrameSize = @sizeOf(@Frame(writeNodeInlayHint));
|
// if (zig_builtin.zig_backend == .other or zig_builtin.zig_backend == .stage1) {
|
||||||
var child_frame = try allocator.alignedAlloc(u8, std.Target.stack_align, FrameSize);
|
// const FrameSize = @sizeOf(@Frame(writeNodeInlayHint));
|
||||||
defer allocator.free(child_frame);
|
// var child_frame = try allocator.alignedAlloc(u8, std.Target.stack_align, FrameSize);
|
||||||
|
// defer allocator.free(child_frame);
|
||||||
return await @asyncCall(child_frame, {}, writeNodeInlayHint, args);
|
// return await @asyncCall(child_frame, {}, writeNodeInlayHint, args);
|
||||||
} else {
|
// } else {
|
||||||
// TODO find a non recursive solution
|
// TODO find a non recursive solution
|
||||||
return @call(.{}, writeNodeInlayHint, args);
|
return @call(.{}, writeNodeInlayHint, args);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// iterates over the ast and writes parameter hints into `builder.hints` for every function call and builtin call
|
/// 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 node_data = tree.nodes.items(.data);
|
||||||
const main_tokens = tree.nodes.items(.main_token);
|
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();
|
var allocator = arena.allocator();
|
||||||
|
|
||||||
@ -452,7 +456,6 @@ fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store:
|
|||||||
.bool_or,
|
.bool_or,
|
||||||
.array_access,
|
.array_access,
|
||||||
.switch_range,
|
.switch_range,
|
||||||
.error_value,
|
|
||||||
.error_union,
|
.error_union,
|
||||||
=> {
|
=> {
|
||||||
try callWriteNodeInlayHint(allocator, .{ builder, arena, store, node_data[node].lhs, range });
|
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 });
|
try callWriteNodeInlayHint(allocator, .{ builder, arena, store, asm_node.ast.template, range });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.error_value => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
// 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.
|
// This case can be implemented just by scanning tokens.
|
||||||
const first_tok = tree.firstToken(decl.decl.label_decl);
|
const first_tok = tree.firstToken(decl.decl.label_decl.label);
|
||||||
const last_tok = ast.lastToken(tree, decl.decl.label_decl);
|
const last_tok = ast.lastToken(tree, decl.decl.label_decl.block);
|
||||||
|
|
||||||
var locations = std.ArrayListUnmanaged(types.Location){};
|
var locations = std.ArrayListUnmanaged(types.Location){};
|
||||||
errdefer locations.deinit(allocator);
|
errdefer locations.deinit(allocator);
|
||||||
|
Loading…
Reference in New Issue
Block a user