Skip to content

Commit 5dfa261

Browse files
author
Benjamin Pasero
committed
remote - allow to open files from user home with tilde syntax (microsoft#83213)
1 parent 2d1e215 commit 5dfa261

5 files changed

Lines changed: 34 additions & 36 deletions

File tree

src/vs/workbench/contrib/search/browser/openFileHandler.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { IModeService } from 'vs/editor/common/services/modeService';
2121
import * as nls from 'vs/nls';
2222
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2323
import { IResourceInput } from 'vs/platform/editor/common/editor';
24-
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2524
import { IFileService } from 'vs/platform/files/common/files';
2625
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2726
import { ILabelService } from 'vs/platform/label/common/label';
@@ -121,11 +120,10 @@ export class OpenFileHandler extends QuickOpenHandler {
121120
@IWorkbenchThemeService private readonly themeService: IWorkbenchThemeService,
122121
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
123122
@ISearchService private readonly searchService: ISearchService,
124-
@IEnvironmentService private readonly environmentService: IEnvironmentService,
123+
@IRemotePathService private readonly remotePathService: IRemotePathService,
125124
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService,
126125
@IFileService private readonly fileService: IFileService,
127-
@ILabelService private readonly labelService: ILabelService,
128-
@IRemotePathService private readonly remotePathService: IRemotePathService,
126+
@ILabelService private readonly labelService: ILabelService
129127
) {
130128
super();
131129

@@ -187,11 +185,12 @@ export class OpenFileHandler extends QuickOpenHandler {
187185
}
188186

189187
private async getAbsolutePathResult(query: IPreparedQuery): Promise<URI | undefined> {
190-
const detildifiedQuery = untildify(query.original, this.environmentService.userHome);
188+
const detildifiedQuery = untildify(query.original, (await this.remotePathService.userHome).path);
191189
if ((await this.remotePathService.path).isAbsolute(detildifiedQuery)) {
192190
const resource = toLocalResource(
193191
await this.remotePathService.fileURI(detildifiedQuery),
194-
this.workbenchEnvironmentService.configuration.remoteAuthority);
192+
this.workbenchEnvironmentService.configuration.remoteAuthority
193+
);
195194

196195
try {
197196
const stat = await this.fileService.resolve(resource);

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
7070
import { RunAutomaticTasks } from 'vs/workbench/contrib/tasks/browser/runAutomaticTasks';
7171

7272
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
73-
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
73+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
7474
import { format } from 'vs/base/common/jsonFormatter';
7575
import { ITextModelService } from 'vs/editor/common/services/resolverService';
7676
import { applyEdits } from 'vs/base/common/jsonEdit';
@@ -256,7 +256,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
256256
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
257257
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
258258
@ITerminalInstanceService private readonly terminalInstanceService: ITerminalInstanceService,
259-
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
259+
@IRemotePathService private readonly remotePathService: IRemotePathService,
260260
@ITextModelService private readonly textModelResolverService: ITextModelService,
261261
@IPreferencesService private readonly preferencesService: IPreferencesService
262262
) {
@@ -1316,7 +1316,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
13161316
this.modelService, this.configurationResolverService, this.telemetryService,
13171317
this.contextService, this.environmentService,
13181318
AbstractTaskService.OutputChannelId, this.fileService, this.terminalInstanceService,
1319-
this.remoteAgentService,
1319+
this.remotePathService,
13201320
(workspaceFolder: IWorkspaceFolder) => {
13211321
if (!workspaceFolder) {
13221322
return undefined;

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { URI } from 'vs/base/common/uri';
4343
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
4444
import { Schemas } from 'vs/base/common/network';
4545
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
46-
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
46+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
4747
import { env as processEnv, cwd as processCwd } from 'vs/base/common/process';
4848

4949
interface TerminalData {
@@ -176,7 +176,7 @@ export class TerminalTaskSystem implements ITaskSystem {
176176
private outputChannelId: string,
177177
private fileService: IFileService,
178178
private terminalInstanceService: ITerminalInstanceService,
179-
private remoteAgentService: IRemoteAgentService,
179+
private remotePathService: IRemotePathService,
180180
taskSystemInfoResolver: TaskSystemInfoResolver,
181181
) {
182182

@@ -829,14 +829,6 @@ export class TerminalTaskSystem implements ITaskSystem {
829829
return nls.localize('TerminalTaskSystem.terminalName', 'Task - {0}', needsFolderQualification ? task.getQualifiedLabel() : task.configurationProperties.name);
830830
}
831831

832-
private async getUserHome(): Promise<URI> {
833-
const env = await this.remoteAgentService.getEnvironment();
834-
if (env) {
835-
return env.userHome;
836-
}
837-
return URI.from({ scheme: Schemas.file, path: this.environmentService.userHome });
838-
}
839-
840832
private async createShellLaunchConfig(task: CustomTask | ContributedTask, workspaceFolder: IWorkspaceFolder | undefined, variableResolver: VariableResolver, platform: Platform.Platform, options: CommandOptions, command: CommandString, args: CommandString[], waitOnExit: boolean | string): Promise<IShellLaunchConfig | undefined> {
841833
let shellLaunchConfig: IShellLaunchConfig;
842834
let isShellCommand = task.command.runtime === RuntimeType.Shell;
@@ -867,7 +859,7 @@ export class TerminalTaskSystem implements ITaskSystem {
867859
windowsShellArgs = true;
868860
let basename = path.basename(shellLaunchConfig.executable!).toLowerCase();
869861
// If we don't have a cwd, then the terminal uses the home dir.
870-
const userHome = await this.getUserHome();
862+
const userHome = await this.remotePathService.userHome;
871863
if (basename === 'cmd.exe' && ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath)))) {
872864
return undefined;
873865
}

src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { ICommandHandler } from 'vs/platform/commands/common/commands';
3535
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3636
import { normalizeDriveLetter } from 'vs/base/common/labels';
3737
import { SaveReason } from 'vs/workbench/common/editor';
38+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
3839

3940
export namespace OpenLocalFileCommand {
4041
export const ID = 'workbench.action.files.openLocalFile';
@@ -134,6 +135,7 @@ export class SimpleFileDialog {
134135
@IModeService private readonly modeService: IModeService,
135136
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
136137
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
138+
@IRemotePathService private readonly remotePathService: IRemotePathService,
137139
@IKeybindingService private readonly keybindingService: IKeybindingService,
138140
@IContextKeyService contextKeyService: IContextKeyService,
139141
) {
@@ -154,8 +156,8 @@ export class SimpleFileDialog {
154156

155157
public async showOpenDialog(options: IOpenDialogOptions = {}): Promise<URI | undefined> {
156158
this.scheme = this.getScheme(options.availableFileSystems, options.defaultUri);
157-
this.userHome = await this.getUserHome();
158-
const newOptions = await this.getOptions(options);
159+
this.userHome = await this.remotePathService.userHome;
160+
const newOptions = this.getOptions(options);
159161
if (!newOptions) {
160162
return Promise.resolve(undefined);
161163
}
@@ -165,9 +167,9 @@ export class SimpleFileDialog {
165167

166168
public async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
167169
this.scheme = this.getScheme(options.availableFileSystems, options.defaultUri);
168-
this.userHome = await this.getUserHome();
170+
this.userHome = await this.remotePathService.userHome;
169171
this.requiresTrailing = true;
170-
const newOptions = await this.getOptions(options, true);
172+
const newOptions = this.getOptions(options, true);
171173
if (!newOptions) {
172174
return Promise.resolve(undefined);
173175
}
@@ -229,16 +231,6 @@ export class SimpleFileDialog {
229231
return this.remoteAgentEnvironment;
230232
}
231233

232-
private async getUserHome(): Promise<URI> {
233-
if (this.scheme !== Schemas.file) {
234-
const env = await this.getRemoteAgentEnvironment();
235-
if (env) {
236-
return env.userHome;
237-
}
238-
}
239-
return URI.from({ scheme: this.scheme, path: this.environmentService.userHome });
240-
}
241-
242234
private async pickResource(isSave: boolean = false): Promise<URI | undefined> {
243235
this.allowFolderSelection = !!this.options.canSelectFolders;
244236
this.allowFileSelection = !!this.options.canSelectFiles;

src/vs/workbench/services/path/common/remotePathService.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ import { URI } from 'vs/base/common/uri';
99
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
1010
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1111
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
12+
import { Schemas } from 'vs/base/common/network';
13+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1214

1315
const REMOTE_PATH_SERVICE_ID = 'remotePath';
1416
export const IRemotePathService = createDecorator<IRemotePathService>(REMOTE_PATH_SERVICE_ID);
1517

1618
export interface IRemotePathService {
1719
_serviceBrand: undefined;
1820

19-
path: Promise<path.IPath>;
21+
readonly path: Promise<path.IPath>;
2022
fileURI(path: string): Promise<URI>;
23+
24+
readonly userHome: Promise<URI>;
2125
}
2226

2327
/**
@@ -29,7 +33,8 @@ export class RemotePathService implements IRemotePathService {
2933
private _extHostOS: Promise<platform.OperatingSystem>;
3034

3135
constructor(
32-
@IRemoteAgentService readonly remoteAgentService: IRemoteAgentService
36+
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
37+
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService
3338
) {
3439
this._extHostOS = remoteAgentService.getEnvironment().then(remoteEnvironment => {
3540
return remoteEnvironment ? remoteEnvironment.os : platform.OS;
@@ -76,6 +81,16 @@ export class RemotePathService implements IRemotePathService {
7681
fragment: ''
7782
});
7883
}
84+
85+
get userHome(): Promise<URI> {
86+
return this.remoteAgentService.getEnvironment().then(env => {
87+
if (env) {
88+
return env.userHome;
89+
}
90+
91+
return URI.from({ scheme: Schemas.file, path: this.environmentService.userHome });
92+
});
93+
}
7994
}
8095

8196
registerSingleton(IRemotePathService, RemotePathService, true);

0 commit comments

Comments
 (0)