-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 support for SnippetString in TextEdit and WorkspaceEdit #145374
Comments
For April I have enabled this (for editor dnd) and for May we can make this more prominent. Questions
|
The actual refactoring is staged but it allow for cool things like such an enhanced extract const flow Screen.Recording.2022-07-07.at.11.58.17.mov |
Hey! Thank you so much for planning this feature! I'd use it in my extension to replace some typed text into snippet. I checked it in insiders and IMO the current implementation is just ideal as it works with multiple different snippets! |
Plan to finalize this API for September |
…dd `WorkspaceEdit#set` overloads #145374
This is now done via |
fyi @matklad |
@jrieken as I understand, 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. |
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 |
@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 ( Is 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 |
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
Thank you so much, I really appreciate the work you're doing here! Let me know how it goes! |
The
TextEdit
andWorkspaceEdit
APIs 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 vairableThe text was updated successfully, but these errors were encountered: