fix: references/rename for struct_init_one, struct_init_one_comma#1903
Conversation
Techatrix
left a comment
There was a problem hiding this comment.
It should be possible to handle all the other .struct_init_* cases by doing something like this:
zls/src/features/inlay_hints.zig
Lines 551 to 556 in 93b7bbd
The following patch appears to fix the "other direction" that previously didn't work:
diff --git a/src/features/references.zig b/src/features/references.zig
index d4b665d1..09646b4d 100644
--- a/src/features/references.zig
+++ b/src/features/references.zig
@@ -443,6 +443,7 @@ pub fn referencesHandler(server: *Server, arena: std.mem.Allocator, request: Gen
break :z null;
},
.label => try Analyser.getLabelGlobal(source_index, handle, name),
+ .enum_literal => try analyser.getSymbolEnumLiteral(arena, handle, source_index, name),
else => null,
} orelse return null;
Awesome, I'll take a pass at the other cases soon. Thank you! :) Edit: |
|
Thought I ran zig fmt before pushing last night, really sorry about that! |
|
Unless I'm mistaken, it looks like CI is failing now due to the recent deprecations in ziglang/zig@f97c2f2, which is fixed in #1904? |
a1a10c9 to
db9a085
Compare
Techatrix
left a comment
There was a problem hiding this comment.
I removed the initial switch case that just handled .struct_init_one.* because the other case is already capable of handling all variants. Otherwise, this looks great!
Makes sense, thanks so much for the help! |
This fixes some cases where references to fields in some struct initializations aren't picked up, causing features like renaming and reference viewing to fail. Currently the fix only works one way, in that a rename invoked on the actual struct initialization will still fail, but will work when invoked on other locations such as the struct's definition or a field access. I took some time to try and fix the other direction, but I don't think I'm familiar enough with the codebase to do that yet. I added a test case for this but left it commented out as it currently fails.
This fix only covers the cases of
.struct_init_oneand.struct_init_one_comma. I'd really like to look into fixing the other node cases (e.g..struct_init,.struct_init_comma, etc. if I'm understanding things properly) but wanted to cover this first case and get some feedback/ a sanity check before proceeding on. Here's a quick demo showing both renaming and references with the improvements:Related Issues: #1837, #1700