'How to pass data through VSCode URL?

I'm building a VSCode extension, which needs to receive data from a web app. In the web app, I call vscode://file to open VSCode, but I also need to pass data to it.

How do I do that?



Solution 1:[1]

You can find answer from this blog : How to callback to your extension from outside Visual Studio Code

It uses VSCode Extension API : vscode.window.registerUriHandler

  1. Enter vscode://<publisher>.<extension name> Uri in the chrome address field.

publisher and extension name is defined in package.json

  1. Edit extension.ts
export function activate(context: vscode.ExtensionContext) {
  const handleUri = (uri: vscode.Uri) => {
     console.log("uri",uri);  
  };

  context.subscriptions.push(
    vscode.window.registerUriHandler({
      handleUri
    })
  );
}

Ensure that the window that extension is activated is always at the top level.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1