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

fix: enum member declarations can now be renamed correctly. #2043

Merged
merged 1 commit into from
Oct 5, 2024
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: 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