Repository navigation
Apply bottom-most SnippetTextEdit in TextDocumentEdit as snippet - #2944
Conversation
|
It looks like Ruff rule C413 is a false-positive, because |
|
I haven't tested yet but switching from top to bottom most doesn't sound good because rust analyzer has a feature to move function up or down and each triggers opposite snippet case. |
|
Maybe I misunderstood. It does actually work both ways (with the change in sublimelsp/LSP-rust-analyzer#208) Screen.Recording.2026-05-31.at.10.13.28.mov |
|
If there is only one SnippetTextEdit in the edits, it is automatically the bottom-most, even if it is the topmost edit. The "bottom-most" is only relevant if server puts multiple SnippetTextEdit's in the edits. In that case we apply the first one that we see, and that is the bottom-most, because edits are applied from bottom to top. |
|
It would be nice to have a use case where the SnippetTextEdit contains placeholder texts and multiple tab stops, to confirm that the snippet still works correctly even when there are other edits applied to the buffer after the |
|
I've manually overridden response for RA and tested both with: and And in both cases I was able to jump to the last ( (those are listed in the order they were applied) |
Documentation says that it's unsafe for this specific case: https://docs.astral.sh/ruff/rules/unnecessary-call-around-sorted/#fix-safety so ignoring is the right way to go. |
| # The insert_snippet command automatically adds additional indentation to each row, based on the | ||
| # indentation level of the row where it gets inserted. Therefore we first have to remove that same | ||
| # indentation whitespace after each line break in the snippet text from the language server. |
There was a problem hiding this comment.
Perhaps worth creating a feature request for ST so that we don't have to do this potentially fragile logic.
This relaxes the condition that the SnippetTextEdit from a TextDocumentEdit needs to be the topmost edit in the file, (if there are multiple edits), in order to be applied as a snippet (otherwise it was downgraded to a regular TextEdit).
Now we apply the first, i.e the bottom-most SnippetTextEdit as a snippet, and in case there are more SnippetTextEdit's later, they are downgraded to regular TextEdit's.
It would be good to test this with the example from #2941 (comment) to confirm that it works as expected (i.e. test that edits to the file which are applied after the
insert_snippetcommand don't break the snippet behavior).