-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
vscode.workspace.getWorkspaceFolder(file)
don't return workspace folder when file open from command line.
#36221
Comments
How to open a file in a workspace with a command line? |
vscode.workspace.getWorkspaceFolder(file)
don't return workspace folder when file open from command line.vscode.workspace.getWorkspaceFolder(file)
don't return workspace folder when file open from command line.
On linux I don`t have this problem:
|
On another computer I update extension and run in Code 1.16.1 then
|
I don't believe that opens a workspace but just the file. cc @bpasero to confirm |
And then |
That isn't what we call a workspace, but a folder. A workspace is one or many folders that are being opened and a workspace is stored a |
Thank you for your interest
The problem no longer exists in version 1.18.0-instider. I believe it will be in the final version. NOTE: It's only problem for file open from outside VSC (command line and also opened from Windows explorer). For file opened from visual studio code panel it`s work fine. |
It's not full available but |
Yes, a workspace file will only be opened if the extension is |
Like @MarekLew say, this bug is only present in code 1.17.1 (In 1.18.0-Insider, it works fine) I use vscode.workspace.getWorkspaceFolder(uri) to prepare Multi-root workspace implementation, With this bug, I'll add temporary a piece of code like that:
|
Still not sure about this. I have an extension that this and it behaves the same on master/insiders and 1.17.2 which is: print undefined when just a file has been opened and print the folder when a folder (no workspace) has been opened. vscode.window.onDidChangeActiveTextEditor(e => {
if (e) {
const folder = vscode.workspace.getWorkspaceFolder(e.document.uri);
console.log(folder);
}
}) Maybe this is an issue about how/when a folder is getting opened even though you specified a file on the command line? |
I use the same code to test... Structure:
I quite often use vscode through a command line, to switch from another program (ide+poor editor) to vscode (a great editor). |
I found problem ( tested only for code 1.17.2 windows 10) File object(
Uppercase letter of the disk! It's not only problem for file opened from comand line. File create in VSC |
So to have the right case, a temporary workaround could be: |
Wow, that is interesting. Thanks for the investigation! |
I have pushed a test to ensure this behaviour is correct. Closing we don't ship 1.17.3 because of this (multi root support will only become "official" with 1.18). Thanks again |
On finally visual studio code 1.18 (windows 10) |
Steps to Reproduce:
local-history
extensioncode .
)echo xxx>a.txt
code a.txt
.history
folderA debug extension and in
history.serring.js:15
functiongetWorkspaceFolder
return None
, when file never open fromexplorer bar
.If file open form command line then
getWorkspaceFolder
return None
.If file open explorer(VSC) then
getWorkspaceFolder
return workspace folderReproduces without extensions: No
The text was updated successfully, but these errors were encountered: