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

Fix prepareRename support #2127

Merged
merged 4 commits into from
Dec 11, 2022
Merged

Fix prepareRename support #2127

merged 4 commits into from
Dec 11, 2022

Conversation

rchl
Copy link
Member

@rchl rchl commented Dec 3, 2022

The issue with the old code was that it has shown the input overlay asking for new name before sending the prepareRename request and didn't use the range (or placeholder) from the response.

Added big comment about how lsp_symbol_rename works since it behaves very differently depending on if server supports prepareRename request.

Related to sublimelsp/LSP-typescript#178

plugin/documents.py Outdated Show resolved Hide resolved
Comment on lines -45 to -57
# mypy: Signature of "is_enabled" incompatible with supertype "LspTextCommand"
def is_enabled( # type: ignore
self,
new_name: str = "",
placeholder: str = "",
position: Optional[int] = None,
event: Optional[dict] = None,
point: Optional[int] = None
) -> bool:
if self.best_session("renameProvider.prepareProvider"):
# The language server will tell us if the selection is on a valid token.
return True
return super().is_enabled(event, point)
Copy link
Member Author

Choose a reason for hiding this comment

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

This was redundant and it's enough to use base implementation.
When this code was introduced it looked a bit differently and it made sense then.

Comment on lines +97 to +99
listener = self.get_listener()
if listener:
listener.purge_changes_async()
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added "purge" because I've noticed an issue with lsp-typescript where it requests client to apply edits and immediately triggers rename before client has triggered "didChange".

https://github.com/typescript-language-server/typescript-language-server/blob/0403b36a6ae181fb25f8236f47029afeb2a739fb/src/lsp-server.ts#L938-L949

@rchl rchl merged commit 472187b into main Dec 11, 2022
@rchl rchl deleted the fix/prepare-rename branch December 11, 2022 12:28
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.

1 participant