Repository navigation
Add support for SnippetString in TextEdit and WorkspaceEdit #145374
Description
Activity
- addedfeature-requestRequest for new features or functionalityRequest for new features or functionality
on Mar 18, 2022 jrieken commented
on Apr 7, 2022 ContributorAuthorMore actionsFor April I have enabled this (for editor dnd) and for May we can make this more prominent. Questions
- how to handle N snippet edits
- where to allow snippets edits
- how do snippet edits fit into workspace edits
11 remaining items
jrieken commented
on Aug 24, 2022 ContributorAuthorMore actionsPlan to finalize this API for September
Reacted by Vitalyjrieken commented
on Sep 13, 2022 ContributorAuthorMore actionsThis is now done via
SnippetTextEditandWorkspaceEdit.set(Uri, SnippetTextEdit[])jrieken commented
on Sep 13, 2022 ContributorAuthorMore actionsJohannes Rieken (@jrieken) as I understand,
CompletionItem.additionalTextEditswon't receive snippets support, right?Inserting/replacing content with snippets would require additional command execution for these cases. I can imagine cases, where it could be handly to replace a few lines with some snippet on completion accepted.
jrieken commented
on Sep 13, 2022 ContributorAuthorMore actionsJohannes Rieken (@jrieken) as I understand, CompletionItem.additionalTextEdits won't receive snippets support, right?
As for this issue no and it needs thinking if it can be done, esp since they can come late and since the main edit can already be a snippet
Reacted by VitalyJohannes Rieken (@jrieken) I also want to ask you about white space normalization. It'd much easier to describe the issue with the following code:
const insertString = '1\n\t1\n1' const snippetString = new vscode.SnippetString(insertString) const editor = vscode.window.activeTextEditor! const insertPos = editor.selection.active // 1 const edit = new vscode.WorkspaceEdit() edit.set(editor.document.uri, [vscode.SnippetTextEdit.insert(insertPos, snippetString)]) void vscode.workspace.applyEdit(edit) // 2 void editor.insertSnippet(snippetString, insertPos)
For me, these approaches to insert snippet seemed equal, but they actually insert different text (
vscode.SnippetTextEdit.insertdoesn't do space adjusting likeeditor.insertSnippet).Is that also by design?
jrieken commented
on Sep 26, 2022 ContributorAuthorMore actionsIs that also by design?
Fair question and something I didn't consider yet. Don't know yet what the design should be but looking at the sources they should behave the same: both should default to adjusting whitespace. I will investigate
Fair question and something I didn't consider yet. I will investigate
If I lived in ideal world I'd see an option to also disable this behavior :) IMO these two cases I described above should be aligned with what accepting completion does. e.g. ok if it does space adjusting by default, but there also should be away to disable that, like we can disable it with
keepWhitespace=falsefor suggestions. Hope you will consider that 🙏I will investigate
Thank you so much, I really appreciate the work you're doing here! Let me know how it goes!
- addedon-release-notesIssue/pull request mentioned in release notesIssue/pull request mentioned in release notes
on Oct 1, 2022 - locked and limited conversation to collaborators
on Oct 28, 2022
The
TextEditandWorkspaceEditAPIs are used to apply refactorings. Those will benefit from being able to place the cursor and add placeholders, like add a placeholder for the suggested name of an extracted vairable