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

Add rename provider #230

Merged
merged 2 commits into from
May 8, 2021
Merged

Conversation

amiralies
Copy link
Contributor

This PR adds lsp rename provider based on references ruquest on analysis cli.
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename

also fixed a small type error in references provider

@cristianoc
Copy link
Collaborator

This looks pretty interesting. Looking.

@cristianoc
Copy link
Collaborator

cristianoc commented May 8, 2021

@amiralies I tried on analysis/tests/src/References.res: this renames References.res but not Cross.res.
Unless Cross.res is already open in the editor, in which case it works.
I think this has to do with vscode's internals. But we would like to have a robust rename, just as we have robust error messages. Any ideas how to do that?

@@ -383,11 +385,49 @@ function onMessage(msg: m.Message) {
// error: code and message set in case an exception happens during the definition request.
};
send(definitionResponse);
} else if (msg.method === p.RenameRequest.method) {
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
let params = msg.params as p.RenameParams;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a bit of code duplication with the rename command.
Maybe it makes sense to move out functionality that could lead to errors in future. E.g. definitely the way the references command is called, which parameters, etc. So that a future edit does not change only one place out of two, by mistake.

} else if (msg.method === p.ReferencesRequest.method) {
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
let params = msg.params as p.ReferenceParams;
let filePath = fileURLToPath(params.textDocument.uri);
let result: Location | null = utils.runAnalysisAfterSanityCheck(
let result: Location[] | null = utils.runAnalysisAfterSanityCheck(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually we had a few of these.
See this alternative way which I'm going to merge now:
#232

Copy link
Collaborator

Choose a reason for hiding this comment

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

Merged --- perhaps rebase on master instead.

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'm not sure if the types on #232 are the correct types.
I've also took look at protocol types in ts and couldn't find correct types.
I think we should rely on manual types based on protocl docs. for example in the docs the response type for references request is Location[] | null but there's not type in ts spec for that.

@amiralies
Copy link
Contributor Author

@amiralies I tried on analysis/tests/src/References.res: this renames References.res but not Cross.res.
Unless Cross.res is already open in the editor, in which case it works.
I think this has to do with vscode's internals. But we would like to have a robust rename, just as we have robust error messages. Any ideas how to do that?

I couldn't reproduce this, tested on vscode, nvim with coc and nvim with built in lsp

recording.mp4

Note that i close files before renaming.

@amiralies amiralies force-pushed the add-rename-provider branch from aadc95f to bd06877 Compare May 8, 2021 09:34
@cristianoc
Copy link
Collaborator

Would you try opening the editor from scratch. Open a single file, then do rename?

@amiralies
Copy link
Contributor Author

Would you try opening the editor from scratch. Open a single file, then do rename?

Sure, It works on my desktop.

recording.mp4

@cristianoc
Copy link
Collaborator

Actually, it works. Sorry for the mix-up.
Thanks for doing this!

@cristianoc cristianoc merged commit d792de9 into rescript-lang:master May 8, 2021
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.

2 participants