-
Notifications
You must be signed in to change notification settings - Fork 184
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 willRename and didRename fileOperations #2498
Conversation
11b3618
to
6f65462
Compare
I will highlight things implemented from the LSP spec. Renaming a document
That part of the spec can be seen on these two lines:
Note The user could rename WillRenameFiles Request
That can be seen here: Lines 95 to 98 in 6f65462
I didn't implement this. DidRenameFiles NotificationWhen a rename happened, all sessions who have the |
Here is what to expect from this PR.
For session that don't support the |
The built-in Line 209 in 293f4a4
While for other features like document symbols or goto symbol, the similar built-in commands are not overridden because they can return different results as the LSP commands, so it might be useful to have both variants. But I think for the rename this is not necessary and to add two more LSP variants into the menus would not be optimal for usability. What do you think? |
plugin/rename_file.py
Outdated
open_file_uri(self.window, new_path).then(restore_regions) | ||
|
||
def notify_did_rename(self, rename_file_params: RenameFilesParams): | ||
sessions = [s for s in self.sessions() if s.has_capability('workspace.fileOperations.didRename')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server capability is defined as 'workspace.fileOperations.didRename'
:
interface ServerCapabilities {
workspace: {
//...
fileOperations: {
// ...
didRename?: FileOperationRegistrationOptions
}
}
interface FileOperationRegistrationOptions {
filters: FileOperationFilter[];
}
export interface FileOperationFilter {
scheme?: string;
pattern: FileOperationPattern
}
interface FileOperationPattern {
glob: string;
matches?: FileOperationPatternKind;
options?: FileOperationPatternOptions;
}
To implement this properly I would need to respect the provided pattern in FileOperationRegistrationOptions
,
but that seem like more work. The current code also works, at least with the server I am testing this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I am unsure if I need to implement FileOperationRegistrationOptions in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should try implementing that. filters
is not an optional feature so we won't be complaint otherwise.
@jwortmann I tried to implement your suggestion on a different branch, |
I will try a workaround sublimehq/sublime_text#2234 (comment) |
@jwortmann I liked the idea, that way we do not introducing new commands, instead relying on existing ones. |
…s from that folder to new location so we do not lose changes The ST default rename_path command doesn't do this VS Code does this LSP will do this
…r of match_file_operation_filters
…ys LSP: Rename File I cannot tweak the text inside the TextInputHandler use show_input_panel instead...
Co-authored-by: jwortmann <[email protected]>
…g ST rename_path command
Will this allow functionality like described in sublimelsp/LSP-intelephense#112 that works in Vscode, where a symbol is mapped to a file name, so the file name would be automatically changed if the symbol is renamed? |
I believe no, this PR would only work in the other direction, i.e. if you rename a file, then the corresponding class name would be updated in that file and in other files. For the functionality from the linked issue, we need to add support for Lines 19 to 22 in f983345
|
@jwortmann thanks for that info. |
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I've noticed that renaming unsaved file is a bit broken because it triggers a dialog to either save or not the changes but at this point the file is already renamed. Then pressing save tries to save the file to the old location and not saving changes leaves the old view open. I suppose that's related to not using |
Another difference compared to native behavior is that if you try to rename a file that is not "fully open" (only previewed on right clicking in the sidebar) then native behavior will keep the renamed one in preview mode while LSP will open the file in non-preview mode. That doesn't seem like much of an issue but there might be it might create some extra issues that I'm not seeing right now. |
Rafal thanks for catching this. Currently the code closes and opens the file after rename. |
🙈 |
Will this get implemented then? 😄 |
@predragnikolic is the last discussed issue something that you would consider the remaining blocker? I no longer have clear recollection of the issues here but if something is not currently possible due to ST limitations then perhaps it would be good idea to make an upstream issue for what's missing. |
I'm not sure :)
Yes. It is possible to implement this, there are no ST blockers.
The easy way to solve the issues you reported, would be to save the file before closing the view. https://github.com/sublimelsp/LSP/pull/2498/files#diff-06bad17710895021d007aba395accf463493660accc8165970646eb9dbde7e0fR101 I don't know if it is expected that a file gets saved before the rename. I haven't test if that would work in all 3 cases.
The reason why I wanted to close and open the view is to avoid thinking if when to shutdown a LS and when to start a new one. I still think that is the easier way to do it, but I am not sure if it is the proper way to do it. |
closes #2199
Here is a example video:
Kapture.2024-06-25.at.18.24.36.mp4
Notice the import changing in file
a.ts
when we rename theb.ts
file.example.zip