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 prepare rename provider #268

Merged

Conversation

amiralies
Copy link
Contributor

No description provided.

@amiralies
Copy link
Contributor Author

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename

this shows a feedback that the current position is not valid to be renamed to the user.
for exmaple try that on a let expression before and after this commit.

let abc = 123
 ^ 

for some reason the { defaultBehavior: boolean } approach didn't work for me

@cristianoc
Copy link
Collaborator

cristianoc commented Jun 7, 2021

(pushed a commit by mistake on this branch). I was going to force-remove it, but don't know if you have some pending changes, so I'll let you remove it.

let result: p.Range | null = null;

if (locations !== null && locations.length > 0) {
let targetLoc = locations.find(loc => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering about the logic (and duplication of logic) here.
It seems intuitively, this should fire exactly when rename returns a non-empty set of changes.

Looking at the commands in Commands.ml, rename returns results always when locations is a non-empty array. So it seems this logic here is unnecessary. Or if necessary, how comes the same logic is not in the rename command?

Should this just call rename instead and check if the result is empty? Not sure why the protocol splits the logic in this way.

Also, just noticed utils.getReferencesForPosition was created when there was more than one use. Before this PR, there was a single use, so it should probably have been removed and inlined.

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 think the split is because of checking rename availability without actually analyzing refs. (I.e check the cursor position is an ident)

Ill look at it tomorrow to see if we can do it better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

One difference w.r.t. rename is that the new name is not supplied. So technically, the rename command cannot be called.

I think this prepare operation makes most sense in an architecture when one has direct access to parsing the document, in which case prepareRename in some cases could be resolved by just parsing.

In our case, we make use of the function that finds references. Note this is more expensive, but it should not matter much as rename is interactive.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see the command should find a range for the symbol. OK then the logic is necessary.

The only remaining comment I have is about returning a boolean directly, which seems to work on vscode but can't see supported in the spec.
Will make a suggestion for a change.

@amiralies
Copy link
Contributor Author

(pushed a commit by mistake on this branch). I was going to force-remove it, but don't know if you have some pending changes, so I'll let you remove it.

Feel free to apply changes to this branch

@cristianoc
Copy link
Collaborator

@amiralies see my proposed change. The only real logical difference is avoiding to return a boolean directly.

@amiralies
Copy link
Contributor Author

The boolean return was inside find method. I'm okay with the change forEach makes sense. it also matches with other parts of the codebase.

@cristianoc
Copy link
Collaborator

The boolean return was inside find method. I'm okay with the change forEach makes sense. it also matches with other parts of the codebase.

That only shows my little knowledge of the language. I did not know that return works like that!

@cristianoc
Copy link
Collaborator

Still, even if the semantics is correct, the readability would not be great. The only way to correctly interpret such a return as a reader would be to spot the little symbol => above.

@cristianoc
Copy link
Collaborator

Looks good!

@cristianoc cristianoc merged commit f8e53ed into rescript-lang:master Jun 7, 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