-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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.findFiles and WorkspaceFolder.uri inconsistency regarding Windows driver letter #194692
Comments
I just noticed that console.log(vscode.Uri.joinPath(workspaceUri, ['multiComponents']))
// d:/a/asciidoctor-vscode/asciidoctor-vscode/test-workspace/multicomponents Is that expected? |
Regarding my last comment, it seems related to: nodejs/node-v0.x-archive#7031 since VS Code is using https://github.com/microsoft/vscode-uri (which relies on posix path):
|
The URI implementation preserves the case of the path component, a normalized variant is being offered via Tho, I wonder why this is needed or how this came up? @ggrossetie Do you use |
I'm using I read somewhere that paths should only be compared after calling As an alternative, the URI module could provide functions to compare URIs (which will be case-insensitive on Windows). |
In summary, the following function does the right thing (i.e., it preserves the case of the path component): console.log(vscode.workspace.workspaceFolders[0].uri.path)
// /D:/a/asciidoctor-vscode/asciidoctor-vscode/test-workspace The following function normalizes Windows drive letter to lowercase: console.log((await vscode.workspace.findFiles('**/antora.yml')).map((uri) => uri.path)
// /d:/a/asciidoctor-vscode/asciidoctor-vscode/test-workspace/antora.yml In my opinion, The following function normalizes path segments: console.log(vscode.Uri.joinPath(workspaceUri, ['multiComponents']))
// /d:/a/asciidoctor-vscode/asciidoctor-vscode/test-workspace/multicomponents I think it would be better to preserve case on path segments. |
It's worth noting that I can reproduce this issue on GitHub Actions but on my local machine (where my drive is C:) I get lowercase c: when calling |
Are you brave enough now? 😉 |
The following function returns the driver letter as is: vscode.workspace.getWorkspaceFolder() Since the Windows driver letter is already in lowercase in other parts or the API, I think it would be great if the Windows driver letter returned by In the meantime, I will use a wrapper around the import vscode, { Uri, WorkspaceFolder } from 'vscode'
import os from 'os'
export function getWorkspaceFolder (uri: Uri): WorkspaceFolder | undefined {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri)
if (workspaceFolder && os.platform() === 'win32') {
return {
uri: workspaceFolder.uri.with({ path: workspaceFolder.uri.path.replace(/^\/([A-Z]):.*/, (driverLetter) => driverLetter.toLowerCase()) }),
name: workspaceFolder.name,
index: workspaceFolder.index,
}
}
return workspaceFolder
} |
@andreamah How and where does search construct its result uris? Do you use the uri identify service and do you create uri from absolute (file) paths or does rg return relative paths that you join with some uri? |
@ggrossetie Fiddling with the drive letter casing will only help you so much. All parts of the path can be in funny and expected casings and that's totally valid (wrt the OS). What we try to do is that the first appearance of an uri defines its shape and latter appearances are normalised to that. However, it only works with full uris and not containment, e.g |
We seem to join a path from rg to another root URI. vscode/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts Lines 256 to 257 in af0f039
I believe that these root URIs source all the way back here:
So I use |
@andreamah I believe this is the bug
The |
…rding Windows driver letter Fixes #194692
Thanks @andreamah and @jrieken 🤗 |
andreamah/issue194692 |
This bug has been fixed in the latest release of VS Code Insiders! @ggrossetie, you can help us out by commenting If things still don't seem right, please ensure you're on version 1091f68 of Insiders (today's or later - you can use Happy Coding! |
Does this issue occur when all extensions are disabled?: Yes
Steps to Reproduce:
Calling
.path
onWorkspaceFolder.uri
returns the Windows drive letter "as is" (in my case, the drive letter is uppercase). For instance:However,
vscode.workspace.findFiles
returns a list of URI with the Windows drive letter as lowercase. For instance:Windows is case-insensitive but I think it would be better to return normalized URIs (or at least return a consistent value across APIs)
The text was updated successfully, but these errors were encountered: