1
>
/*---------------------------------------------------------------------------------------------
pathService.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { isValidBasename } from '../../../../base/common/extpath.js';
7
>
import { Schemas } from '../../../../base/common/network.js';
8
>
import { IPath, win32, posix } from '../../../../base/common/path.js';
9
>
import { OperatingSystem, OS } from '../../../../base/common/platform.js';
10
>
import { basename } from '../../../../base/common/resources.js';
11
>
import { URI } from '../../../../base/common/uri.js';
12
>
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
13
>
import { getVirtualWorkspaceScheme } from '../../../../platform/workspace/common/virtualWorkspace.js';
14
>
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
15
>
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';
16
>
import { IRemoteAgentService } from '../../remote/common/remoteAgentService.js';
17
>
18
>
export const IPathService = createDecorator<IPathService>('pathService');
19
>
20
>
/**
21
>
* Provides access to path related properties that will match the
22
>
* environment. If the environment is connected to a remote, the
23
>
* path properties will match that of the remotes operating system.
24
>
*/
25
>
export interface IPathService {
26
>
27
>
readonly _serviceBrand: undefined;
28
>
29
>
/**
30
>
* The correct path library to use for the target environment. If
31
>
* the environment is connected to a remote, this will be the
32
>
* path library of the remote file system. Otherwise it will be
33
>
* the local file system's path library depending on the OS.
34
>
*/
35
>
readonly path: Promise<IPath>;
36
>
37
>
/**
38
>
* Determines the best default URI scheme for the current workspace.
39
>
* It uses information about whether we're running remote, in browser,
40
>
* or native combined with information about the current workspace to
41
>
* find the best default scheme.
42
>
*/
43
>
readonly defaultUriScheme: string;
44
>
45
>
/**
46
>
* Converts the given path to a file URI to use for the target
47
>
* environment. If the environment is connected to a remote, it
48
>
* will use the path separators according to the remote file
49
>
* system. Otherwise it will use the local file system's path
50
>
* separators.
51
>
*/
52
>
fileURI(path: string): Promise<URI>;
53
>
54
>
/**
55
>
* Resolves the user-home directory for the target environment.
56
>
* If the envrionment is connected to a remote, this will be the
57
>
* remote's user home directory, otherwise the local one unless
58
>
* `preferLocal` is set to `true`.
59
>
*/
60
>
userHome(options: { preferLocal: true }): URI;
61
>
userHome(options?: { preferLocal: boolean }): Promise<URI>;
62
>
63
>
/**
64
>
* Figures out if the provided resource has a valid file name
65
>
* for the operating system the file is saved to.
66
>
*
67
>
* Note: this currently only supports `file` and `vscode-file`
68
>
* protocols where we know the limits of the file systems behind
69
>
* these OS. Other remotes are not supported and this method
70
>
* will always return `true` for them.
71
>
*/
72
>
hasValidBasename(resource: URI, basename?: string): Promise<boolean>;
73
>
hasValidBasename(resource: URI, os: OperatingSystem, basename?: string): boolean;
74
>
75
>
/**
76
>
* @deprecated use `userHome` instead.
77
>
*/
78
>
readonly resolvedUserHome: URI | undefined;
79
>
}
80
>
81
>
export abstract class AbstractPathService implements IPathService {
82
>
83
>
declare readonly _serviceBrand: undefined;
84
>
85
>
private resolveOS: Promise<OperatingSystem>;
86
>
87
>
private resolveUserHome: Promise<URI>;
88
>
private maybeUnresolvedUserHome: URI | undefined;
89
>
90
>
constructor(
91
private localUserHome: URI,
92
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,