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

textEditor.insertSnippet: snippet not inserted when text is the same #19449

Closed
aeschli opened this issue Jan 26, 2017 · 3 comments
Closed

textEditor.insertSnippet: snippet not inserted when text is the same #19449

aeschli opened this issue Jan 26, 2017 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug snippets verified Verification succeeded
Milestone

Comments

@aeschli
Copy link
Contributor

aeschli commented Jan 26, 2017

Testing #15952

Create the following extension:

'use strict';
import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
        if (!vscode.window.activeTextEditor) {
            console.log('No editor');
            return;
        }
        let doc= vscode.window.activeTextEditor.document;
        let p = vscode.window.activeTextEditor.insertSnippet(new vscode.SnippetString('for (var ${1:i}=0; ${1:i}<len; ${1:i}++) { $0 }'), new vscode.Position(0, 0));
        p.then(_ => {
            vscode.window.activeTextEditor.insertSnippet(new vscode.SnippetString('for (var ${1:i}=0; ${1:i}<len; ${1:i}++) { $0 }'), new vscode.Position(0, 0));
        });
    });

    context.subscriptions.push(disposable);
}
  • run the extension, open an editor and run the 'hello world' command.
    Only one snippet is inserted.

  • When changing the snippet text of the second snippet, (e.g. 'let to 'var') more is inserted, except for the common prefix.

@jrieken jrieken added this to the February 2017 milestone Jan 27, 2017
@jrieken
Copy link
Member

jrieken commented Jan 27, 2017

Well, insertSnippet returns a promise on which you must wait until further changes are performed. I'll add a guard to make sure the second call is a noop when the version numbers don't match anymore

@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug snippets labels Jan 27, 2017
@aeschli
Copy link
Contributor Author

aeschli commented Jan 27, 2017

Ok, I updated the code example above to use the promise. Bug is still there.

@jrieken
Copy link
Member

jrieken commented Jan 27, 2017

I guess that happens because the editor is still in snippet mode. Unsure if, the promise should only resolve when snippet mode has finished, if snippet mode should be aborted and restarted, or if the second snippet should be blocked (promise resolving to false)

@roblourens roblourens added the verified Verification succeeded label Feb 24, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug snippets verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants