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: LSP rename support #4365

Merged
merged 22 commits into from
Aug 7, 2023
Merged

Conversation

alex-chew
Copy link
Contributor

@alex-chew alex-chew commented Aug 1, 2023

Fixes #2322.

TODO:

  • Base implementation
  • Add unit tests
  • Figure out why IDE doesn't seem to find project file as expected

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@alex-chew alex-chew marked this pull request as ready for review August 3, 2023 22:07
// Reject rename requests in implicit projects, because we might not find all references within the codebase,
// so a partial rename may result in breaking the codebase
if ((await projects.GetProject(requestUri)).IsImplicitProject) {
throw new Exception("Renaming support requires --project-mode and a Dafny project file (dfyconfig.toml)");
Copy link
Member

@keyboardDrummer keyboardDrummer Aug 4, 2023

Choose a reason for hiding this comment

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

What's the resulting behavior in the client? Does it allow the user to attempt to rename after which nothing happens, or it the rename prevented altogether?

I see that LSP also has a prepareRename request: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_prepareRename

that seems to be meant to deal with situations in which renaming is not valid, but that doesn't seem to be implemented here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the resulting behavior in the client? Does it allow the user to attempt to rename after which nothing happens, or it the rename prevented altogether?

The VS Code client prevents the rename altogether, making no document changes, and shows the error message of the exception. Unfortunately, the Omnisharp library doesn't seem to have a way to cleanly show an error message, so the error message looks like a crash (includes stack trace and everything) until you read the message in detail. If there's a better way to display an error message, please let me know.

I see that LSP also has a prepareRename request: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_prepareRename

that seems to be meant to deal with situations in which renaming is not valid, but that doesn't seem to be implemented here.

Indeed this PR doesn't implement the prepareRename request.

@keyboardDrummer
Copy link
Member

Looks great! Left one comment

@alex-chew alex-chew enabled auto-merge (squash) August 4, 2023 16:00
public async Task RenameNonSymbolFails() {
var tempDir = await SetUpProjectFile();
var documentItem = await CreateAndOpenTestDocument("module Foo {}", Path.Combine(tempDir, "tmp.dfy"));
var workspaceEdit = await RequestRename(documentItem, new Position(0, 6), "space");
Copy link
Member

Choose a reason for hiding this comment

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

What if you do a PrepareRename call here? Can that one fail and succeed?

Copy link
Member

@keyboardDrummer keyboardDrummer left a comment

Choose a reason for hiding this comment

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

Approved

@alex-chew alex-chew merged commit c31932b into dafny-lang:master Aug 7, 2023
@alex-chew alex-chew deleted the feat/lsp-rename branch August 7, 2023 20:42
keyboardDrummer pushed a commit to keyboardDrummer/dafny that referenced this pull request Sep 15, 2023
keyboardDrummer pushed a commit that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support the Rename LSP request type
2 participants