-
Notifications
You must be signed in to change notification settings - Fork 29.4k
/
workingCopy.ts
193 lines (157 loc) · 5.01 KB
/
workingCopy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { ISaveOptions, IRevertOptions, SaveReason, SaveSource } from 'vs/workbench/common/editor';
import { CancellationToken } from 'vs/base/common/cancellation';
import { VSBufferReadable, VSBufferReadableStream } from 'vs/base/common/buffer';
export const enum WorkingCopyCapabilities {
/**
* Signals no specific capability for the working copy.
*/
None = 0,
/**
* Signals that the working copy requires
* additional input when saving, e.g. an
* associated path to save to.
*/
Untitled = 1 << 1
}
/**
* Data to be associated with working copy backups. Use
* `IWorkingCopyBackupService.resolve(workingCopy)` to
* retrieve the backup when loading the working copy.
*/
export interface IWorkingCopyBackup {
/**
* Any serializable metadata to be associated with the backup.
*/
meta?: IWorkingCopyBackupMeta;
/**
* The actual snapshot of the contents of the working copy at
* the time the backup was made.
*/
content?: VSBufferReadable | VSBufferReadableStream;
}
/**
* Working copy backup metadata that can be associated
* with the backup.
*
* Some properties may be reserved as outlined here and
* cannot be used.
*/
export interface IWorkingCopyBackupMeta {
/**
* Any property needs to be serializable through JSON.
*/
[key: string]: unknown;
/**
* `typeId` is a reserved property that cannot be used
* as backup metadata.
*/
typeId?: never;
}
/**
* @deprecated it is important to provide a type identifier
* for working copies to enable all capabilities.
*/
export const NO_TYPE_ID = '';
/**
* Every working copy has in common that it is identified by
* a resource `URI` and a `typeId`. There can only be one
* working copy registered with the same `URI` and `typeId`.
*/
export interface IWorkingCopyIdentifier {
/**
* The type identifier of the working copy for grouping
* working copies of the same domain together.
*
* There can only be one working copy for a given resource
* and type identifier.
*/
readonly typeId: string;
/**
* The resource of the working copy must be unique for
* working copies of the same `typeId`.
*/
readonly resource: URI;
}
export interface IWorkingCopySaveEvent {
/**
* The reason why the working copy was saved.
*/
readonly reason?: SaveReason;
/**
* The source of the working copy save request.
*/
readonly source?: SaveSource;
}
/**
* A working copy is an abstract concept to unify handling of
* data that can be worked on (e.g. edited) in an editor.
*
*
* A working copy resource may be the backing store of the data
* (e.g. a file on disk), but that is not a requirement. If
* your working copy is file based, consider to use the
* `IFileWorkingCopy` instead that simplifies a lot of things
* when working with file based working copies.
*/
export interface IWorkingCopy extends IWorkingCopyIdentifier {
/**
* Human readable name of the working copy.
*/
readonly name: string;
/**
* The capabilities of the working copy.
*/
readonly capabilities: WorkingCopyCapabilities;
//#region Events
/**
* Used by the workbench to signal if the working copy
* is dirty or not. Typically a working copy is dirty
* once changed until saved or reverted.
*/
readonly onDidChangeDirty: Event<void>;
/**
* Used by the workbench e.g. to trigger auto-save
* (unless this working copy is untitled) and backups.
*/
readonly onDidChangeContent: Event<void>;
/**
* Used by the workbench e.g. to track local history
* (unless this working copy is untitled).
*/
readonly onDidSave: Event<IWorkingCopySaveEvent>;
//#endregion
//#region Dirty Tracking
isDirty(): boolean;
//#endregion
//#region Save / Backup
/**
* The workbench may call this method often after it receives
* the `onDidChangeContent` event for the working copy. The motivation
* is to allow to quit VSCode with dirty working copies present.
*
* Providers of working copies should use `IWorkingCopyBackupService.resolve(workingCopy)`
* to retrieve the backup metadata associated when loading the working copy.
*
* @param token support for cancellation
*/
backup(token: CancellationToken): Promise<IWorkingCopyBackup>;
/**
* Asks the working copy to save. If the working copy was dirty, it is
* expected to be non-dirty after this operation has finished.
*
* @returns `true` if the operation was successful and `false` otherwise.
*/
save(options?: ISaveOptions): Promise<boolean>;
/**
* Asks the working copy to revert. If the working copy was dirty, it is
* expected to be non-dirty after this operation has finished.
*/
revert(options?: IRevertOptions): Promise<void>;
//#endregion
}