diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index f899de2f910..c6f9e804869 100644 --- a/src/vs/platform/environment/common/environment.ts +++ b/src/vs/platform/environment/common/environment.ts @@ -36,6 +36,10 @@ export interface IEnvironmentService { argvResource: URI; snippetsHome: URI; + // --- data paths + backupHome: URI; + untitledWorkspacesHome: URI; + // --- settings sync userDataSyncLogResource: URI; userDataSyncHome: URI; @@ -56,20 +60,10 @@ export interface IEnvironmentService { verbose: boolean; isBuilt: boolean; - // --- data paths - backupHome: URI; - untitledWorkspacesHome: URI; - // --- misc disableTelemetry: boolean; - serviceMachineIdResource: URI; - /** - * @deprecated use IRemotePathService#userHome instead (https://github.com/microsoft/vscode/issues/94506) - */ - userHome?: URI; - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // NOTE: DO NOT ADD ANY OTHER PROPERTY INTO THE COLLECTION HERE // UNLESS THIS PROPERTY IS SUPPORTED BOTH IN WEB AND DESKTOP!!!! diff --git a/src/vs/workbench/contrib/debug/browser/linkDetector.ts b/src/vs/workbench/contrib/debug/browser/linkDetector.ts index 4319d66031c..32b3f73ec44 100644 --- a/src/vs/workbench/contrib/debug/browser/linkDetector.ts +++ b/src/vs/workbench/contrib/debug/browser/linkDetector.ts @@ -120,7 +120,7 @@ export class LinkDetector { } if (path[0] === '~') { - const userHome = this.remotePathService.userHomeSync; + const userHome = this.remotePathService.resolvedUserHome; if (userHome) { path = osPath.join(userHome.fsPath, path.substring(1)); } diff --git a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts index 286099ff89a..700f7e611c8 100644 --- a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts +++ b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts @@ -347,7 +347,7 @@ class SessionTreeItem extends BaseTreeItem { } else { // on unix try to tildify absolute paths path = normalize(path); - const userHome = this._remotePathService.userHomeSync; + const userHome = this._remotePathService.resolvedUserHome; if (userHome && !isWindows) { path = tildify(path, userHome.fsPath); } diff --git a/src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts b/src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts index 717e3d4139b..753a608da79 100644 --- a/src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts +++ b/src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts @@ -631,7 +631,8 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider { - this._userHome = userHome; - }); } - private _userHome: URI | undefined; - text(contentPattern: IPatternInfo, folderResources?: uri[], options: ITextQueryBuilderOptions = {}): ITextQuery { contentPattern = this.getContentPattern(contentPattern, options); const searchConfig = this.configurationService.getValue(); @@ -244,8 +239,9 @@ export class QueryBuilder { const segments = splitGlobPattern(pattern) .map(segment => { - if (this._userHome) { - return untildify(segment, this._userHome.fsPath); + const userHome = this.remotePathService.resolvedUserHome; + if (userHome) { + return untildify(segment, userHome.scheme === Schemas.file ? userHome.fsPath : userHome.path); } return segment; diff --git a/src/vs/workbench/contrib/search/test/browser/queryBuilder.test.ts b/src/vs/workbench/contrib/search/test/browser/queryBuilder.test.ts index cc8f788f891..27104feb755 100644 --- a/src/vs/workbench/contrib/search/test/browser/queryBuilder.test.ts +++ b/src/vs/workbench/contrib/search/test/browser/queryBuilder.test.ts @@ -50,7 +50,7 @@ suite('QueryBuilder', () => { instantiationService.stub(IWorkspaceContextService, mockContextService); instantiationService.stub(IEnvironmentService, TestEnvironmentService); - instantiationService.stub(IRemotePathService, new TestRemotePathService(TestEnvironmentService)); + instantiationService.stub(IRemotePathService, new TestRemotePathService()); queryBuilder = instantiationService.createInstance(QueryBuilder); }); diff --git a/src/vs/workbench/contrib/search/test/electron-browser/queryBuilder.test.ts b/src/vs/workbench/contrib/search/test/electron-browser/queryBuilder.test.ts index bc60138cbbc..9a4980f43f0 100644 --- a/src/vs/workbench/contrib/search/test/electron-browser/queryBuilder.test.ts +++ b/src/vs/workbench/contrib/search/test/electron-browser/queryBuilder.test.ts @@ -8,10 +8,9 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { IWorkspaceContextService, toWorkspaceFolder, Workspace } from 'vs/platform/workspace/common/workspace'; import { ISearchPathsInfo, QueryBuilder } from 'vs/workbench/contrib/search/common/queryBuilder'; -import { TestEnvironmentService } from 'vs/workbench/test/electron-browser/workbenchTestServices'; +import { TestEnvironmentService, TestNativeRemotePathService } from 'vs/workbench/test/electron-browser/workbenchTestServices'; import { assertEqualSearchPathResults, getUri, patternsToIExpression, globalGlob, fixPath } from 'vs/workbench/contrib/search/test/browser/queryBuilder.test'; import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices'; -import { TestRemotePathService } from 'vs/workbench/test/browser/workbenchTestServices'; import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService'; const DEFAULT_EDITOR_CONFIG = {}; @@ -41,7 +40,7 @@ suite('QueryBuilder', () => { instantiationService.stub(IWorkspaceContextService, mockContextService); instantiationService.stub(IEnvironmentService, TestEnvironmentService); - instantiationService.stub(IRemotePathService, new TestRemotePathService(TestEnvironmentService)); + instantiationService.stub(IRemotePathService, new TestNativeRemotePathService(TestEnvironmentService)); queryBuilder = instantiationService.createInstance(QueryBuilder); await new Promise(resolve => setTimeout(resolve, 5)); // Wait for RemotePathService.userHome to resolve diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index 2d67cee7dfa..e023fe1b214 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -135,9 +135,9 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce const hasRemoteAuthority = !!this.remoteAuthority; let launchRemotely = hasRemoteAuthority || forceExtHostProcess; - // userHomeSync is needed here as remote resolvers can launch local terminals before + // resolvedUserHome is needed here as remote resolvers can launch local terminals before // they're connected to the remote. - this.userHome = this._remotePathService.userHomeSync?.fsPath; + this.userHome = this._remotePathService.resolvedUserHome?.fsPath; this.os = platform.OS; if (launchRemotely) { const userHomeUri = await this._remotePathService.userHome; diff --git a/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkManager.test.ts b/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkManager.test.ts index ad7fd6a94e6..5662066333d 100644 --- a/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkManager.test.ts +++ b/src/vs/workbench/contrib/terminal/test/browser/links/terminalLinkManager.test.ts @@ -93,7 +93,7 @@ suite('Workbench - TerminalLinkHandler', () => { setup(() => { instantiationService = new TestInstantiationService(); instantiationService.stub(IEnvironmentService, TestEnvironmentService); - instantiationService.stub(IRemotePathService, new TestRemotePathService(TestEnvironmentService)); + instantiationService.stub(IRemotePathService, new TestRemotePathService()); }); suite('localLinkRegex', () => { diff --git a/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts b/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts index eb501abe939..5ef56f5c844 100644 --- a/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts +++ b/src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts @@ -38,7 +38,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor import { KeybindingsEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService'; -import { TestBackupFileService, TestEditorGroupsService, TestEditorService, TestLifecycleService } from 'vs/workbench/test/browser/workbenchTestServices'; +import { TestBackupFileService, TestEditorGroupsService, TestEditorService, TestLifecycleService, TestRemotePathService } from 'vs/workbench/test/browser/workbenchTestServices'; import { FileService } from 'vs/platform/files/common/fileService'; import { Schemas } from 'vs/base/common/network'; import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider'; @@ -57,6 +57,7 @@ import { UndoRedoService } from 'vs/platform/undoRedo/common/undoRedoService'; import { TestTextResourcePropertiesService, TestContextService, TestWorkingCopyService } from 'vs/workbench/test/common/workbenchTestServices'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; +import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService'; class TestEnvironmentService extends NativeWorkbenchEnvironmentService { @@ -93,6 +94,7 @@ suite('KeybindingsEditing', () => { configService.setUserConfiguration('files', { 'eol': '\n' }); instantiationService.stub(IEnvironmentService, environmentService); + instantiationService.stub(IRemotePathService, new TestRemotePathService()); instantiationService.stub(IConfigurationService, configService); instantiationService.stub(IWorkspaceContextService, new TestContextService()); const lifecycleService = new TestLifecycleService(); diff --git a/src/vs/workbench/services/label/common/labelService.ts b/src/vs/workbench/services/label/common/labelService.ts index 74d17900862..3200d718844 100644 --- a/src/vs/workbench/services/label/common/labelService.ts +++ b/src/vs/workbench/services/label/common/labelService.ts @@ -135,7 +135,7 @@ 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.path, this.environmentService, options.relative ? this.contextService : undefined); + return getPathLabel(resource.path, { userHome: this.remotePathService.resolvedUserHome }, options.relative ? this.contextService : undefined); } let label: string | undefined; @@ -266,7 +266,7 @@ export class LabelService extends Disposable implements ILabelService { } if (formatting.tildify && !forceNoTildify) { - const userHome = this.remotePathService.userHomeSync; + const userHome = this.remotePathService.resolvedUserHome; if (userHome) { label = tildify(label, userHome.fsPath); } 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 ddecfd5863b..76370016b78 100644 --- a/src/vs/workbench/services/label/test/browser/label.test.ts +++ b/src/vs/workbench/services/label/test/browser/label.test.ts @@ -5,10 +5,7 @@ import * as assert from 'assert'; import { TestEnvironmentService, TestRemotePathService } from 'vs/workbench/test/browser/workbenchTestServices'; -import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; import { URI } from 'vs/base/common/uri'; -import { sep } from 'vs/base/common/path'; -import { isWindows } from 'vs/base/common/platform'; import { LabelService } from 'vs/workbench/services/label/common/labelService'; import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices'; @@ -17,28 +14,7 @@ suite('URI Label', () => { let labelService: LabelService; setup(() => { - labelService = new LabelService(TestEnvironmentService, new TestContextService(), new TestRemotePathService(TestEnvironmentService)); - }); - - test('file scheme', function () { - labelService.registerFormatter({ - scheme: 'file', - formatting: { - label: '${path}', - separator: sep, - tildify: !isWindows, - normalizeDriveLetter: isWindows - } - }); - - const uri1 = TestWorkspace.folders[0].uri.with({ path: TestWorkspace.folders[0].uri.path.concat('/a/b/c/d') }); - assert.equal(labelService.getUriLabel(uri1, { relative: true }), isWindows ? 'a\\b\\c\\d' : 'a/b/c/d'); - assert.equal(labelService.getUriLabel(uri1, { relative: false }), isWindows ? 'C:\\testWorkspace\\a\\b\\c\\d' : '/testWorkspace/a/b/c/d'); - assert.equal(labelService.getUriBasenameLabel(uri1), 'd'); - - const uri2 = URI.file('c:\\1/2/3'); - assert.equal(labelService.getUriLabel(uri2, { relative: false }), isWindows ? 'C:\\1\\2\\3' : '/c:\\1/2/3'); - assert.equal(labelService.getUriBasenameLabel(uri2), '3'); + labelService = new LabelService(TestEnvironmentService, new TestContextService(), new TestRemotePathService()); }); test('custom scheme', function () { diff --git a/src/vs/workbench/services/label/test/electron-browser/label.test.ts b/src/vs/workbench/services/label/test/electron-browser/label.test.ts new file mode 100644 index 00000000000..ceb122d22a3 --- /dev/null +++ b/src/vs/workbench/services/label/test/electron-browser/label.test.ts @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as assert from 'assert'; +import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; +import { URI } from 'vs/base/common/uri'; +import { sep } from 'vs/base/common/path'; +import { isWindows } from 'vs/base/common/platform'; +import { LabelService } from 'vs/workbench/services/label/common/labelService'; +import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices'; +import { TestNativeRemotePathService, TestEnvironmentService } from 'vs/workbench/test/electron-browser/workbenchTestServices'; + +suite('URI Label', () => { + + let labelService: LabelService; + + setup(() => { + labelService = new LabelService(TestEnvironmentService, new TestContextService(), new TestNativeRemotePathService(TestEnvironmentService)); + }); + + test('file scheme', function () { + labelService.registerFormatter({ + scheme: 'file', + formatting: { + label: '${path}', + separator: sep, + tildify: !isWindows, + normalizeDriveLetter: isWindows + } + }); + + const uri1 = TestWorkspace.folders[0].uri.with({ path: TestWorkspace.folders[0].uri.path.concat('/a/b/c/d') }); + assert.equal(labelService.getUriLabel(uri1, { relative: true }), isWindows ? 'a\\b\\c\\d' : 'a/b/c/d'); + assert.equal(labelService.getUriLabel(uri1, { relative: false }), isWindows ? 'C:\\testWorkspace\\a\\b\\c\\d' : '/testWorkspace/a/b/c/d'); + assert.equal(labelService.getUriBasenameLabel(uri1), 'd'); + + const uri2 = URI.file('c:\\1/2/3'); + assert.equal(labelService.getUriLabel(uri2, { relative: false }), isWindows ? 'C:\\1\\2\\3' : '/c:\\1/2/3'); + assert.equal(labelService.getUriBasenameLabel(uri2), '3'); + }); +}); diff --git a/src/vs/workbench/services/path/browser/remotePathService.ts b/src/vs/workbench/services/path/browser/remotePathService.ts new file mode 100644 index 00000000000..7aeaab0fe7f --- /dev/null +++ b/src/vs/workbench/services/path/browser/remotePathService.ts @@ -0,0 +1,29 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; +import { IRemotePathService, AbstractRemotePathService } from 'vs/workbench/services/path/common/remotePathService'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; +import { URI } from 'vs/base/common/uri'; +import { Schemas } from 'vs/base/common/network'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; + +export class BrowserRemotePathService extends AbstractRemotePathService { + + private static fallbackUserHome(historyService: IHistoryService, environmentService: IWorkbenchEnvironmentService): URI { + return historyService.getLastActiveWorkspaceRoot() || URI.from({ scheme: Schemas.vscodeRemote, authority: environmentService.configuration.remoteAuthority, path: '/' }); + } + + constructor( + @IRemoteAgentService remoteAgentService: IRemoteAgentService, + @IHistoryService historyService: IHistoryService, + @IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService + ) { + super(() => BrowserRemotePathService.fallbackUserHome(historyService, environmentService), remoteAgentService); + } +} + +registerSingleton(IRemotePathService, BrowserRemotePathService, true); diff --git a/src/vs/workbench/services/path/common/remotePathService.ts b/src/vs/workbench/services/path/common/remotePathService.ts index a1e875a0e13..94ea045d7e1 100644 --- a/src/vs/workbench/services/path/common/remotePathService.ts +++ b/src/vs/workbench/services/path/common/remotePathService.ts @@ -3,13 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'vs/base/common/path'; -import * as platform from 'vs/base/common/platform'; +import { IPath, win32, posix } from 'vs/base/common/path'; +import { OperatingSystem, OS } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; -import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; -import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; const REMOTE_PATH_SERVICE_ID = 'remotePath'; export const IRemotePathService = createDecorator(REMOTE_PATH_SERVICE_ID); @@ -21,7 +19,7 @@ export interface IRemotePathService { /** * The path library to use for the target remote environment. */ - readonly path: Promise; + readonly path: Promise; /** * Converts the given path to a file URI in the remote environment. @@ -35,36 +33,50 @@ export interface IRemotePathService { /** * Provides access to the user home of the remote environment - * if defined. + * if defined. The variable will be `undefined` as long as the + * remote environment has not been resolved yet. */ - readonly userHomeSync: URI | undefined; + readonly resolvedUserHome: URI | undefined; } /** * Provides the correct IPath implementation for dealing with paths that refer to locations in the extension host */ -export class RemotePathService implements IRemotePathService { +export abstract class AbstractRemotePathService implements IRemotePathService { + _serviceBrand: undefined; - private _extHostOS: Promise; - private _userHomeSync: URI | undefined; + private remoteOS: Promise; + + private resolveUserHome: Promise; + private maybeUnresolvedUserHome: URI | undefined; constructor( - @IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService, - @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService + fallbackUserHome: () => URI, + @IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService ) { - this._extHostOS = remoteAgentService.getEnvironment().then(remoteEnvironment => { - this._userHomeSync = remoteEnvironment?.userHome; + this.remoteOS = this.remoteAgentService.getEnvironment().then(env => env?.os || OS); - return remoteEnvironment ? remoteEnvironment.os : platform.OS; + this.resolveUserHome = this.remoteAgentService.getEnvironment().then(env => { + const userHome = this.maybeUnresolvedUserHome = env?.userHome || fallbackUserHome(); + + return userHome; }); } - get path(): Promise { - return this._extHostOS.then(os => { - return os === platform.OperatingSystem.Windows ? - path.win32 : - path.posix; + get userHome(): Promise { + return this.resolveUserHome; + } + + get resolvedUserHome(): URI | undefined { + return this.maybeUnresolvedUserHome; + } + + get path(): Promise { + return this.remoteOS.then(os => { + return os === OperatingSystem.Windows ? + win32 : + posix; }); } @@ -74,7 +86,7 @@ export class RemotePathService implements IRemotePathService { // normalize to fwd-slashes on windows, // on other systems bwd-slashes are valid // filename character, eg /f\oo/ba\r.txt - if ((await this._extHostOS) === platform.OperatingSystem.Windows) { + if ((await this.remoteOS) === OperatingSystem.Windows) { _path = _path.replace(/\\/g, '/'); } @@ -100,23 +112,4 @@ export class RemotePathService implements IRemotePathService { fragment: '' }); } - - get userHome(): Promise { - return this.remoteAgentService.getEnvironment().then(env => { - - // remote: use remote environment userHome - if (env) { - return env.userHome; - } - - // local: use the userHome from environment - return this.environmentService.userHome!; - }); - } - - get userHomeSync(): URI | undefined { - return this._userHomeSync || this.environmentService.userHome; - } } - -registerSingleton(IRemotePathService, RemotePathService, true); diff --git a/src/vs/workbench/services/path/electron-browser/remotePathService.ts b/src/vs/workbench/services/path/electron-browser/remotePathService.ts new file mode 100644 index 00000000000..67c74c0b0c9 --- /dev/null +++ b/src/vs/workbench/services/path/electron-browser/remotePathService.ts @@ -0,0 +1,22 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { IRemotePathService, AbstractRemotePathService } from 'vs/workbench/services/path/common/remotePathService'; +import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService'; + +export class NativeRemotePathService extends AbstractRemotePathService { + + constructor( + @IRemoteAgentService remoteAgentService: IRemoteAgentService, + @IWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService + ) { + super(() => environmentService.userHome, remoteAgentService); + } +} + +registerSingleton(IRemotePathService, NativeRemotePathService, true); diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 496550a2491..63f207772b1 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -115,7 +115,10 @@ export interface ITestInstantiationService extends IInstantiationService { stub(service: ServiceIdentifier, ctor: any): T; } -export function workbenchInstantiationService(overrides?: { textFileService?: (instantiationService: IInstantiationService) => ITextFileService }): ITestInstantiationService { +export function workbenchInstantiationService(overrides?: { + textFileService?: (instantiationService: IInstantiationService) => ITextFileService + remotePathService?: (instantiationService: IInstantiationService) => IRemotePathService +}): ITestInstantiationService { const instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()])); instantiationService.stub(IWorkingCopyService, new TestWorkingCopyService()); @@ -131,7 +134,7 @@ export function workbenchInstantiationService(overrides?: { textFileService?: (i instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService)); instantiationService.stub(IUntitledTextEditorService, instantiationService.createInstance(UntitledTextEditorService)); instantiationService.stub(IStorageService, new TestStorageService()); - instantiationService.stub(IRemotePathService, new TestRemotePathService(TestEnvironmentService)); + instantiationService.stub(IRemotePathService, overrides?.remotePathService ? overrides.remotePathService(instantiationService) : new TestRemotePathService()); const layoutService = new TestLayoutService(); instantiationService.stub(IWorkbenchLayoutService, layoutService); instantiationService.stub(IDialogService, new TestDialogService()); @@ -1108,12 +1111,12 @@ export class TestRemotePathService implements IRemotePathService { _serviceBrand: undefined; - constructor(@IWorkbenchEnvironmentService private readonly environmentService: IEnvironmentService) { } + constructor(private readonly fallbackUserHome: URI = URI.from({ scheme: Schemas.vscodeRemote, path: '/' })) { } get path() { return Promise.resolve(isWindows ? win32 : posix); } - get userHome() { return Promise.resolve(this.environmentService.userHome!); } - get userHomeSync() { return this.environmentService.userHome; } + get userHome() { return Promise.resolve(this.fallbackUserHome); } + get resolvedUserHome() { return this.fallbackUserHome; } async fileURI(path: string): Promise { return URI.file(path); diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index 13920be7069..fd17d5c30e3 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { workbenchInstantiationService as browserWorkbenchInstantiationService, ITestInstantiationService, TestLifecycleService, TestFilesConfigurationService, TestFileService, TestFileDialogService } from 'vs/workbench/test/browser/workbenchTestServices'; +import { workbenchInstantiationService as browserWorkbenchInstantiationService, ITestInstantiationService, TestLifecycleService, TestFilesConfigurationService, TestFileService, TestFileDialogService, TestRemotePathService } from 'vs/workbench/test/browser/workbenchTestServices'; import { Event } from 'vs/base/common/event'; import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService'; import { NativeWorkbenchEnvironmentService, INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService'; @@ -219,7 +219,8 @@ export class TestElectronService implements IElectronService { export function workbenchInstantiationService(): ITestInstantiationService { const instantiationService = browserWorkbenchInstantiationService({ - textFileService: insta => insta.createInstance(TestTextFileService) + textFileService: insta => insta.createInstance(TestTextFileService), + remotePathService: insta => insta.createInstance(TestNativeRemotePathService) }); instantiationService.stub(IElectronService, new TestElectronService()); @@ -243,3 +244,12 @@ export class TestServiceAccessor { ) { } } + +export class TestNativeRemotePathService extends TestRemotePathService { + + _serviceBrand: undefined; + + constructor(@IWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService) { + super(environmentService.userHome); + } +} diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index 7288803da97..d8ffd1576f2 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -76,7 +76,6 @@ import 'vs/workbench/services/extensionManagement/common/extensionEnablementServ import 'vs/workbench/services/notification/common/notificationService'; import 'vs/workbench/services/extensions/common/staticExtensions'; import 'vs/workbench/services/userDataSync/common/userDataSyncUtil'; -import 'vs/workbench/services/path/common/remotePathService'; import 'vs/workbench/services/remote/common/remoteExplorerService'; import 'vs/workbench/services/workingCopy/common/workingCopyService'; import 'vs/workbench/services/workingCopy/common/workingCopyFileService'; diff --git a/src/vs/workbench/workbench.desktop.main.ts b/src/vs/workbench/workbench.desktop.main.ts index cdd9d93c1ea..71fa3df99bc 100644 --- a/src/vs/workbench/workbench.desktop.main.ts +++ b/src/vs/workbench/workbench.desktop.main.ts @@ -66,6 +66,7 @@ import 'vs/workbench/services/update/electron-browser/updateService'; import 'vs/workbench/services/issue/electron-browser/issueService'; import 'vs/workbench/services/menubar/electron-browser/menubarService'; import 'vs/workbench/services/extensionResourceLoader/electron-browser/extensionResourceLoaderService'; +import 'vs/workbench/services/path/electron-browser/remotePathService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { ICredentialsService } from 'vs/platform/credentials/common/credentials'; diff --git a/src/vs/workbench/workbench.web.main.ts b/src/vs/workbench/workbench.web.main.ts index 82e9da5652f..ced463bc91e 100644 --- a/src/vs/workbench/workbench.web.main.ts +++ b/src/vs/workbench/workbench.web.main.ts @@ -50,6 +50,7 @@ import 'vs/workbench/services/request/browser/requestService'; import 'vs/workbench/services/lifecycle/browser/lifecycleService'; import 'vs/workbench/services/clipboard/browser/clipboardService'; import 'vs/workbench/services/extensionResourceLoader/browser/extensionResourceLoaderService'; +import 'vs/workbench/services/path/browser/remotePathService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';