Open AbdealiLoKo opened 4 years ago
Yeah I don't think this is currently possible it but it seems straightforward enough to implement.
So this was implemented in https://github.com/cdr/code-server/issues/1292
Will become more visible with https://github.com/cdr/code-server/issues/2179
I think this is for editing a file from a link on a website or something in code-server. So clicking it would launch code-server and then open that file. Actually it would be even cooler maybe if we could handle web+code-server://
URLs and then they open in your existing code-server (or a new one if it's not open).
Oh my bad. I thought we supported ?path=
for this or something along those lines @code-asher
In regards to the scheme URL, see https://github.com/cdr/code-server/issues/1571
We have ?folder=
and ?workspace=
but nothing for individual files yet.
I should have linked that issue! Maybe we just roll this up into that one.
I think they're different enough, will reopen this.
Just giving my two cents that this is a worthy enhancement. A lot of doc sites themes/builders have built in opening the corresponding file in a github repo for editing from the rendered page like this https://geekdocs.de/usage/configuration/ (see Edit this page
link). If opening a file directly from url worked in code-server one could use this feature by just supplying the configuration values. I've already tried and it kinda works sans being able to open the exact page.
geekdocRepo: https://my.domain.net
geekdocEditPath: ?folder=/files/content
renders
https://my.domain.net/?folder=/files/content/_index.md
which sadly does not open the page for editing. Might be nice if it opened the root folder tree in naviator and that file in the editor.
I think if code-server
were to implement this feature, the query param folder
should be replaced with a single param named path
. I just think it would be more straightforward and wouldn't be as confusing as having two.
And maybe possibly @dkebler's comments:
Might be nice if it opened the root folder tree in naviator and that file in the editor.
could be implemented via an option.
probably need to continue support for ?folder=
but ?path=
could as @JammSpread says be used for both, to load a directory (i.e. folder) in the explorer and an actual file in editor if supplied in path string.
Not sure if it's possible but if there is already an open tab then it should just load the file there instead of opening another instance.
Is anyone currently working on this? Having ?path=
support file names would allow me to use code-server rather than rolling my own solution, which would be a waste when code-server is so close. I haven’t looked at the code yet, but I’ll see if I can find where path
is implemented. FWIW, my implementation would be ?path=/dir/file.ext:line
and possibly optional column for those who would want that level of granularity.
Is anyone currently working on this?
Not actively being worked on, but I can move it to On Deck so it's on our radar and ready to be worked on!
Thanks so much for the responsiveness.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no activity occurs in the next 5 days.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no activity occurs in the next 5 days.
Is anyone currently working on this?
Not actively being worked on, but I can move it to On Deck so it's on our radar and ready to be worked on!
So ... it's been a year. How long does On Deck go out?
So ... it's been a year. How long does On Deck go out?
Great question! So there isn't an exact number. We won't be adding many new features to code-server unfortunately. We'll still keep this open though but it's not guaranteed that it will be worked on. On Deck just means it's something that could be picked up.
I'm going to move it to Backlog though since like I said, we won't be adding new features.
Thanks very much for the reply.
Is there some other browser-based editor the team is working on instead?
Is there some other browser-based editor the team is working on instead?
Great question! No, but we want to stay as close to VS Code as possible (you can see our patches here). In the ideal world, we would have no patches and any features (like this one) would be implemented in VS Code.
Since Codespaces came out and the VS Code team has open sourced more of the web-side of VS Code, we've been able to eliminate some of our patches. Therefore, we try to introduce as few new patches as possible. Our plan right now is to fix bugs and stay close to VS Code.
If this type of feature request could be implemented upstream, then VS Code Web/Codespaces and code-server could all benefit. I haven't looked though to see if that's something they're working on, or how difficult it would be.
Makes sense. Thanks!
I'm not sure, but I think there is something like this in VS now. Unless it's an extension I forgot I installed.
If I right click a line or selection in code-server, there is 'Share' > 'Copy vscode.dev Link'.
But the link goes to vscode.dev (as promised). It looks like it uses git info to build the link (I'm testing with a project from Github).
Can it be patched to work within code-server without going to vscode.dev?
It might be possible but we would have to look into this. Help is welcome!
Did some spelunking into the VSCode codebase, and it seems like this functionality is already available OOB!
To open /foo/bar
in the folder /foo
:
/?folder=/foo&payload=[["openFile","vscode-remote:///foo/bar"]]
To open /foo/bar
at line 1, column 1, in the folder /foo
:
/?folder=/foo&payload=[["gotoLineMode","true"],["openFile","vscode-remote:///foo/bar:1:1"]]
This also works for workspaces specified via workspace
(as opposed to folder
).
References:
payload
param, which seems to be a Map serialized as string pairs.Good find @sleexyz! I'll have to get back to trying this again soon
Nice find!!
Thank you, this works beautifully for my use case.
@sleexyz when I try this, it opens an empty file at that location, even if there is already a file there I can even open the original file side-by-side with it But then if I hit command-S, it overwrites the original file with the empty version
So, I'm pretty sure that I have the right URL, and it's not just opening the empty file in a random location. Any ideas for troubleshooting? Or more general advice for finding answers in the VS Code source since code-server
's documentation is so sparse?
thanks for the find @sleexyz . This really helps. Now the ultimate dream would be a copy link button.
In case somone is interested, why I need that: My use case is that I have a jupyter notebook and I link to code examples from my knowledgebase.
@hoffm386 Sorry for the lack of a response but I hope late is better than never. code-server does not document much of VS Code, for that VS Code's own documentation is probably a better bet, wherever that might be if they even have it; I have had the most luck just reading through the source code and adding logging statements or stepping through. For this kind of thing, since it is native VS Code functionality, code-server is actually not even necessary, you can just run their web stuff directly, which can be more effective since it narrows the search scope.
@itsamemarkus If you frame it as a feature request to Codespaces, you could try submitting it upstream to https://github.com/microsoft/vscode. If it gains enough traction they might implement. Sounds like a cool idea.
- Where query para
Did some spelunking into the VSCode codebase, and it seems like this functionality is already available OOB!
To open
/foo/bar
in the folder/foo
:/?folder=/foo&payload=[["openFile","vscode-remote:///foo/bar"]]
To open
/foo/bar
at line 1, column 1, in the folder/foo
:/?folder=/foo&payload=[["gotoLineMode","true"],["openFile","vscode-remote:///foo/bar:1:1"]]
This also works for workspaces specified via
workspace
(as opposed tofolder
).References:
Where query params seems to be handled: https://github.com/microsoft/vscode/blob/426ecc23472bc88ed7cab45ed0e72be1476b0585/src/vs/code/browser/workbench/workbench.ts#L291
- There is this
payload
param, which seems to be a Map serialized as string pairs.- Mentions of opening files from payload: https://github.com/microsoft/vscode/blob/426ecc23472bc88ed7cab45ed0e72be1476b0585/src/vs/workbench/services/host/browser/browserHostService.ts#L343
- URIs seem to be transformed via https://github.com/microsoft/vscode/blob/426ecc23472bc88ed7cab45ed0e72be1476b0585/src/vs/workbench/api/node/uriTransformer.ts
Anyway to open a github repo automatically (clone) via url like https://code.visualstudio.com/docs/editor/vscode-web#_github-repos
Anyway to open a github repo automatically (clone) via url like https://code.visualstudio.com/docs/editor/vscode-web#_github-repos
No, this is not currently possible with code-server, as far as I know. There might be an extension that does it; it would probably more sense to implement in an extension or in VS Code core than code-server.
Anyway to open a github repo automatically (clone) via url like https://code.visualstudio.com/docs/editor/vscode-web#_github-repos
No, this is not currently possible with code-server, as far as I know. There might be an extension that does it; it would probably more sense to implement in an extension or in VS Code core than code-server.
For sure I understand, tbf this is in *vscode core there is an extension that goes most the way
Visual Studio Code
vscode://robertohuertasm.open-vscode?repo=licensebat&uri=https://github.com/licensebat/licensebat.git&ref=6ec2f28d98d61f8d56cabeb5028abcd432f5bf41&file=licensebat-cli/src/cli.rs&range=17:5
# Visual Studio Code Insiders
vscode-insiders://robertohuertasm.open-vscode?repo=licensebat&uri=https://github.com/licensebat/licensebat.git&ref=6ec2f28d98d61f8d56cabeb5028abcd432f5bf41&file=licensebat-cli/src/cli.rs&range=17:5
# VSCodium
vscodium://robertohuertasm.open-vscode?repo=licensebat&uri=https://github.com/licensebat/licensebat.git&ref=6ec2f28d98d61f8d56cabeb5028abcd432f5bf41&file=licensebat-cli/src/cli.rs&range=17:5
I managed to adjust the manifest of code-server to handle custom protocols, I'm looking at just adding a server route to code-server to listen and handle. Will see how far I get :)
for reference:
{
"name": "code-server",
"short_name": "code-server",
...
"protocol_handlers": [
{
"protocol": "web+coder",
"url": "/robertohuertasm.open-vscode?%s"
},
{
"protocol": "web+codey",
"url": "/openRepo/https://github.com/robertohuertasm/vscode-open?branch=master&%s"
}
],
...
}
That seems promising!! Definitely interested in seeing what you come up with.
We're trying to setup a online developmenr environment for our users - and are trying code-server.
We're using it for static HTML pages for website development, and I was hoping to add a button on the HTML pages which says "Edit this page on code-server".
I was hoping to setup that up, I could provide the path / URL to code-server ... something like:
mycodeserver.domain.com/?file=project/README.md
And it would open that particular file in the code-server when the button is clicked..I couldn't find any documentation or notes about whether this is possible right now
NOTE: I did see https://github.com/cdr/code-server/issues/1960 - but it didn't seem the similar
Edit: Should also support line and column syntax, for example:
http://code-server:port/path=/dir/sub/file.ext:line:col