1
>
/*---------------------------------------------------------------------------------------------
workspace.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 { localize } from '../../../nls.js';
7
>
import { Event } from '../../../base/common/event.js';
8
>
import { basename, extname } from '../../../base/common/path.js';
9
>
import { TernarySearchTree } from '../../../base/common/ternarySearchTree.js';
10
>
import { extname as resourceExtname, basenameOrAuthority, joinPath, extUriBiasedIgnorePathCase } from '../../../base/common/resources.js';
11
>
import { URI, UriComponents } from '../../../base/common/uri.js';
12
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
13
>
import { IEnvironmentService } from '../../environment/common/environment.js';
14
>
import { Schemas } from '../../../base/common/network.js';
15
>
16
>
export const IWorkspaceContextService = createDecorator<IWorkspaceContextService>('contextService');
17
>
18
>
export interface IWorkspaceContextService {
19
>
20
>
readonly _serviceBrand: undefined;
21
>
22
>
/**
23
>
* An event which fires on workbench state changes.
24
>
*/
25
>
readonly onDidChangeWorkbenchState: Event<WorkbenchState>;
26
>
27
>
/**
28
>
* An event which fires on workspace name changes.
29
>
*/
30
>
readonly onDidChangeWorkspaceName: Event<void>;
31
>
32
>
/**
33
>
* An event which fires before workspace folders change.
34
>
*/
35
>
readonly onWillChangeWorkspaceFolders: Event<IWorkspaceFoldersWillChangeEvent>;
36
>
37
>
/**
38
>
* An event which fires on workspace folders change.
39
>
*/
40
>
readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent>;
41
>
42
>
/**
43
>
* Provides access to the complete workspace object.
44
>
*/
45
>
getCompleteWorkspace(): Promise<IWorkspace>;
46
>
47
>
/**
48
>
* Provides access to the workspace object the window is running with.
49
>
* Use `getCompleteWorkspace` to get complete workspace object.
50
>
*/
51
>
getWorkspace(): IWorkspace;
52
>
53
>
/**
54
>
* Return the state of the workbench.
55
>
*
56
>
* WorkbenchState.EMPTY - if the workbench was opened with empty window or file
57
>
* WorkbenchState.FOLDER - if the workbench was opened with a folder
58
>
* WorkbenchState.WORKSPACE - if the workbench was opened with a workspace
59
>
*/
60
>
getWorkbenchState(): WorkbenchState;
61
>
62
>
/**
63
>
* Returns the folder for the given resource from the workspace.
64
>
* Can be null if there is no workspace or the resource is not inside the workspace.
65
>
*/
66
>
getWorkspaceFolder(resource: URI): IWorkspaceFolder | null;
67
>
68
>
/**
69
>
* Return `true` if the current workspace has the given identifier or root URI otherwise `false`.
70
>
*/
71
>
isCurrentWorkspace(workspaceIdOrFolder: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI): boolean;
72
>
73
>
/**
74
>
* Returns if the provided resource is inside the workspace or not.
75
>
*/
76
>
isInsideWorkspace(resource: URI): boolean;
77
>
78
>
/**
79
>
* Return `true` if the current workspace has data (e.g. folders or a workspace configuration) that can be sent to the extension host, otherwise `false`.
80
>
*/
81
>
hasWorkspaceData(): boolean;
82
>
}
83
>
84
>
export interface IResolvedWorkspace extends IWorkspaceIdentifier, IBaseWorkspace {
85
>
readonly folders: IWorkspaceFolder[];
86
>
}
87
>
88
>
export interface IBaseWorkspace {
89
>
90
>
/**
91
>
* If present, marks the window that opens the workspace
92
>
* as a remote window with the given authority.
93
>
*/
94
>
readonly remoteAuthority?: string;
95
>
96
>
/**
97
>
* Transient workspaces are meant to go away after being used
98
>
* once, e.g. a window reload of a transient workspace will
99
>
* open an empty window.
100
>
*
101
>
* See: https://github.com/microsoft/vscode/issues/119695
102
>
*/
103
>
readonly transient?: boolean;
104
>
}
105
>
106
>
export interface IBaseWorkspaceIdentifier {
107
>
108
>
/**
109
>
* Every workspace (multi-root, single folder or empty)
110
>
* has a unique identifier. It is not possible to open
111
>
* a workspace with the same `id` in multiple windows
112
>
*/
113
>
readonly id: string;
114
>
}
115
>
116
>
/**
117
>
* A single folder workspace identifier is a path to a folder + id.
118
>
*/
119
>
export interface ISingleFolderWorkspaceIdentifier extends IBaseWorkspaceIdentifier {
120
>
121
>
/**
122
>
* Folder path as `URI`.
123
>
*/
124
>
readonly uri: URI;
125
>
}
126
>
127
>
/**
128
>
* A multi-root workspace identifier is a path to a workspace file + id.
129
>
*/
130
>
export interface IWorkspaceIdentifier extends IBaseWorkspaceIdentifier {
131
>
132
>
/**
133
>
* Workspace config file path as `URI`.
134
>
*/
135
>
configPath: URI;
136
>
}
137
>
138
>
export interface IEmptyWorkspaceIdentifier extends IBaseWorkspaceIdentifier { }
139
>
140
>
export type IAnyWorkspaceIdentifier = IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier;
141
>
142
>
export function isSingleFolderWorkspaceIdentifier(obj: unknown): obj is ISingleFolderWorkspaceIdentifier {
143
const singleFolderIdentifier = obj as ISingleFolderWorkspaceIdentifier | undefined;
144
145
return typeof singleFolderIdentifier?.id === 'string' && URI.isUri(singleFolderIdentifier.uri);
146
}
148
>
export function isEmptyWorkspaceIdentifier(obj: unknown): obj is IEmptyWorkspaceIdentifier {
149
const emptyWorkspaceIdentifier = obj as IEmptyWorkspaceIdentifier | undefined;
150
return typeof emptyWorkspaceIdentifier?.id === 'string'