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

minor: Allow multiple snippet edits in a TextDocumentEdit #15876

Merged

Conversation

DropDemBits
Copy link
Contributor

Explicitly1 allow a single TextDocumentEdit to have multiple SnippetTextEdits. This allows things like renaming extracted variables and functions without having to go through a separate rename step. For an example of what this looks like, see the video in this comment.

The behavior described here lines up with what VSCode does, and presumably what the eventual LSP behavior will be.

Footnotes

  1. This was technically the case before internal: Defer structured snippet rendering to allow escaping snippet bits #15269, a single TextDocumentEdit always had multiple edits which were InsertTextFormat.Snippet as all of the edits were marked as being snippets, even if there weren't any tab stops or placeholders.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 12, 2023
@DropDemBits
Copy link
Contributor Author

Wasn't sure on which changelog prefix to use since it's only a documentation change (would minor work for this?).

@Veykril Veykril changed the title Allow multiple snippet edits in a TextDocumentEdit minor: Allow multiple snippet edits in a TextDocumentEdit Nov 12, 2023
@Veykril
Copy link
Member

Veykril commented Nov 12, 2023

minor should be fine, lsp extension changes relevant for client implementations should be announced at #4604 fwiw

@Veykril
Copy link
Member

Veykril commented Nov 12, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 12, 2023

📌 Commit 1e46868 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Nov 12, 2023

⌛ Testing commit 1e46868 with merge 92d9ca7...

@bors
Copy link
Collaborator

bors commented Nov 12, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 92d9ca7 to master...

@bors bors merged commit 92d9ca7 into rust-lang:master Nov 12, 2023
10 checks passed
@DropDemBits DropDemBits deleted the lsp-ext-multiple-snippet-textedit branch November 13, 2023 20:30
@nemethf
Copy link
Contributor

nemethf commented Nov 13, 2023

@DropDemBits, do I understand correctly that currently rust-analyzer does not have a feature that creates a single TextDocumentEdit with multiple SnippetTextEdits? Once it has, can you, please, update the example section? It would help me to implement this in a LSP client.

Thank you.

@DropDemBits
Copy link
Contributor Author

@nemethf That is correct. It's something that I'm planning to do too, and I can also ping when I make the PR.

@nemethf
Copy link
Contributor

nemethf commented Feb 9, 2024

It's something that I'm planning to do too, and I can also ping when I make the PR.

@DropDemBits, have you made any progress on this? Thanks.

@DropDemBits
Copy link
Contributor Author

@nemethf Sorry, just started working on rust-analyzer again recently after a bit of a break.

I still have this tracked in my backlog, though with college running up again it's hard to find free time to work on stuff again. 😅

nemethf added a commit to nemethf/eglot-x that referenced this pull request Feb 21, 2024
rust-lang/rust-analyzer#15876
https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_trait_from_impl.rs#L20

* eglot-x.el (eglot-x-enable-snippet-text-edit): Add link to an example.
(eglot-x--unify-snippets, eglot-x--work-around-snippet-bug): New
defuns.
(eglot-x--apply-text-edits): Give a single, merged range to
snippet-expansion-fn when there are multiple snippets in a
text-edit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants