@codingame/monaco-vscode-api 1.83.12 → 1.83.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-api",
|
|
3
|
-
"version": "1.83.
|
|
3
|
+
"version": "1.83.13",
|
|
4
4
|
"description": "VSCode public API plugged on the monaco editor",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": {
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
"dependencies": {
|
|
97
97
|
"monaco-editor": "0.44.0",
|
|
98
98
|
"vscode-semver": "npm:semver@=5.5.0",
|
|
99
|
-
"@codingame/monaco-vscode-
|
|
100
|
-
"@codingame/monaco-vscode-
|
|
101
|
-
"@codingame/monaco-vscode-
|
|
102
|
-
"@codingame/monaco-vscode-
|
|
103
|
-
"@codingame/monaco-vscode-quickaccess-service-override": "1.83.
|
|
99
|
+
"@codingame/monaco-vscode-layout-service-override": "1.83.13",
|
|
100
|
+
"@codingame/monaco-vscode-environment-service-override": "1.83.13",
|
|
101
|
+
"@codingame/monaco-vscode-extensions-service-override": "1.83.13",
|
|
102
|
+
"@codingame/monaco-vscode-files-service-override": "1.83.13",
|
|
103
|
+
"@codingame/monaco-vscode-quickaccess-service-override": "1.83.13"
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -175,7 +175,7 @@ class CellMatch {
|
|
|
175
175
|
this._webviewMatches.clear();
|
|
176
176
|
}
|
|
177
177
|
addContentMatches(textSearchMatches) {
|
|
178
|
-
const contentMatches = textSearchMatchesToNotebookMatches();
|
|
178
|
+
const contentMatches = textSearchMatchesToNotebookMatches(textSearchMatches, this);
|
|
179
179
|
contentMatches.forEach((match) => {
|
|
180
180
|
this._contentMatches.set(match.id(), match);
|
|
181
181
|
});
|
|
@@ -193,7 +193,7 @@ class CellMatch {
|
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
addWebviewMatches(textSearchMatches) {
|
|
196
|
-
const webviewMatches = textSearchMatchesToNotebookMatches();
|
|
196
|
+
const webviewMatches = textSearchMatchesToNotebookMatches(textSearchMatches, this);
|
|
197
197
|
webviewMatches.forEach((match) => {
|
|
198
198
|
this._webviewMatches.set(match.id(), match);
|
|
199
199
|
});
|
|
@@ -1889,6 +1889,27 @@ function textSearchResultToMatches(rawMatch, fileMatch) {
|
|
|
1889
1889
|
}
|
|
1890
1890
|
function textSearchMatchesToNotebookMatches(textSearchMatches, cell) {
|
|
1891
1891
|
const notebookMatches = [];
|
|
1892
|
+
textSearchMatches.forEach((textSearchMatch) => {
|
|
1893
|
+
const previewLines = textSearchMatch.preview.text.split('\n');
|
|
1894
|
+
if (Array.isArray(textSearchMatch.ranges)) {
|
|
1895
|
+
textSearchMatch.ranges.forEach((r, i) => {
|
|
1896
|
+
const previewRange = textSearchMatch.preview.matches[i];
|
|
1897
|
+
const match = ( new MatchInNotebook(cell, previewLines, previewRange, r, textSearchMatch.webviewIndex));
|
|
1898
|
+
notebookMatches.push(match);
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
else {
|
|
1902
|
+
const previewRange = textSearchMatch.preview.matches;
|
|
1903
|
+
const match = ( new MatchInNotebook(
|
|
1904
|
+
cell,
|
|
1905
|
+
previewLines,
|
|
1906
|
+
previewRange,
|
|
1907
|
+
textSearchMatch.ranges,
|
|
1908
|
+
textSearchMatch.webviewIndex
|
|
1909
|
+
));
|
|
1910
|
+
notebookMatches.push(match);
|
|
1911
|
+
}
|
|
1912
|
+
});
|
|
1892
1913
|
return notebookMatches;
|
|
1893
1914
|
}
|
|
1894
1915
|
function arrayContainsElementOrParent(element, testArray) {
|
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { joinPath } from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
3
|
-
import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
|
|
4
|
-
import { coalesce } from 'monaco-editor/esm/vs/base/common/arrays.js';
|
|
5
|
-
import { deepClone, equals } from 'monaco-editor/esm/vs/base/common/objects.js';
|
|
6
|
-
import { ResourceQueue, Promises } from 'monaco-editor/esm/vs/base/common/async.js';
|
|
7
|
-
import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
|
|
8
|
-
import { ResourceMap } from 'monaco-editor/esm/vs/base/common/map.js';
|
|
9
|
-
import { isReadableStream, peekStream } from 'monaco-editor/esm/vs/base/common/stream.js';
|
|
10
|
-
import { VSBuffer, prefixedBufferStream, prefixedBufferReadable, bufferToStream, streamToBuffer, readableToBuffer } from 'monaco-editor/esm/vs/base/common/buffer.js';
|
|
11
|
-
import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
12
|
-
import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
|
|
13
|
-
import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
|
|
14
|
-
import { hash } from 'monaco-editor/esm/vs/base/common/hash.js';
|
|
15
|
-
import { isEmptyObject } from 'monaco-editor/esm/vs/base/common/types.js';
|
|
16
|
-
import { NO_TYPE_ID } from './workingCopy.js';
|
|
17
|
-
var WorkingCopyBackupServiceImpl_1;
|
|
18
|
-
class WorkingCopyBackupsModel {
|
|
19
|
-
static async create(backupRoot, fileService) {
|
|
20
|
-
const model = ( new WorkingCopyBackupsModel(backupRoot, fileService));
|
|
21
|
-
await model.resolve();
|
|
22
|
-
return model;
|
|
23
|
-
}
|
|
24
|
-
constructor(backupRoot, fileService) {
|
|
25
|
-
this.backupRoot = backupRoot;
|
|
26
|
-
this.fileService = fileService;
|
|
27
|
-
this.cache = ( new ResourceMap());
|
|
28
|
-
}
|
|
29
|
-
async resolve() {
|
|
30
|
-
try {
|
|
31
|
-
const backupRootStat = await this.fileService.resolve(this.backupRoot);
|
|
32
|
-
if (backupRootStat.children) {
|
|
33
|
-
await Promises.settled(( backupRootStat.children
|
|
34
|
-
.filter(child => child.isDirectory)
|
|
35
|
-
.map(async (backupSchemaFolder) => {
|
|
36
|
-
const backupSchemaFolderStat = await this.fileService.resolve(backupSchemaFolder.resource);
|
|
37
|
-
if (backupSchemaFolderStat.children) {
|
|
38
|
-
for (const backupForSchema of backupSchemaFolderStat.children) {
|
|
39
|
-
if (!backupForSchema.isDirectory) {
|
|
40
|
-
this.add(backupForSchema.resource);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
})));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
add(resource, versionId = 0, meta) {
|
|
51
|
-
this.cache.set(resource, {
|
|
52
|
-
versionId,
|
|
53
|
-
meta: deepClone(meta)
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
update(resource, meta) {
|
|
57
|
-
const entry = this.cache.get(resource);
|
|
58
|
-
if (entry) {
|
|
59
|
-
entry.meta = deepClone(meta);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
count() {
|
|
63
|
-
return this.cache.size;
|
|
64
|
-
}
|
|
65
|
-
has(resource, versionId, meta) {
|
|
66
|
-
const entry = this.cache.get(resource);
|
|
67
|
-
if (!entry) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
if (typeof versionId === 'number' && versionId !== entry.versionId) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
if (meta && !equals(meta, entry.meta)) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
get() {
|
|
79
|
-
return Array.from(( this.cache.keys()));
|
|
80
|
-
}
|
|
81
|
-
remove(resource) {
|
|
82
|
-
this.cache.delete(resource);
|
|
83
|
-
}
|
|
84
|
-
clear() {
|
|
85
|
-
this.cache.clear();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
let WorkingCopyBackupServiceImpl = class WorkingCopyBackupServiceImpl extends Disposable {
|
|
89
|
-
static { WorkingCopyBackupServiceImpl_1 = this; }
|
|
90
|
-
static { this.PREAMBLE_END_MARKER = '\n'; }
|
|
91
|
-
static { this.PREAMBLE_END_MARKER_CHARCODE = '\n'.charCodeAt(0); }
|
|
92
|
-
static { this.PREAMBLE_META_SEPARATOR = ' '; }
|
|
93
|
-
static { this.PREAMBLE_MAX_LENGTH = 10000; }
|
|
94
|
-
constructor(backupWorkspaceHome, fileService, logService) {
|
|
95
|
-
super();
|
|
96
|
-
this.backupWorkspaceHome = backupWorkspaceHome;
|
|
97
|
-
this.fileService = fileService;
|
|
98
|
-
this.logService = logService;
|
|
99
|
-
this.ioOperationQueues = this._register(( new ResourceQueue()));
|
|
100
|
-
this.model = undefined;
|
|
101
|
-
this.initialize(backupWorkspaceHome);
|
|
102
|
-
}
|
|
103
|
-
initialize(backupWorkspaceResource) {
|
|
104
|
-
this.backupWorkspaceHome = backupWorkspaceResource;
|
|
105
|
-
this.ready = this.doInitialize();
|
|
106
|
-
}
|
|
107
|
-
async doInitialize() {
|
|
108
|
-
this.model = await WorkingCopyBackupsModel.create(this.backupWorkspaceHome, this.fileService);
|
|
109
|
-
return this.model;
|
|
110
|
-
}
|
|
111
|
-
async hasBackups() {
|
|
112
|
-
const model = await this.ready;
|
|
113
|
-
await this.joinBackups();
|
|
114
|
-
return model.count() > 0;
|
|
115
|
-
}
|
|
116
|
-
hasBackupSync(identifier, versionId, meta) {
|
|
117
|
-
if (!this.model) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
const backupResource = this.toBackupResource(identifier);
|
|
121
|
-
return ( this.model.has(backupResource, versionId, meta));
|
|
122
|
-
}
|
|
123
|
-
async backup(identifier, content, versionId, meta, token) {
|
|
124
|
-
const model = await this.ready;
|
|
125
|
-
if (token?.isCancellationRequested) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const backupResource = this.toBackupResource(identifier);
|
|
129
|
-
if (( model.has(backupResource, versionId, meta))) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
return this.ioOperationQueues.queueFor(backupResource).queue(async () => {
|
|
133
|
-
if (token?.isCancellationRequested) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (( model.has(backupResource, versionId, meta))) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
let preamble = this.createPreamble(identifier, meta);
|
|
140
|
-
if (preamble.length >= WorkingCopyBackupServiceImpl_1.PREAMBLE_MAX_LENGTH) {
|
|
141
|
-
preamble = this.createPreamble(identifier);
|
|
142
|
-
}
|
|
143
|
-
const preambleBuffer = VSBuffer.fromString(preamble);
|
|
144
|
-
let backupBuffer;
|
|
145
|
-
if (isReadableStream(content)) {
|
|
146
|
-
backupBuffer = prefixedBufferStream(preambleBuffer, content);
|
|
147
|
-
}
|
|
148
|
-
else if (content) {
|
|
149
|
-
backupBuffer = prefixedBufferReadable(preambleBuffer, content);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
backupBuffer = VSBuffer.concat([preambleBuffer, VSBuffer.fromString('')]);
|
|
153
|
-
}
|
|
154
|
-
await this.fileService.writeFile(backupResource, backupBuffer);
|
|
155
|
-
model.add(backupResource, versionId, meta);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
createPreamble(identifier, meta) {
|
|
159
|
-
return `${( identifier.resource.toString())}${WorkingCopyBackupServiceImpl_1.PREAMBLE_META_SEPARATOR}${JSON.stringify({ ...meta, typeId: identifier.typeId })}${WorkingCopyBackupServiceImpl_1.PREAMBLE_END_MARKER}`;
|
|
160
|
-
}
|
|
161
|
-
async discardBackups(filter) {
|
|
162
|
-
const model = await this.ready;
|
|
163
|
-
const except = filter?.except;
|
|
164
|
-
if (Array.isArray(except) && except.length > 0) {
|
|
165
|
-
const exceptMap = ( new ResourceMap());
|
|
166
|
-
for (const exceptWorkingCopy of except) {
|
|
167
|
-
exceptMap.set(this.toBackupResource(exceptWorkingCopy), true);
|
|
168
|
-
}
|
|
169
|
-
await Promises.settled(( model.get().map(async (backupResource) => {
|
|
170
|
-
if (!( exceptMap.has(backupResource))) {
|
|
171
|
-
await this.doDiscardBackup(backupResource);
|
|
172
|
-
}
|
|
173
|
-
})));
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
await this.deleteIgnoreFileNotFound(this.backupWorkspaceHome);
|
|
177
|
-
model.clear();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
discardBackup(identifier, token) {
|
|
181
|
-
const backupResource = this.toBackupResource(identifier);
|
|
182
|
-
return this.doDiscardBackup(backupResource, token);
|
|
183
|
-
}
|
|
184
|
-
async doDiscardBackup(backupResource, token) {
|
|
185
|
-
const model = await this.ready;
|
|
186
|
-
if (token?.isCancellationRequested) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
return this.ioOperationQueues.queueFor(backupResource).queue(async () => {
|
|
190
|
-
if (token?.isCancellationRequested) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
await this.deleteIgnoreFileNotFound(backupResource);
|
|
194
|
-
model.remove(backupResource);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async deleteIgnoreFileNotFound(backupResource) {
|
|
198
|
-
try {
|
|
199
|
-
await this.fileService.del(backupResource, { recursive: true });
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
if (error.fileOperationResult !== 1 ) {
|
|
203
|
-
throw error;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async getBackups() {
|
|
208
|
-
const model = await this.ready;
|
|
209
|
-
await this.joinBackups();
|
|
210
|
-
const backups = await Promise.all(( model.get().map(backupResource => this.resolveIdentifier(backupResource, model))));
|
|
211
|
-
return coalesce(backups);
|
|
212
|
-
}
|
|
213
|
-
async resolveIdentifier(backupResource, model) {
|
|
214
|
-
let res = undefined;
|
|
215
|
-
await this.ioOperationQueues.queueFor(backupResource).queue(async () => {
|
|
216
|
-
if (!( model.has(backupResource))) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const backupPreamble = await this.readToMatchingString(backupResource, WorkingCopyBackupServiceImpl_1.PREAMBLE_END_MARKER, WorkingCopyBackupServiceImpl_1.PREAMBLE_MAX_LENGTH);
|
|
220
|
-
if (!backupPreamble) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const metaStartIndex = backupPreamble.indexOf(WorkingCopyBackupServiceImpl_1.PREAMBLE_META_SEPARATOR);
|
|
224
|
-
let resourcePreamble;
|
|
225
|
-
let metaPreamble;
|
|
226
|
-
if (metaStartIndex > 0) {
|
|
227
|
-
resourcePreamble = backupPreamble.substring(0, metaStartIndex);
|
|
228
|
-
metaPreamble = backupPreamble.substr(metaStartIndex + 1);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
resourcePreamble = backupPreamble;
|
|
232
|
-
metaPreamble = undefined;
|
|
233
|
-
}
|
|
234
|
-
const { typeId, meta } = this.parsePreambleMeta(metaPreamble);
|
|
235
|
-
model.update(backupResource, meta);
|
|
236
|
-
res = {
|
|
237
|
-
typeId: typeId ?? NO_TYPE_ID,
|
|
238
|
-
resource: ( URI.parse(resourcePreamble))
|
|
239
|
-
};
|
|
240
|
-
});
|
|
241
|
-
return res;
|
|
242
|
-
}
|
|
243
|
-
async readToMatchingString(backupResource, matchingString, maximumBytesToRead) {
|
|
244
|
-
const contents = ( (await this.fileService.readFile(backupResource, { length: maximumBytesToRead })).value.toString());
|
|
245
|
-
const matchingStringIndex = contents.indexOf(matchingString);
|
|
246
|
-
if (matchingStringIndex >= 0) {
|
|
247
|
-
return contents.substr(0, matchingStringIndex);
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
async resolve(identifier) {
|
|
252
|
-
const backupResource = this.toBackupResource(identifier);
|
|
253
|
-
const model = await this.ready;
|
|
254
|
-
let res = undefined;
|
|
255
|
-
await this.ioOperationQueues.queueFor(backupResource).queue(async () => {
|
|
256
|
-
if (!( model.has(backupResource))) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const backupStream = await this.fileService.readFileStream(backupResource);
|
|
260
|
-
const peekedBackupStream = await peekStream(backupStream.value, 1);
|
|
261
|
-
const firstBackupChunk = VSBuffer.concat(peekedBackupStream.buffer);
|
|
262
|
-
const preambleEndIndex = firstBackupChunk.buffer.indexOf(WorkingCopyBackupServiceImpl_1.PREAMBLE_END_MARKER_CHARCODE);
|
|
263
|
-
if (preambleEndIndex === -1) {
|
|
264
|
-
this.logService.trace(`Backup: Could not find meta end marker in ${backupResource}. The file is probably corrupt (filesize: ${backupStream.size}).`);
|
|
265
|
-
return undefined;
|
|
266
|
-
}
|
|
267
|
-
const preambelRaw = ( firstBackupChunk.slice(0, preambleEndIndex).toString());
|
|
268
|
-
let meta;
|
|
269
|
-
const metaStartIndex = preambelRaw.indexOf(WorkingCopyBackupServiceImpl_1.PREAMBLE_META_SEPARATOR);
|
|
270
|
-
if (metaStartIndex !== -1) {
|
|
271
|
-
meta = this.parsePreambleMeta(preambelRaw.substr(metaStartIndex + 1)).meta;
|
|
272
|
-
}
|
|
273
|
-
model.update(backupResource, meta);
|
|
274
|
-
const firstBackupChunkWithoutPreamble = firstBackupChunk.slice(preambleEndIndex + 1);
|
|
275
|
-
let value;
|
|
276
|
-
if (peekedBackupStream.ended) {
|
|
277
|
-
value = bufferToStream(firstBackupChunkWithoutPreamble);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
value = prefixedBufferStream(firstBackupChunkWithoutPreamble, peekedBackupStream.stream);
|
|
281
|
-
}
|
|
282
|
-
res = { value, meta };
|
|
283
|
-
});
|
|
284
|
-
return res;
|
|
285
|
-
}
|
|
286
|
-
parsePreambleMeta(preambleMetaRaw) {
|
|
287
|
-
let typeId = undefined;
|
|
288
|
-
let meta = undefined;
|
|
289
|
-
if (preambleMetaRaw) {
|
|
290
|
-
try {
|
|
291
|
-
meta = JSON.parse(preambleMetaRaw);
|
|
292
|
-
typeId = meta?.typeId;
|
|
293
|
-
if (typeof meta?.typeId === 'string') {
|
|
294
|
-
delete meta.typeId;
|
|
295
|
-
if (isEmptyObject(meta)) {
|
|
296
|
-
meta = undefined;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
catch (error) {
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return { typeId, meta };
|
|
304
|
-
}
|
|
305
|
-
toBackupResource(identifier) {
|
|
306
|
-
return joinPath(this.backupWorkspaceHome, identifier.resource.scheme, hashIdentifier(identifier));
|
|
307
|
-
}
|
|
308
|
-
joinBackups() {
|
|
309
|
-
return this.ioOperationQueues.whenDrained();
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
WorkingCopyBackupServiceImpl = WorkingCopyBackupServiceImpl_1 = ( __decorate([
|
|
313
|
-
( __param(1, IFileService)),
|
|
314
|
-
( __param(2, ILogService))
|
|
315
|
-
], WorkingCopyBackupServiceImpl));
|
|
316
|
-
class InMemoryWorkingCopyBackupService extends Disposable {
|
|
317
|
-
constructor() {
|
|
318
|
-
super();
|
|
319
|
-
this.backups = ( new ResourceMap());
|
|
320
|
-
}
|
|
321
|
-
async hasBackups() {
|
|
322
|
-
return this.backups.size > 0;
|
|
323
|
-
}
|
|
324
|
-
hasBackupSync(identifier, versionId) {
|
|
325
|
-
const backupResource = this.toBackupResource(identifier);
|
|
326
|
-
return ( this.backups.has(backupResource));
|
|
327
|
-
}
|
|
328
|
-
async backup(identifier, content, versionId, meta, token) {
|
|
329
|
-
const backupResource = this.toBackupResource(identifier);
|
|
330
|
-
this.backups.set(backupResource, {
|
|
331
|
-
typeId: identifier.typeId,
|
|
332
|
-
content: content instanceof VSBuffer ? content : content ? isReadableStream(content) ? await streamToBuffer(content) : readableToBuffer(content) : VSBuffer.fromString(''),
|
|
333
|
-
meta
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
async resolve(identifier) {
|
|
337
|
-
const backupResource = this.toBackupResource(identifier);
|
|
338
|
-
const backup = this.backups.get(backupResource);
|
|
339
|
-
if (backup) {
|
|
340
|
-
return { value: bufferToStream(backup.content), meta: backup.meta };
|
|
341
|
-
}
|
|
342
|
-
return undefined;
|
|
343
|
-
}
|
|
344
|
-
async getBackups() {
|
|
345
|
-
return ( Array.from(this.backups.entries()).map(([resource, backup]) => ({ typeId: backup.typeId, resource })));
|
|
346
|
-
}
|
|
347
|
-
async discardBackup(identifier) {
|
|
348
|
-
this.backups.delete(this.toBackupResource(identifier));
|
|
349
|
-
}
|
|
350
|
-
async discardBackups(filter) {
|
|
351
|
-
const except = filter?.except;
|
|
352
|
-
if (Array.isArray(except) && except.length > 0) {
|
|
353
|
-
const exceptMap = ( new ResourceMap());
|
|
354
|
-
for (const exceptWorkingCopy of except) {
|
|
355
|
-
exceptMap.set(this.toBackupResource(exceptWorkingCopy), true);
|
|
356
|
-
}
|
|
357
|
-
for (const backup of await this.getBackups()) {
|
|
358
|
-
if (!( exceptMap.has(this.toBackupResource(backup)))) {
|
|
359
|
-
await this.discardBackup(backup);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
this.backups.clear();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
toBackupResource(identifier) {
|
|
368
|
-
return ( URI.from({ scheme: Schemas.inMemory, path: hashIdentifier(identifier) }));
|
|
369
|
-
}
|
|
370
|
-
async joinBackups() {
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function hashIdentifier(identifier) {
|
|
375
|
-
let resource;
|
|
376
|
-
if (identifier.typeId.length > 0) {
|
|
377
|
-
const typeIdHash = hashString(identifier.typeId);
|
|
378
|
-
if (identifier.resource.path) {
|
|
379
|
-
resource = joinPath(identifier.resource, typeIdHash);
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
resource = identifier.resource.with({ path: typeIdHash });
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
resource = identifier.resource;
|
|
387
|
-
}
|
|
388
|
-
return hashPath(resource);
|
|
389
|
-
}
|
|
390
|
-
function hashPath(resource) {
|
|
391
|
-
const str = resource.scheme === Schemas.file || resource.scheme === Schemas.untitled ? resource.fsPath : ( resource.toString());
|
|
392
|
-
return hashString(str);
|
|
393
|
-
}
|
|
394
|
-
function hashString(str) {
|
|
395
|
-
return ( hash(str).toString(16));
|
|
396
|
-
}
|
|
397
|
-
export { InMemoryWorkingCopyBackupService, WorkingCopyBackupsModel, hashIdentifier };
|