Skip to content

Commit

Permalink
fix: enum members can now be renamed from decls (#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
srijan-paul authored Oct 5, 2024
1 parent db05a1c commit 063d7ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/features/references.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const Builder = struct {
locations: std.ArrayListUnmanaged(types.Location) = .{},
/// this is the declaration we are searching for
decl_handle: Analyser.DeclWithHandle,
/// Whether the `decl_handle` has been added
did_add_decl_handle: bool = false,
analyser: *Analyser,
encoding: offsets.Encoding,

Expand All @@ -81,6 +83,12 @@ const Builder = struct {
}

fn add(self: *Builder, handle: *DocumentStore.Handle, token_index: Ast.TokenIndex) error{OutOfMemory}!void {
if (self.decl_handle.handle == handle and
self.decl_handle.nameToken() == token_index)
{
if (self.did_add_decl_handle) return;
self.did_add_decl_handle = true;
}
try self.locations.append(self.allocator, .{
.uri = handle.uri,
.range = offsets.tokenToRange(handle.tree, token_index, self.encoding),
Expand Down
10 changes: 10 additions & 0 deletions tests/lsp_features/references.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ test "for/while capture" {
);
}

test "enum field access" {
try testReferences(
\\const E = enum {
\\ <0>,
\\ bar
\\};
\\const e = E.<0>;
);
}

test "struct field access" {
try testReferences(
\\const S = struct {<0>: u32 = 3};
Expand Down

0 comments on commit 063d7ff

Please sign in to comment.