VSCode Version: 0.10.11
OS Version: Windows 10
Details:
Please provide a URL handler for accessing vscode from external applications.
For example :
vscode://open?url=file://path/to/file
vscode://new?text=text_that_will_be_in_file&type=js
This would be very useful for lets say browser extensions etc....
@joaomoreno fyi maybe this is easy to do given you already work on this area
Well... this specific use case won't happen. You can already open files in the command line. If you want API for creating an unsaved buffer with a certain content in a certain mode, that's definitely a feature request.
Hi, @kamilkosek
I had the same request like you, after search on github and reference from subl-handler. I accomplished vscode:// url handler here: https://github.com/shengyou/vscode-handler.
It's not perfect, but for workaround, it just works. FYI.
It looks like VS Code now registers a URL handler for "vscode", at least on Mac.


Unfortunately, it doesn't seem to work. Anyone know if it's supposed to?
@robyoder What exactly do you mean by _it doesn't seem to work_? What steps are you performing?
Like the OP, I'm looking for a way to use URLs like this to open files in VS Code: vscode://open?url=file://path/to/file&line=2&column=12
So when I said it didn't seem to work, I meant that it didn't open a URL like that correctly. But I have no idea what the built-in functionality is supposed to do. It just doesn't do what this issue is talking about and what I wish it did.
My specific steps are:
vscode:// prefix, but nothing else happens. The file is not opened.Since @shengyou's solution uses the same vscode scheme, it wasn't working. Control was transferred directly to Code instead of his handler app, but Code didn't do anything with the URL. So I forked @shengyou's repo and changed the scheme to vs-code to avoid the conflict and get it working.
So do you know if Code is supposed to be handling vscode:// URLs? If so, what is it supposed to be doing with them and what formats does it support? If not, why is the scheme registered with the system?
VSCode is able to handle vscode:// urls. The only syntax it supports so far is the one used to open extensions from the Marketplace: vscode://extension/extension.id.
What is the actual use case of opening files through a URL handler? Why not simply calling code file from the command line?
@joaomoreno, interesting, thanks for the info about the syntax/purpose it supports. That's what I was looking for, but couldn't find any references to.
My use case I described in my last comment. My TypeScript build script logs errors to the Terminal window. On a Mac, you can command-double-click URLs in the Terminal to open them. You can't command-double-click a Terminal command to execute it. So If I can command-double-click vscode://open?url=file:///some/path/to/file.ts&line=7&column=3, then I can go straight to the file. Otherwise, I would need to log code -g -r /some/path/to/file.ts:7:3, then select that text, copy it, and paste it at the command prompt. It's just about ease and speed, which happens to be what most of software is about come to think of it...
The script that @shengyou put together does this for me, intercepting the vscode:// url and transforming it into a shell script which it executes to open the file. The only problem is that since VS Code registers the vscode:// URL scheme, @shengyou's script won't get the URL. So I forked his repo and changed the script to look for vs-code:// URLs instead.
My script works just fine, but when I saw that VS Code had registered the vscode:// scheme, I thought there might be a chance that this functionality was being implemented natively. I see that is not the case, and that is fine, I was just curious. I will continue happily using my script and supplying it to my team for their use as well. No further action is needed here unless someone considers this a worthwhile feature to build into the app. (It is a native feature in Sublime.) Thanks for your response!
Got it.
There's no reason we don't handle files through URLs, though, thus saving you the need for an extra script. Do you want to attempt a PR? It should be fairly straightforward. URLService is a great place to start from. I suggest URLs in the format of vscode:file/PATH with the optional line and column query params. We could have the WorkbenchEditorService listen on that onOpenURL event.
Oh man, I wish I could attempt a PR. I'm a little out of my depth here though and things are crazy busy. If no one touches this, I'll see if I can come back to it some time.
No worries about depth, it's quite straightforward. I'll be your guide, in case you get lost. 馃憡
@joaomoreno - I came across this conversation this morning and thought I'd take a stab at the implementation. Would you mind giving this PR a review: https://github.com/Microsoft/vscode/pull/15320?
Where can I find documentation on the expected format for these links? I'm using links in the following format, and the Code app opens upon clicking the link but the file itself is not opened.
vscode://open?url=file:///path/to/file.ext
This should do it: vscode://file/path/to/file.ext. Also, Microsoft/vscode-docs#791
@johnbillion : In addition to what @joaomoreno provided.
Open a file to a specific line and column number:
vscode://file/path/to/file/file.ext:L:C
Example Open file.ext to line 55 and column 20:vscode://file/path/to/file/file.ext:55:20
Open a project, workspace, or folder with directory contents:
vscode://file/path/to/project/
Most helpful comment
@johnbillion : In addition to what @joaomoreno provided.
Open a file to a specific line and column number:
vscode://file/path/to/file/file.ext:L:CExample Open file.ext to line 55 and column 20:
vscode://file/path/to/file/file.ext:55:20Open a project, workspace, or folder with directory contents:
vscode://file/path/to/project/