Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/editSessions/common/editSessions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { decodeBase64, VSBuffer } from '../../../../base/common/buffer.js';
7
import { Codicon } from '../../../../base/common/codicons.js';
8
import { localize, localize2 } from '../../../../nls.js';
9
import { ILocalizedString } from '../../../../platform/action/common/action.js';
10
import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
11
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
12
import { ILogService } from '../../../../platform/log/common/log.js';
13
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
14
import { IResourceRefHandle } from '../../../../platform/userDataSync/common/userDataSync.js';
15
import { Event } from '../../../../base/common/event.js';
16
import { StringSHA1 } from '../../../../base/common/hash.js';
17
import { EditSessionsStoreClient } from './editSessionsStorageClient.js';
18
19
export const EDIT_SESSION_SYNC_CATEGORY = localize2('cloud changes', 'Cloud Changes');
20
21
export type SyncResource = 'editSessions' | 'workspaceState';
22
23
export const IEditSessionsStorageService = createDecorator<IEditSessionsStorageService>('IEditSessionsStorageService');
24
export interface IEditSessionsStorageService {
25
_serviceBrand: undefined;
26
27
readonly SIZE_LIMIT: number;
28
29
readonly isSignedIn: boolean;
30
readonly onDidSignIn: Event<void>;
31
readonly onDidSignOut: Event<void>;
32
33
storeClient: EditSessionsStoreClient | undefined;
34
35
lastReadResources: Map<SyncResource, { ref: string; content: string }>;
36
lastWrittenResources: Map<SyncResource, { ref: string; content: string }>;
37
38
initialize(reason: 'read' | 'write', silent?: boolean): Promise<boolean>;
39
read(resource: SyncResource, ref: string | undefined): Promise<{ ref: string; content: string } | undefined>;
40
write(resource: SyncResource, content: string | EditSession): Promise<string>;
41
delete(resource: SyncResource, ref: string | null): Promise<void>;
42
list(resource: SyncResource): Promise<IResourceRefHandle[]>;
43
getMachineById(machineId: string): Promise<string | undefined>;
44
}
45
46
export const IEditSessionsLogService = createDecorator<IEditSessionsLogService>('IEditSessionsLogService');
47
export interface IEditSessionsLogService extends ILogService { }
48
49
export enum ChangeType {
50
Addition = 1,
51
Deletion = 2,
52
}
53
54
export enum FileType {
55
File = 1,
56
}
57
58
interface Addition {
59
relativeFilePath: string;
60
fileType: FileType.File;
61
contents: string;
62
type: ChangeType.Addition;
63
}
64
65
interface Deletion {
66
relativeFilePath: string;
67
fileType: FileType.File;
68
contents: undefined;
69
type: ChangeType.Deletion;
70
}
71
72
export type Change = Addition | Deletion;
73
74
export interface Folder {
75
name: string;
76
canonicalIdentity: string | undefined;
77
workingChanges: Change[];
78
absoluteUri: string | undefined;
79
}
80
81
export const EditSessionSchemaVersion = 3;
82
83
export interface EditSession {
84
version: number;
85
workspaceStateId?: string;
86
machine?: string;
87
folders: Folder[];
88
}
89
90
export const EDIT_SESSIONS_SIGNED_IN_KEY = 'editSessionsSignedIn';
91
export const EDIT_SESSIONS_SIGNED_IN = new RawContextKey<boolean>(EDIT_SESSIONS_SIGNED_IN_KEY, false);
92
93
export const EDIT_SESSIONS_PENDING_KEY = 'editSessionsPending';
94
export const EDIT_SESSIONS_PENDING = new RawContextKey<boolean>(EDIT_SESSIONS_PENDING_KEY, false);
95
96
export const EDIT_SESSIONS_CONTAINER_ID = 'workbench.view.editSessions';
97
export const EDIT_SESSIONS_DATA_VIEW_ID = 'workbench.views.editSessions.data';
98
export const EDIT_SESSIONS_TITLE: ILocalizedString = localize2('cloud changes', 'Cloud Changes');
99
100
export const EDIT_SESSIONS_VIEW_ICON = registerIcon('edit-sessions-view-icon', Codicon.cloudDownload, localize('editSessionViewIcon', 'View icon of the cloud changes view.'));
101
102
export const EDIT_SESSIONS_SHOW_VIEW = new RawContextKey<boolean>('editSessionsShowView', false);
103
104
export const EDIT_SESSIONS_SCHEME = 'vscode-edit-sessions';
105
106
export function decodeEditSessionFileContent(version: number, content: string): VSBuffer {
107
switch (version) {
108
case 1:
109
return VSBuffer.fromString(content);
110
case 2:
111
return decodeBase64(content);
112
default:
113
throw new Error('Upgrade to a newer version to decode this content.');
114
}
115
}
116
117
export function hashedEditSessionId(editSessionId: string) {
118
const sha1 = new StringSHA1();
119
sha1.update(editSessionId);
120
return sha1.digest();
121
}
122
123
export const editSessionsLogId = 'editSessions';
124
125