linuxvisual-studio-codeurl-scheme

How to set up vscode: protocol to open links in VS Code on Linux?


I downloaded and ran VS Code from a tarball, which does not set up the vscode: protocol binding. So when I installed the Cody AI extension for VS Code, it prompted me to sign in, and I signed in with GitLab in Firefox, but when Firefox tried to redirect me back to VS Code using the vscode: protocol, it didn't know how to because the protocol wasn't registered.

How can I register the protocol manually?


Solution

    1. Download the .desktop file template by going to https://github.com/microsoft/vscode/blob/main/resources/linux/code-url-handler.desktop and clicking the download icon in the top bar of the file.

    2. Edit the file you just downloaded. Replace @@NAME_LONG@@ with "VS Code". Replace @@EXEC@@ with the full path to the code executable on your system. Replace @@ICON@@ with some random application icon, e.g. firefox (it doesn't really matter). Replace @@URLPROTOCOL@@ with vscode.

    3. Very important - do not skip this step, which I couldn't find documented anywhere else, or it won't work! Move the file into ~/.local/share/applications and remove any .download extension if your browser has added it - the file should now have a .desktop extension.

    4. Type xdg-settings set default-url-scheme-handler vscode <your .desktop filename>. Do not provide an absolute path or you will get a cryptic error about invalid application name.

    Now try logging in to the extension again and it should all work. However, I did restart VS Code and Firefox, so you might need to do that as well.