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

feat: Warn the user when a rename will change the meaning of the program #19079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChayimFriedman2
Copy link
Contributor

Specifically, when a rename of a local will change some code that refers it to refer another local, or some code that refer another local to refer to it.

We do it by introducing a dummy edit with an annotation. I'm not a fond of this approach, but I don't think LSP has a better way.

Demo:

Screen.Recording.2025-02-02.015127.mp4

Closes #10713.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 1, 2025
},
Indel {
insert: "\n\nfn fun_name() -> i32 {\n 5\n}",
delete: 110..110,
annotation: None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but might be nice to omit rendering annotation in the debug impl if its None (given we use it in a bunch of expect tests that reduces some noise)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to update the tests, like what if we will need it in some of them eventually.

// Create a dummy edit to warn the user.
file_id = Some(file_id2);
let text = sema.db.file_text(file_id2.file_id())[range].to_owned();
edit.indel(Indel::replace(range, text).with_annotation(annotation));
Copy link
Member

@Veykril Veykril Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need annotation support on an Indel basis? That seems way too fine grained, imo it should totally suffice to attach an annotation on a per TextEdit basis instead. That would simplify things as well (just because the LSP allows us to have this level of control doesn't mean we need to do so).

That way we also don't need a dummy edit here I believe and instead just attach the annotation to the edit and then replicate that back to all of its indels within the proto conversion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dummy edit is important because it shows which variables will conflict. As such I think we do need them on Indel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that rather confusing though. We are abusing the LSP here, showing the user a no-op edit (that in VSCode they can set a checkbox for that doesn't do anything).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that either, but I do think pointing to the affected variables is important. Perhaps we can create a protocol extension? Does VSCode have some way to point at them during rename?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is. VSCode is generally very inflexible with its builtin features.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so I don't know what is best. I still think we should show the conflicting variables, but I also agree the noop edit is confusing. So I'll do what you prefer. Do you prefer to show one confirmation?

Specifically, when a rename of a local will change some code that refers it to refer another local, or some code that refer another local to refer to it.

We do it by introducing a dummy edit with an annotation. I'm not a fond of this approach, but I don't think LSP has a better way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renames are allowed to change the meaning of the program, due to shadowing.
3 participants