Dylan Landry
Dylan Landry

Reputation: 1290

How do I prevent my vscode extension's long-running process from blocking other extensions?

I created a vscode extension that takes a while to do it's job. That's okay, but it became a problem when I noticed it causes my other extensions to freeze.

Here's pseudo code for my extension:

async updateExtension() {
  // takes a couple seconds to complete
}

async activate() {
  vscode.workspace.onDidSaveTextDocument(updateExtension);
}

After I save a document I notice my vim extension freezes, I'm unable to move the cursor for as long as my custom extension is updating. Once my extension is done its long update the vim extension catches up and quickly performs all the late actions.

I've tried disabling my vim extension and normal text editing isn't frozen by my own extension taking a long time to update. I'm assuming that this issue with my vim extension is not isolated to itself, I expect it to affect any other extensions and I'd like to avoid that.

My extension's long update runs asynchronous code, including madge and simple-git, so I don't think it should be blocking with any synchronous code.

I've tried doing this instead to try to return early so vscode doesn't wait for my extension to update before moving onto other extensions' listeners:

vscode.workspace.onDidSaveTextDocument(() => updateExtension());

... but it didn't help.

Upvotes: 0

Views: 71

Answers (0)

Related Questions