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

Correct generate rename code action in LSP #67731

Merged
merged 13 commits into from
Apr 14, 2023

Conversation

Cosifne
Copy link
Member

@Cosifne Cosifne commented Apr 11, 2023

If a document is renamed, using Document.Rename
The document would still have the same document Id.
In this case, the document is considered as InfoChange

In LSP we only generate text edits to the client, and this would make things like 'Rename file to match the type' not working in LSP

@Cosifne Cosifne requested a review from a team as a code owner April 11, 2023 04:37
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 11, 2023
@Cosifne Cosifne enabled auto-merge April 13, 2023 22:59
Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

This is probably going to throw exceptions around additional files if we had a rename of those; the test also potentially looks incomplete as I'm not sure it's missing an assert. Should be easy to fix though.

Comment on lines +167 to +169
// Rename documents is not supported by this workspace
codeAction.Edit = new LSP.WorkspaceEdit { DocumentChanges = Array.Empty<TextDocumentEdit>() };
return codeAction;
Copy link
Member

Choose a reason for hiding this comment

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

Should we have filtered out this sort of code action earlier rather than bailing here? Because this would mean we will show the action but invoking it will do nothing? I see this pattern is widely used so I'd rather take this PR than nothing at all, but still wondering if we should be making further changes here.

Copy link
Member Author

@Cosifne Cosifne Apr 14, 2023

Choose a reason for hiding this comment

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

This pattern is introduced by Sam to overcome the cases when VS doesn't support the client's capabilities.

This seems like we need to ask each refactoring provide/code fixer to give hints about the kind of operation it is going to perform when the code action is computed. So we can filter the unsupported code actions before the changes are computed.
It sounds like a bigger change, but unrelated to this PR.

Tag @dibarbet , @sharwell also maybe @CyrusNajmabadi
Do we want to create a work item for this?

@Cosifne Cosifne merged commit 0368609 into dotnet:main Apr 14, 2023
@ghost ghost added this to the Next milestone Apr 14, 2023
@dibarbet dibarbet modified the milestones: Next, 17.7 P1 Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants