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

executeCommand does not wait for text editor commands to complete #2933

Closed
stkb opened this issue Feb 11, 2016 · 4 comments
Closed

executeCommand does not wait for text editor commands to complete #2933

stkb opened this issue Feb 11, 2016 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@stkb
Copy link
Contributor

stkb commented Feb 11, 2016

If you register a command with registerTextEditorCommand, then when later calling that command with commands.executeCommand(), executeCommand won't wait for that command to complete before resolving. With commands registered with registerCommand, it behaves as expected.

For example, this works:

vscode.commands.registerCommand('extension.normalCommand', () => {
    return new Promise(resolve => {
        // Do some work ...
        console.log("Command is now finished");
        resolve(123);
    })
})

// Later...
vscode.commands.executeCommand('extension.normalCommand').then(value => {
    console.log("Command should have already finished");
    console.log(value);
})

Output:

Command is now finished
Command should have already finished
123

This doesn't:

vscode.commands.registerTextEditorCommand('extension.editorCommand', (editor) => {
    return new Promise(resolve => {
        // Do some work ...
        console.log("Command is now finished");
        resolve(123);
    })
})

// Later...
vscode.commands.executeCommand('extension.editorCommand').then(value => {
    console.log("Command should have already finished");
    console.log(value);
})

Output:

Command should have already finished
undefined
Command is now finished

Can also create an example repo if necessary.

@alexdima alexdima self-assigned this Feb 11, 2016
@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Feb 11, 2016
@alexdima alexdima added this to the July 2016 milestone Jul 5, 2016
@alexdima
Copy link
Member

alexdima commented Jul 5, 2016

Fixed with 1d8a002

@alexdima alexdima closed this as completed Jul 5, 2016
@stkb
Copy link
Contributor Author

stkb commented Jul 5, 2016

👍

@jrieken jrieken added the verified Verification succeeded label Jul 28, 2016
@fcrespo82
Copy link

I have a similar problem with 1.7.2

In my callback I have a call to vscode.window.showInputBox but the code after that uses the value from the input, but the callback is finished before it can use it.

Shouldn't registerTextEditorCommand returns a T | Thenable<T> just like its big brother registerCommand, or am I doing something wrong?

@stkb
Copy link
Contributor Author

stkb commented Dec 7, 2016

@fcrespo82 I think you should probably file a separate issue for that, with example code to reproduce the problem.

@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 verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants