* Compute `fsPath` with slash normalized to `/` for the given uri. * * This is what vscode uses internally to compute uri.fsPath; however, * backslash conversion for Windows host is removed, and drive letter is always normalized to uppercase. * * The problems with the internal `uri.fsPath`: *
(uri: Uri)
| 165 | * Modified from https://github.com/microsoft/vscode/blob/f74e473238aca7b79c08be761d99a0232838ca4c/src/vs/base/common/uri.ts#L579-L604 |
| 166 | */ |
| 167 | function uriToFsPath(uri: Uri): string { |
| 168 | let value: string; |
| 169 | if (uri.authority && uri.path.length > 1 && uri.scheme === "file") { |
| 170 | // unc path: file://shares/c$/far/boo |
| 171 | value = `//${uri.authority}${uri.path}`; |
| 172 | } else if ( |
| 173 | // e.g. local file and vscode-remote file |
| 174 | uri.path.charCodeAt(0) === CharCode.Slash && |
| 175 | hasDriveLetter(uri.path, 1) |
| 176 | ) { |
| 177 | // windows drive letter: file:///c:/far/boo |
| 178 | // Normalized drive letter -> C:/far/boo |
| 179 | value = uri.path[1].toUpperCase() + uri.path.substr(2); |
| 180 | } else { |
| 181 | // other path |
| 182 | value = uri.path; |
| 183 | } |
| 184 | return value; |
| 185 | } |
| 186 | |
| 187 | function equalsIgnoreCase(a1: string, a2: string) { |
| 188 | return a1.length === a1.length && a1.toLowerCase() === a2.toLowerCase(); |
no test coverage detected