1
>
/*---------------------------------------------------------------------------------------------
workspaces.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 { Event } from '../../../base/common/event.js';
7
>
import { isUNC, toSlashes } from '../../../base/common/extpath.js';
8
>
import * as json from '../../../base/common/json.js';
9
>
import * as jsonEdit from '../../../base/common/jsonEdit.js';
10
>
import { FormattingOptions } from '../../../base/common/jsonFormatter.js';
11
>
import { normalizeDriveLetter } from '../../../base/common/labels.js';
12
>
import { Schemas } from '../../../base/common/network.js';
13
>
import { isAbsolute, posix } from '../../../base/common/path.js';
14
>
import { isLinux, isMacintosh, isWindows } from '../../../base/common/platform.js';
15
>
import { IExtUri, isEqualAuthority } from '../../../base/common/resources.js';
16
>
import { URI } from '../../../base/common/uri.js';
17
>
import { IWorkspaceBackupInfo, IFolderBackupInfo } from '../../backup/common/backup.js';
18
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
19
>
import { ILogService } from '../../log/common/log.js';
20
>
import { getRemoteAuthority } from '../../remote/common/remoteHosts.js';
21
>
import { IBaseWorkspace, IRawFileWorkspaceFolder, IRawUriWorkspaceFolder, IWorkspaceIdentifier, WorkspaceFolder } from '../../workspace/common/workspace.js';
22
>
23
>
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');
24
>
25
>
export interface IWorkspacesService {
26
>
27
>
readonly _serviceBrand: undefined;
28
>
29
>
// Workspaces Management
30
>
enterWorkspace(workspaceUri: URI): Promise<IEnterWorkspaceResult | undefined>;
31
>
createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier>;
32
>
deleteUntitledWorkspace(workspace: IWorkspaceIdentifier): Promise<void>;
33
>
getWorkspaceIdentifier(workspaceUri: URI): Promise<IWorkspaceIdentifier>;
34
>
35
>
// Workspaces History
36
>
readonly onDidChangeRecentlyOpened: Event<void>;
37
>
addRecentlyOpened(recents: IRecent[]): Promise<void>;
38
>
removeRecentlyOpened(workspaces: URI[]): Promise<void>;
39
>
clearRecentlyOpened(): Promise<void>;
40
>
getRecentlyOpened(): Promise<IRecentlyOpened>;
41
>
42
>
// Dirty Workspaces
43
>
getDirtyWorkspaces(): Promise<Array<IWorkspaceBackupInfo | IFolderBackupInfo>>;
44
>
}
45
>
46
>
//#region Workspaces Recently Opened
47
>
48
>
export interface IRecentlyOpened {
49
>
workspaces: Array<IRecentWorkspace | IRecentFolder>;
50
>
files: IRecentFile[];
51
>
}
52
>
53
>
export type IRecent = IRecentWorkspace | IRecentFolder | IRecentFile;
54
>
55
>
export interface IRecentWorkspace {
56
>
readonly workspace: IWorkspaceIdentifier;
57
>
label?: string;
58
>
readonly remoteAuthority?: string;
59
>
}
60
>
61
>
export interface IRecentFolder {
62
>
readonly folderUri: URI;
63
>
label?: string;
64
>
readonly remoteAuthority?: string;
65
>
}
66
>
67
>
export interface IRecentFile {
68
>
readonly fileUri: URI;
69
>
label?: string;
70
>
readonly remoteAuthority?: string;
71
>
}
72
>
73
>
export function isRecentWorkspace(curr: IRecent): curr is IRecentWorkspace {
74
return curr.hasOwnProperty('workspace');
75
}
77
>
export function isRecentFolder(curr: IRecent): curr is IRecentFolder {
78
return curr.hasOwnProperty('folderUri');
79
}
81
>
export function isRecentFile(curr: IRecent): curr is IRecentFile {
82
return curr.hasOwnProperty('fileUri');
83
}
85
>
//#endregion
86
>
87
>
//#region Workspace File Utilities
88
>
89
>
export function isStoredWorkspaceFolder(obj: unknown): obj is IStoredWorkspaceFolder {
90
return isRawFileWorkspaceFolder(obj) || isRawUriWorkspaceFolder(obj);
91
}
93
function isRawFileWorkspaceFolder(obj: unknown): obj is IRawFileWorkspaceFolder {
94
const candidate = obj as IRawFileWorkspaceFolder | undefined;