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

Rename of enum field does not rename references. #2048

Open
smallkirby opened this issue Oct 8, 2024 · 1 comment
Open

Rename of enum field does not rename references. #2048

smallkirby opened this issue Oct 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@smallkirby
Copy link

smallkirby commented Oct 8, 2024

Zig Version

0.14.0-dev.1820+ea527f7a8

ZLS Version

0.14.0-dev.167+063d7ff

Client / Code Editor / Extensions

Visual Studio Code-1.94.0

Steps to Reproduce and Observed Behavior

Init new project with zig init.
Edit main.zig as follows:

const std = @import("std");
const log = std.log;

const SomeEnum = enum(u8) {
    zero,
    one,
    two,
};

pub fn main() !void {
    const e = SomeEnum.two;
    switch (e) {
        .zero => log.info("zero", .{}),
        .one => log.info("one", .{}),
        .two => log.info("two", .{}),
    }
}

Right click the field of enum SomeEnum, for example zero, to rename. Enter new name and press enter. The field name is successfully renamed but its usages, .zero in the switch in this example, are not renamed.

Expected Behavior

Enum field itself and all the usages are renamed.

Relevant log output

No response

Notes

This would be the continuation of #2042. By #2043, the rename operation itself stopped failing. But it still does not work as expected.

@smallkirby smallkirby added the bug Something isn't working label Oct 8, 2024
@srijan-paul
Copy link
Contributor

So this one is a little harder to tackle, because ZLS cannot infer enum types like the zig compiler can, and the compiler itself does not expose an API to query type information after the Sema phase.
Though maybe in cases like this where there can only be one obvious type that .zero belongs to, we can use the AST to find references? Worth trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants