diff --git a/src/vs/workbench/services/label/common/labelService.ts b/src/vs/workbench/services/label/common/labelService.ts index 78fb342c331..cb7100587c8 100644 --- a/src/vs/workbench/services/label/common/labelService.ts +++ b/src/vs/workbench/services/label/common/labelService.ts @@ -10,9 +10,9 @@ import * as paths from 'vs/base/common/path'; import { Emitter } from 'vs/base/common/event'; import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { Registry } from 'vs/platform/registry/common/platform'; -import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkspaceContextService, IWorkspace, isWorkspace, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier, toWorkspaceIdentifier, WORKSPACE_EXTENSION, isUntitledWorkspace, isTemporaryWorkspace } from 'vs/platform/workspace/common/workspace'; -import { basenameOrAuthority, basename, joinPath, dirname } from 'vs/base/common/resources'; +import { basenameOrAuthority, basename, joinPath, dirname, toLocalResource } from 'vs/base/common/resources'; import { tildify, getPathLabel } from 'vs/base/common/labels'; import { ILabelService, ResourceLabelFormatter, ResourceLabelFormatting, IFormatterChangeEvent } from 'vs/platform/label/common/label'; import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry'; @@ -107,7 +107,7 @@ export class LabelService extends Disposable implements ILabelService { readonly onDidChangeFormatters = this._onDidChangeFormatters.event; constructor( - @IEnvironmentService private readonly environmentService: IEnvironmentService, + @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, @IPathService private readonly pathService: IPathService ) { @@ -156,7 +156,16 @@ export class LabelService extends Disposable implements ILabelService { private doGetUriLabel(resource: URI, formatting?: ResourceLabelFormatting, options: { relative?: boolean; noPrefix?: boolean; endWithSeparator?: boolean } = {}): string { if (!formatting) { - return getPathLabel(resource, { userHome: this.pathService.resolvedUserHome }, options.relative ? this.contextService : undefined); + + // 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. + + const defaultResource = toLocalResource(resource, this.environmentService.remoteAuthority, this.pathService.defaultUriScheme); + + return getPathLabel(defaultResource, { userHome: this.pathService.resolvedUserHome }, options.relative ? this.contextService : undefined); } let label: string | undefined; diff --git a/src/vs/workbench/services/label/test/browser/label.test.ts b/src/vs/workbench/services/label/test/browser/label.test.ts index fd625cd763c..ea4f1bdead0 100644 --- a/src/vs/workbench/services/label/test/browser/label.test.ts +++ b/src/vs/workbench/services/label/test/browser/label.test.ts @@ -260,7 +260,7 @@ suite('multi-root workspace', () => { new Workspace('test-workspace', [ new WorkspaceFolder({ uri: rootFolder, index: 0, name: 'FSProotFolder' }), ])), - new TestPathService()); + new TestPathService(undefined, rootFolder.scheme)); const generated = labelService.getUriLabel(URI.parse('myscheme://myauthority/some/folder/test.txt'), { relative: true }); if (isWindows) { diff --git a/src/vs/workbench/services/workingCopy/test/browser/fileWorkingCopyManager.test.ts b/src/vs/workbench/services/workingCopy/test/browser/fileWorkingCopyManager.test.ts index 157a36e5cdd..307ed8eb379 100644 --- a/src/vs/workbench/services/workingCopy/test/browser/fileWorkingCopyManager.test.ts +++ b/src/vs/workbench/services/workingCopy/test/browser/fileWorkingCopyManager.test.ts @@ -247,7 +247,7 @@ suite('FileWorkingCopyManager', () => { const workingCopy = await manager.resolve({ associatedResource: { path: '/some/associated.txt' } }); workingCopy.model?.updateContents('Simple Save As with associated resource'); - const target = URI.from({ scheme: Schemas.vscodeRemote, path: '/some/associated.txt' }); + const target = URI.from({ scheme: Schemas.file, path: '/some/associated.txt' }); accessor.fileService.notExistsSet.set(target, true); diff --git a/src/vs/workbench/services/workingCopy/test/browser/untitledFileWorkingCopyManager.test.ts b/src/vs/workbench/services/workingCopy/test/browser/untitledFileWorkingCopyManager.test.ts index e37181dafe7..69f8c133efc 100644 --- a/src/vs/workbench/services/workingCopy/test/browser/untitledFileWorkingCopyManager.test.ts +++ b/src/vs/workbench/services/workingCopy/test/browser/untitledFileWorkingCopyManager.test.ts @@ -226,7 +226,7 @@ suite('UntitledFileWorkingCopyManager', () => { const workingCopy = await manager.untitled.resolve({ associatedResource: { path: '/some/associated.txt' } }); workingCopy.model?.updateContents('Simple Save with associated resource'); - accessor.fileService.notExistsSet.set(URI.from({ scheme: Schemas.vscodeRemote, path: '/some/associated.txt' }), true); + accessor.fileService.notExistsSet.set(URI.from({ scheme: Schemas.file, path: '/some/associated.txt' }), true); const result = await workingCopy.save(); assert.ok(result); diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index b4690df3ec9..e006fbc7187 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -1677,7 +1677,7 @@ export class TestPathService implements IPathService { declare readonly _serviceBrand: undefined; - constructor(private readonly fallbackUserHome: URI = URI.from({ scheme: Schemas.vscodeRemote, path: '/' }), public defaultUriScheme = Schemas.vscodeRemote) { } + constructor(private readonly fallbackUserHome: URI = URI.from({ scheme: Schemas.file, path: '/' }), public defaultUriScheme = Schemas.file) { } hasValidBasename(resource: URI, basename?: string): Promise; hasValidBasename(resource: URI, os: OperatingSystem, basename?: string): boolean;