Skip to content

Commit e73d3a8

Browse files
author
Benjamin Pasero
committed
pathService - defaultUriScheme() => defaultUriScheme
1 parent e0d5fae commit e73d3a8

7 files changed

Lines changed: 26 additions & 30 deletions

File tree

src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class SearchEditorInput extends EditorInput {
274274

275275
const searchFileName = (query.replace(/[^\w \-_]+/g, '_') || 'Search') + SEARCH_EDITOR_EXT;
276276

277-
return joinPath(this.fileDialogService.defaultFilePath(this.pathService.defaultUriScheme()) || (await this.pathService.userHome()), searchFileName);
277+
return joinPath(this.fileDialogService.defaultFilePath(this.pathService.defaultUriScheme) || (await this.pathService.userHome()), searchFileName);
278278
}
279279
}
280280

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
230230
}
231231

232232
protected getSchemeFilterForWindow(defaultUriScheme?: string): string {
233-
return defaultUriScheme ?? this.pathService.defaultUriScheme();
233+
return defaultUriScheme ?? this.pathService.defaultUriScheme;
234234
}
235235

236236
protected getFileSystemSchema(options: { availableFileSystems?: readonly string[], defaultUri?: URI }): string {

src/vs/workbench/services/history/browser/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class HistoryService extends Disposable implements IHistoryService {
516516

517517
private preferResourceEditorInput(input: IEditorInput): IEditorInput | IResourceEditorInput {
518518
const resource = input.resource;
519-
if (resource && (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote || resource.scheme === Schemas.userData || resource.scheme === this.pathService.defaultUriScheme())) {
519+
if (resource && (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote || resource.scheme === Schemas.userData || resource.scheme === this.pathService.defaultUriScheme)) {
520520
// for now, only prefer well known schemes that we control to prevent
521521
// issues such as https://github.com/microsoft/vscode/issues/85204
522522
return { resource };

src/vs/workbench/services/path/browser/pathService.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { URI } from 'vs/base/common/uri';
1010
import { Schemas } from 'vs/base/common/network';
1111
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1212
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
13+
import { memoize } from 'vs/base/common/decorators';
1314

1415
export class BrowserPathService extends AbstractPathService {
1516

@@ -21,15 +22,18 @@ export class BrowserPathService extends AbstractPathService {
2122
super(URI.from({ scheme: Schemas.vscodeRemote, authority: environmentService.configuration.remoteAuthority, path: '/' }), remoteAgentService);
2223
}
2324

24-
defaultUriScheme(): string {
25+
@memoize
26+
get defaultUriScheme(): string {
2527
if (this.environmentService.configuration.remoteAuthority) {
2628
return Schemas.vscodeRemote;
27-
} else {
28-
if (this.contextService.getWorkspace().folders.length === 0) {
29-
throw new Error('Empty workspace is not supported in browser when there is no remote');
30-
}
31-
return this.contextService.getWorkspace().folders[0].uri.scheme;
3229
}
30+
31+
const firstFolder = this.contextService.getWorkspace().folders[0];
32+
if (!firstFolder) {
33+
throw new Error('Empty workspace is not supported in browser when there is no remote connection.');
34+
}
35+
36+
return firstFolder.uri.scheme;
3337
}
3438
}
3539

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ export interface IPathService {
2828
*/
2929
readonly path: Promise<IPath>;
3030

31+
/**
32+
* Determines the best default URI scheme for the current workspace.
33+
* It uses information about whether we're running remote, in browser,
34+
* or native combined with information about the current workspace to
35+
* find the best default scheme.
36+
*/
37+
readonly defaultUriScheme: string;
38+
3139
/**
3240
* Converts the given path to a file URI to use for the target
3341
* environment. If the environment is connected to a remote, it
@@ -45,14 +53,6 @@ export interface IPathService {
4553
*/
4654
userHome(options?: { preferLocal: boolean }): Promise<URI>;
4755

48-
/**
49-
* Determines the best default URI scheme for the current workspace.
50-
* It uses information about whether we're running remote, in browser,
51-
* or native combined with information about the current workspace to
52-
* find the best default scheme.
53-
*/
54-
defaultUriScheme(): string;
55-
5656
/**
5757
* @deprecated use `userHome` instead.
5858
*/
@@ -68,6 +68,8 @@ export abstract class AbstractPathService implements IPathService {
6868
private resolveUserHome: Promise<URI>;
6969
private maybeUnresolvedUserHome: URI | undefined;
7070

71+
abstract readonly defaultUriScheme: string;
72+
7173
constructor(
7274
private localUserHome: URI,
7375
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService
@@ -139,6 +141,4 @@ export abstract class AbstractPathService implements IPathService {
139141
fragment: ''
140142
});
141143
}
142-
143-
abstract defaultUriScheme(): string;
144144
}

src/vs/workbench/services/path/electron-sandbox/pathService.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@ import { Schemas } from 'vs/base/common/network';
1212

1313
export class NativePathService extends AbstractPathService {
1414

15+
readonly defaultUriScheme = this.environmentService.configuration.remoteAuthority ? Schemas.vscodeRemote : Schemas.file;
16+
1517
constructor(
1618
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
1719
@IWorkbenchEnvironmentService private readonly environmentService: INativeWorkbenchEnvironmentService
1820
) {
1921
super(environmentService.userHome, remoteAgentService);
2022
}
21-
22-
defaultUriScheme(): string {
23-
if (this.environmentService.configuration.remoteAuthority) {
24-
return Schemas.vscodeRemote;
25-
} else {
26-
return Schemas.file;
27-
}
28-
}
2923
}
3024

3125
registerSingleton(IPathService, NativePathService, true);

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,7 @@ export class TestPathService implements IPathService {
12321232
return URI.file(path);
12331233
}
12341234

1235-
defaultUriScheme(): string {
1236-
return Schemas.vscodeRemote;
1237-
}
1235+
readonly defaultUriScheme = Schemas.vscodeRemote;
12381236
}
12391237

12401238
export class TestTextFileEditorModelManager extends TextFileEditorModelManager {

0 commit comments

Comments
 (0)