Field rename does not rename struct initialization's fields
Zig Version
0.12.0-dev.3245+4f782d1e8
Zig Language Server Version
0.12.0-dev.496+96eddd0
Client / Code Editor / Extensions
vscode
Steps to Reproduce and Observed Behavior
Rename field inside TestStruct, initialize struct using syntax below ⇾ the initialization does not get updated
const TestStruct = struct {
test_var_renamed: i32, //field was renamed here
};
test "test" {
const test_struct: TestStruct = .{
.test_var = 1, //does not get renamed
};
const test_struct2: TestStruct = TestStruct{
.test_var = 1, //does not get renamed
};
std.debug.print("{}", .{test_struct});
std.debug.print("{}", .{test_struct2});
}
Expected Behavior
const TestStruct = struct {
test_var_renamed: i32, //field was renamed here
};
test "test" {
const test_struct: TestStruct = .{
.test_var_renamed = 1, //gets renamed
};
const test_struct2: TestStruct = TestStruct{
.test_var_renamed = 1, //gets renamed
};
std.debug.print("{}", .{test_struct});
std.debug.print("{}", .{test_struct2});
}
Relevant log output
No response
I'm also running into this issue using 0.13.0-dev.29+bb19bee. It looks like zls is ignoring the initialization accesses to the struct's fields when it searches for references as part of the renaming request. These references are also missing when using the server's textDocument/reference capability. I'm not super familiar with the language/ zls code base yet, but after a bit of poking around it looks like the references are missed here:
https://github.com/zigtools/zls/blob/93b7bbd0d96ee7088c46d1373a2810e84f7d47be/src/features/references.zig#L95-L135
~~If I add a .assign_destructure arm to the switch block, it looks like that matches up with the missing references to the field initializations (I'm still not 100% confident, though). Still working on how to properly add the appropriate information to the references builder, but hopefully this helps narrow down the issue :)~~ Nevermind, definitely not .assign_destructure.
Related #1700
this could be pretty easily fixed by using something like nodesOverlappingIndex here but i can only imagine how potentially expensive that might end up on large files, though it might not be too bad with #2348 for example.