paths - allow to get at local userHome folder

This commit is contained in:
Benjamin Pasero 2020-06-22 10:28:02 +02:00
parent 68bf05a59c
commit 1264c0dfbf
10 changed files with 16 additions and 15 deletions

View file

@ -348,7 +348,7 @@ class SessionTreeItem extends BaseTreeItem {
// on unix try to tildify absolute paths
path = normalize(path);
if (!isWindows) {
path = tildify(path, (await this._pathService.userHome).fsPath);
path = tildify(path, (await this._pathService.userHome()).fsPath);
}
}
}

View file

@ -40,7 +40,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
terminalService.openTerminal(paths.dirname(activeFile.fsPath));
} else {
const pathService = accessor.get(IPathService);
const userHome = await pathService.userHome;
const userHome = await pathService.userHome();
terminalService.openTerminal(userHome.fsPath);
}
}

View file

@ -643,7 +643,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
return;
}
const userHome = await this.pathService.userHome;
const userHome = await this.pathService.userHome();
const detildifiedQuery = untildify(query.original, userHome.scheme === Schemas.file ? userHome.fsPath : userHome.path);
if (token.isCancellationRequested) {
return;

View file

@ -280,7 +280,7 @@ export class SearchEditorInput extends EditorInput {
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
const schemeFilter = remoteAuthority ? network.Schemas.vscodeRemote : network.Schemas.file;
return joinPath(this.fileDialogService.defaultFilePath(schemeFilter) || (await this.pathService.userHome), searchFileName);
return joinPath(this.fileDialogService.defaultFilePath(schemeFilter) || (await this.pathService.userHome()), searchFileName);
}
}

View file

@ -968,7 +968,7 @@ export class TerminalTaskSystem implements ITaskSystem {
windowsShellArgs = true;
let basename = path.basename(shellLaunchConfig.executable!).toLowerCase();
// If we don't have a cwd, then the terminal uses the home dir.
const userHome = await this.pathService.userHome;
const userHome = await this.pathService.userHome();
if (basename === 'cmd.exe' && ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath)))) {
return undefined;
}

View file

@ -146,7 +146,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
this.userHome = this._pathService.resolvedUserHome?.fsPath;
this.os = platform.OS;
if (launchRemotely) {
const userHomeUri = await this._pathService.userHome;
const userHomeUri = await this._pathService.userHome();
this.userHome = userHomeUri.path;
if (hasRemoteAuthority) {
const remoteEnv = await this._remoteAgentService.getEnvironment();

View file

@ -231,8 +231,8 @@ export class SimpleFileDialog {
return this.remoteAgentEnvironment;
}
protected async getUserHome(): Promise<URI> {
return (await this.pathService.userHome) ?? URI.from({ scheme: this.scheme, authority: this.remoteAuthority, path: '/' });
protected getUserHome(): Promise<URI> {
return this.pathService.userHome({ preferLocal: this.scheme === Schemas.file });
}
private async pickResource(isSave: boolean = false): Promise<URI | undefined> {

View file

@ -40,9 +40,10 @@ export interface IPathService {
/**
* Resolves the user-home directory for the target environment.
* If the envrionment is connected to a remote, this will be the
* remote's user home directory, otherwise the local one.
* remote's user home directory, otherwise the local one unless
* `preferLocal` is set to `true`.
*/
readonly userHome: Promise<URI>;
userHome(options?: { preferLocal: boolean }): Promise<URI>;
/**
* @deprecated use `userHome` instead.
@ -60,7 +61,7 @@ export abstract class AbstractPathService implements IPathService {
private maybeUnresolvedUserHome: URI | undefined;
constructor(
localUserHome: URI,
private localUserHome: URI,
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService
) {
@ -81,8 +82,8 @@ export abstract class AbstractPathService implements IPathService {
})();
}
get userHome(): Promise<URI> {
return this.resolveUserHome;
async userHome(options?: { preferLocal: boolean }): Promise<URI> {
return options?.preferLocal ? this.localUserHome : this.resolveUserHome;
}
get resolvedUserHome(): URI | undefined {

View file

@ -462,7 +462,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
// Try to place where last active file was if any
// Otherwise fallback to user home
return joinPath(this.fileDialogService.defaultFilePath() || (await this.pathService.userHome), suggestedFilename);
return joinPath(this.fileDialogService.defaultFilePath() || (await this.pathService.userHome()), suggestedFilename);
}
//#endregion

View file

@ -1154,7 +1154,7 @@ export class TestPathService implements IPathService {
get path() { return Promise.resolve(isWindows ? win32 : posix); }
get userHome() { return Promise.resolve(this.fallbackUserHome); }
async userHome() { return this.fallbackUserHome; }
get resolvedUserHome() { return this.fallbackUserHome; }
async fileURI(path: string): Promise<URI> {