-
-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lsp): use home directory as working directory #3649
Conversation
CodSpeed Performance ReportMerging #3649 will improve performances by 6.5%Comparing Summary
Benchmarks breakdown
|
Is it possible to set the working directory to the parent folder of the file?
So if I open vscode with (that way |
It should, but unfortunately the LSP client doesn't provide such information, and the LSP server alone can't know which one is the working directory |
I don't know how it actually works - but can't the vscode extension pass the path itself? this doesn't really feel like a real fix :/ |
I think this might have potential to get fixed in biomejs/biome-vscode#200
|
Indeed. The extension will create a dedicated LSP session where the parent folder of the file opened in single-file mode will be considered the root. This however may not necessarily be true for other LSP clients |
Ok, that's fair. I removed it. However we should agree that the bug you filed and the "global/user configuration" are different :) |
@ematipico, does |
Yeah,
But that's the actual bug 😅 When VSCode is opened with a single file using the CLI Ironically, zed behaves differently, and when I call |
Ah sorry I wasn't super clear. In the current version of the extension we don't set a custom cwd which may explain why we get /. In v3 I'm explicitly passing the root of a project folder as the cwd. I'll do some tests later to confirm my doubts |
Oh, awesome! I am happy to hold off this PR then :) |
So this PR will just alter what happens in an edge case where the lsp client doesn't pass If so then I'm not sure if this is needed, isn't it the lsp's client job to provide the directory? and if it doesn't then it probably indicates a bug in the lsp client implementation? I don't think a user would expect the home directory to be used as CWD IMO it should be an error for the lsp client not to pass a directory to work with, unless I'm missing something @nhedger in v3 if I open vscode with nothing open, then create a new untitled file - will biome work? and if it will then what will be the cwd passed to the lsp server? |
I don't think there's a spec for this case, so I am unsure if it's a VSCode bug, but it's possible. I'll update the PR to use |
Feels weird, I wonder why that is… handling unsaved untitled files? Maybe it shouldn't be optional - which would make lsp client implementation have to resolve that issue themselves
isn't |
Yes. The extension will create a global LSP session, but no working directory will be set explicitly. I'm assuming it would default to / in that case. |
In this case, I propose that the lsp server and cli app should both default to the user directory if no config was found lsp server would do it if the lsp client decides it (untitled unsaved files, custom workspace option, etc) cli would do it if no config was found (in any parent dir) or if some kind of cli option was set ( and then Biome could clearly state this in the documentation and effectively allow global configuration
|
It's part of the LSP spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize |
Summary
Closes #2772
The original issue was triggered when a single file was opened by a single client. When this occurs, the client can't pass
rootUri
orworkspaceFolders
. When this happens, the working directory becomesenv::current_dir()
, which is the/
in this particular case.In this PR I refactored the code, and before falling back to
env::current_dir()
, we attempt to retrieve the home directory of the user, and use that one as working directory.Test Plan
I manually tested the feature using a local project