-
Notifications
You must be signed in to change notification settings - Fork 188
Add willRename and didRename fileOperations #2498
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
base: main
Are you sure you want to change the base?
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? |
|
@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
rchl
left a comment
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.
After all the years of work, I think it looks good now :)
|
There are two minor things worth addressing in this PR.
|
old_path is a full path - "/full/path/to/hello.txt" new_name is not a full path - "./../hello.txt" new_path is a full path - "/full/path/to/hello.txt"
self.window.views() returns views ordered from left to right. When we iterate to close the views in the first loop, because closing a view shifts the indices of all subsequent views (to its right), we must iterate and grab the views from right to left (in reversed order). This prevents the shifting indices from causing errors when calling get_view_index for the remaining views. When we restore the views, we do the opposite: we iterate from left to right (in original order).
|
Thank you Rafal, Janos for the comments. |
and ignore the rest because required_view_version might throw an error
Initially it was implemented to be send to only one server later in fbcbec5 it was changed to be send to all servers the benefit is that multiple server can receive WorkspaceEdit, however the downside is that apply workspace edits in the LSP can fail if the document version changes. So for now I will only send the request to one server
This reverts commit 3267e02.
…onses. The response type for the request is WorkspaceEdit | null, so maybe there could be a case where only one of the servers responds with a WorkspaceEdit, and this way would increase the chance that we get at least one response which is not null
|
Here is a video that could be used to showcase this feature in the release notes:
demo.mp4
|
|
I will wait one day to see if there are some additional comments |
|
Another idea that I just had: it might not be obvious to users why there is a special "LSP: Rename Path" command for a simple rename operation and even when mentioned in the release notes, people might not remember it later. So maybe after applying the WorkspaceEdit, we can display a It might also be nice to add another section "Rename Path" with a short description in the docs after https://lsp.sublimetext.io/features/#rename. |
Here X would be the total number of Lines 61 to 63 in d5aefde
Though I'm not sure if it is possible to evaluate the correct number, because this method calls a TextCommand which then can also ignore edits at Lines 62 to 64 in d5aefde
and I think there is no way to report the actual number of applied changes back to the caller. Maybe for now it would be sufficient to just count the TextEdits and URIs that are in the WorkspaceEdit (i.e. regardless of whether they were applied or not). Could be done in a different PR (just throwing in some ideas here). |
|
+1 for adding docs For the other improvements that were suggested by Janos, I do have something to share. I experimented the previous week with adding the same prompt that we have for rename symbol. prompt.mp4I did not push the "prompt" code changes to Github, they will probably be introduced in a follow up PR. The same goes true for the docs. That said, I am fine if this PR stays open until I create the other two changes. |
closes #2199
Here is a example video:
Kapture.2024-06-25.at.18.24.36.mp4
Notice the import changing in file
a.tswhen we rename theb.tsfile.example.zip