code-server
code-server copied to clipboard
[Bug]: code-server ignores path argument and always opens last location
Is there an existing issue for this?
- [X] I have searched the existing issues
OS/Web Information
- Web Browser: Chrome
- Local OS: macOS
- Remote OS: Linux
- Remote Architecture: amd64
code-server --version: 4.2.0 693b1fac04524bb0e0cfbb93afc85702263329bb with Code 1.64.2
Steps to Reproduce
- open code-server on directory foo:
code-server /path/to/project/foo - close/kill/stop code-server
- open code-server on directory bar:
code-server /some/other/path/bar
Expected
For code-server to run with the project base in /some/other/path/bar.
Actual
code-server runs with the project base /path/to/project/foo
Logs
No response
Screenshot/Video
No response
Does this issue happen in VS Code?
- [X] I cannot reproduce this in VS Code.
Are you accessing code-server over HTTPS?
- [X] I am using HTTPS.
Notes
This has worked fine until recently.
Using over SSH tunnel, NOT HTTPS.
Can you please upgrade to 4.4.0 and see if the issue persists?
I just upgraded to 4.4.0 and tested and got the same result.
I was able to reproduce this. I can't get it to take my path argument.
Video
https://user-images.githubusercontent.com/3806031/168136825-329b20af-7328-4ec1-b0a5-48899ff17ae6.mov
Just upgraded to v4.5.0 and still have this problem.
I was able to reproduce this. I can't get it to take my path argument.
That's because this hasn't ben fixed yet. Hoping we can get to this soon.
I believe this is as designed; code-server will prefer the last opened directory to whatever is passed on the command line.
This behavior can be prevented with --ignore-last-opened to always open the directory passed on the command line. Let us know if that works for you!
I believe this is as designed; code-server will prefer the last opened directory to whatever is passed on the command line.
This behavior can be prevented with
--ignore-last-openedto always open the directory passed on the command line. Let us know if that works for you!
@code-asher This is not the behavior of older versions of code-sever. Additionally if that is the case, then why does code-server even take a path at all?
I think that if a path is provided, code-server should use it. If no path is provided, then defaulting to the last used path is desirable. But ignoring a path the user intentionally provided seems undesirable.
Thanks for letting me know about the --ignore-last-opened flag. That, at least temporarily, does provide the desired behavior.
Oh yeah you are right I had the same thoughts which is the reason we initially implemented it such that the path was preferred. I originally wrote in this issue:
[...] if you explicitly call code-server it'll favor the last directory instead of whatever you passed on the command line. It feels unexpected to me [...]
I was going back and forth on it for a bit since code-server was intended to be ran as a long-lived server process via systemd or something like that and not spawned manually with different paths but ultimately we decided to prefer the path over the last opened.
Today though the path acts as a default directory for when there is not yet any last opened directory (to answer the question of why it still takes a path) and --ignore-last-opened can be used to revert to the old behavior.
This default directory behavior is useful but we could have instead implemented this with a --fallback-directory or something which I think would have made more sense. I am not sure why we went with the implementation we did.
So looking at the commit history I think this happened during the switch to upstream's server. Upstream's implementation was preferring the last opened over the provided path so that naturally became our default as well. That makes sense since I did not recall explicitly changing this behavior. Eventually we had to move the implementation back to our side (theirs did not work so we had to re-implement it) which is why I was remembering the current behavior.
This happened during a major version bump so I guess that panned out; changing it at this point seems like it might be risky if users are depending on the current behavior unless we major bump. If we had realized the implementation was different we could have changed it then but I think I had forgotten until now it used to be another way (probably we were just porting the upstream implementation and not really thinking too deeply about it).
I'm currently having problems with this on version 4.5.1. Currently, we have an app for codeserver to be used on HPC systems, where a user selects a path in a form and launches their own codeserver in a container to work in.
This workflow seems to be at odds with the intended design that I'm reading in this issue though, where codeserver instead is used as a long lived process to open many paths from(?), if I'm understanding correctly.
Trying to add the --ignore-last-opened in the script where codeserver is called also is not fixing the issue for me when the script runs as it still doesn't actually load the user's provided path.
Any ideas how to get the 4.5.1 version to just take the path I give it and not the behavior of loading a cached directory (where does it actually get this?)?
Is there a version that fixes this issue and works with a passed path?
If not, does that mean users would need to launch codeserver going forward and then within the app select the path they want to work in?
I was looking through the release notes to see when that might have changed after 4.5.1 but couldn't find anything.
I'm on 4.8.2 and when I launch code-server --ignore-last-opened it loads an empty window.
When I launch code-server ./dev/coder/code-server it opens that folder:
The other thing you can do is use the query parameter: https://localhost:8080/?folder=/Users/jp/dev/coder
Thanks @jsjoeio
My requirement at the moment was 4.5. However, if it's the case that this behavior is in fact broken in 4.5 and fixed by 4.8 I can put the request in to use that version instead. Is that correct that passing a path will have it load correctly on 4.8?
In 4.5 this does not work, and while passing the --ignore-last-opened does launch an empty window, this breaks the functionality of the user selecting the working directory in the form they are shown, and instead relies on the user understanding how to navigate to the correct location within codeserver which is not ideal for the users across all the institutions using this.
My requirement at the moment was 4.5. However, if it's the case that this behavior is in fact broken in 4.5 and fixed by 4.8 I can put the request in to use that version instead. Is that correct that passing a path will have it load correctly on 4.8?
Yes! 4.8.2 should have the behavior you're looking for then