diff --git a/src/vs/base/common/labels.ts b/src/vs/base/common/labels.ts index 1a9cb36b9a3f..e869e52c6a3a 100644 --- a/src/vs/base/common/labels.ts +++ b/src/vs/base/common/labels.ts @@ -78,8 +78,23 @@ export function getPathLabel(resource: URI, formatting: IPathLabelFormatting): s } } + // we need to get at the file path of the resource but in a way + // that preserves platform separators. By default, `URI.fsPath` + // will convert separators without allowing to control this from + // the outside. But we cannot just use `URI.path` because that + // might miss a authority that can be present. + // As such our strategy is to: + // - use `fsPath` to preserve authority + // - convert separators based on OS accordingly + let path = resource.fsPath; + if (os === OperatingSystem.Windows) { + path = path.replace(/\//g, '\\'); + } else { + path = path.replace(/\\/g, '/'); + } + // normalize - let res = pathLib.normalize(resource.fsPath); + let res = pathLib.normalize(path); // Windows: normalize drive letter res = normalizeDriveLetter(res, os === OperatingSystem.Windows); diff --git a/src/vs/workbench/services/label/common/labelService.ts b/src/vs/workbench/services/label/common/labelService.ts index 3c93b022ec5a..bb2c13070815 100644 --- a/src/vs/workbench/services/label/common/labelService.ts +++ b/src/vs/workbench/services/label/common/labelService.ts @@ -177,10 +177,11 @@ export class LabelService extends Disposable implements ILabelService { if (!formatting) { // Without a formatter we have to fallback to figuring out what the - // label could be given the environment. For that we convert the - // given resource to the default scheme and remote authority that - // is present in an attempt to e.g. resolve a proper relative path - // if that is needed. + // label could be that best matches the environment and workspace + // the user is in. + // As such, we convert the given resource to the default scheme and + // remote authority that is present in an attempt to e.g. resolve a + // proper relative path if that is needed. const defaultResource = toLocalResource(resource, this.environmentService.remoteAuthority, this.pathService.defaultUriScheme);