Skip to content

Add support for SnippetString in TextEdit and WorkspaceEdit #145374

Description

The TextEdit and WorkspaceEdit 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 vairable

Activity

  1. jrieken commented on Apr 7, 2022

    @jrieken
    ContributorAuthor

    For 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
  2. 11 remaining items

  3. jrieken commented on Aug 24, 2022

    @jrieken
    ContributorAuthor

    Plan to finalize this API for September

  4. jrieken commented on Sep 13, 2022

    @jrieken
    ContributorAuthor
  5. jrieken commented on Sep 13, 2022

    @jrieken
    ContributorAuthor
  6. zardoy commented on Sep 13, 2022

    @zardoy
    Contributor

    Johannes Rieken (@jrieken) as I understand, CompletionItem.additionalTextEdits won'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.

  7. jrieken commented on Sep 13, 2022

    @jrieken
    ContributorAuthor

    Johannes 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

  8. zardoy commented on Sep 22, 2022

    @zardoy
    Contributor

    Johannes 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.insert doesn't do space adjusting like editor.insertSnippet).

    Is that also by design?

  9. jrieken commented on Sep 26, 2022

    @jrieken
    ContributorAuthor

    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

  10. zardoy commented on Sep 26, 2022

    @zardoy
    Contributor

    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=false for 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!

  11. locked and limited conversation to collaborators on Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions