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

CompletionItem - conflict between commitCharacters and a SnippetString insertText #79373

Closed
gjsjohnmurray opened this issue Aug 17, 2019 · 5 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) suggest IntelliSense, Auto Complete

Comments

@gjsjohnmurray
Copy link
Contributor

Issue Type: Bug

  1. In a language extension implement a CompletionItemProvider that returns the following CompletionItem:
{
 label: '$Piece()',
 kind: vscode.CompletionItemKind.Function,
 filterText: '$Piece',
 commitCharacters: ['('],
 insertText: new vscode.SnippetString('\\$Piece(${1:expr}, ${2:dlm}, ${3:int})$0')
}
  1. Enter the keystrokes shown in the following animation:
    junk

In the first part of the recording, when the ( specified in commitCharacters accepts the suggestion notice how VSCode injects that character into the first field of the insertText snippet. This is unwanted.

In contrast, see how the CompletionItem behaves as intended if the suggestion is accepted by pressing 'Tab'.

I acknowledge that altering this behaviour would result in a breaking change. So I propose enhancing commitCharacters to accept as an alternative an array of objects structured as {character: string, inject: boolean}

@jrieken what do you think?

VS Code version: Code 1.37.1 (f06011a, 2019-08-15T16:17:55.855Z)
OS version: Windows_NT x64 10.0.17134

@gjsjohnmurray
Copy link
Contributor Author

Another strategy might be to add an insertSnippet method to TextEdit (equivalent to that method that already exists on TextEditor). Then my CompletionItem could invoke this via additionalTextEdits and specify a suitably-shortened snippet e.g.

new vscode.SnippetString('${1:expr}, ${2:dlm}, ${3:int})$0')

@jrieken jrieken added the suggest IntelliSense, Auto Complete label Aug 19, 2019
@jrieken
Copy link
Member

jrieken commented Aug 19, 2019

/duplicate of #42544

@vscodebot vscodebot bot added the *duplicate Issue identified as a duplicate of another issue(s) label Aug 19, 2019
@vscodebot
Copy link

vscodebot bot commented Aug 19, 2019

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.

Happy Coding!

@gjsjohnmurray
Copy link
Contributor Author

@jrieken thanks for finding the dup. What do you think of my proposal about enhancing commitCharacters? Would you accept a PR? I'm asking here rather than on #42544 because that one is locked despite being open.

@jrieken
Copy link
Member

jrieken commented Aug 20, 2019

Ops, unlocked. Yeah, the proposal does seem reasonable but I didn't spend too much time thinking of it. Tho, it won't be easy to implement because commit characters work with a typing listener that has no chance of preventing. Some "delete that character before inserting the snippet" logic will be needed...

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) suggest IntelliSense, Auto Complete
Projects
None yet
Development

No branches or pull requests

2 participants