@opensumi/ide-utils 2.16.6
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/lib/ansi.d.ts +5 -0
- package/lib/ansi.d.ts.map +1 -0
- package/lib/ansi.js +14 -0
- package/lib/ansi.js.map +1 -0
- package/lib/arrays.d.ts +49 -0
- package/lib/arrays.d.ts.map +1 -0
- package/lib/arrays.js +275 -0
- package/lib/arrays.js.map +1 -0
- package/lib/async.d.ts +185 -0
- package/lib/async.d.ts.map +1 -0
- package/lib/async.js +467 -0
- package/lib/async.js.map +1 -0
- package/lib/buffer.d.ts +35 -0
- package/lib/buffer.d.ts.map +1 -0
- package/lib/buffer.js +174 -0
- package/lib/buffer.js.map +1 -0
- package/lib/cache.d.ts +12 -0
- package/lib/cache.d.ts.map +1 -0
- package/lib/cache.js +37 -0
- package/lib/cache.js.map +1 -0
- package/lib/cancellation.d.ts +23 -0
- package/lib/cancellation.d.ts.map +1 -0
- package/lib/cancellation.js +120 -0
- package/lib/cancellation.js.map +1 -0
- package/lib/charCode.d.ts +406 -0
- package/lib/charCode.d.ts.map +1 -0
- package/lib/charCode.js +8 -0
- package/lib/charCode.js.map +1 -0
- package/lib/character-classifier.d.ts +25 -0
- package/lib/character-classifier.d.ts.map +1 -0
- package/lib/character-classifier.js +59 -0
- package/lib/character-classifier.js.map +1 -0
- package/lib/const/encoding.d.ts +10 -0
- package/lib/const/encoding.d.ts.map +1 -0
- package/lib/const/encoding.js +244 -0
- package/lib/const/encoding.js.map +1 -0
- package/lib/const/index.d.ts +2 -0
- package/lib/const/index.d.ts.map +1 -0
- package/lib/const/index.js +5 -0
- package/lib/const/index.js.map +1 -0
- package/lib/date.d.ts +2 -0
- package/lib/date.d.ts.map +1 -0
- package/lib/date.js +22 -0
- package/lib/date.js.map +1 -0
- package/lib/decorators.d.ts +11 -0
- package/lib/decorators.d.ts.map +1 -0
- package/lib/decorators.js +151 -0
- package/lib/decorators.js.map +1 -0
- package/lib/disposable.d.ts +88 -0
- package/lib/disposable.d.ts.map +1 -0
- package/lib/disposable.js +316 -0
- package/lib/disposable.js.map +1 -0
- package/lib/encoding.d.ts +34 -0
- package/lib/encoding.d.ts.map +1 -0
- package/lib/encoding.js +217 -0
- package/lib/encoding.js.map +1 -0
- package/lib/errors.d.ts +56 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +148 -0
- package/lib/errors.js.map +1 -0
- package/lib/event.d.ts +268 -0
- package/lib/event.d.ts.map +1 -0
- package/lib/event.js +816 -0
- package/lib/event.js.map +1 -0
- package/lib/file-uri.d.ts +15 -0
- package/lib/file-uri.d.ts.map +1 -0
- package/lib/file-uri.js +46 -0
- package/lib/file-uri.js.map +1 -0
- package/lib/filters.d.ts +47 -0
- package/lib/filters.d.ts.map +1 -0
- package/lib/filters.js +698 -0
- package/lib/filters.js.map +1 -0
- package/lib/functional.d.ts +4 -0
- package/lib/functional.d.ts.map +1 -0
- package/lib/functional.js +45 -0
- package/lib/functional.js.map +1 -0
- package/lib/glob.d.ts +46 -0
- package/lib/glob.d.ts.map +1 -0
- package/lib/glob.js +561 -0
- package/lib/glob.js.map +1 -0
- package/lib/hash.d.ts +38 -0
- package/lib/hash.d.ts.map +1 -0
- package/lib/hash.js +294 -0
- package/lib/hash.js.map +1 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +45 -0
- package/lib/index.js.map +1 -0
- package/lib/iterator.d.ts +17 -0
- package/lib/iterator.d.ts.map +1 -0
- package/lib/iterator.js +24 -0
- package/lib/iterator.js.map +1 -0
- package/lib/lifecycle.d.ts +17 -0
- package/lib/lifecycle.d.ts.map +1 -0
- package/lib/lifecycle.js +39 -0
- package/lib/lifecycle.js.map +1 -0
- package/lib/linked-list.d.ts +18 -0
- package/lib/linked-list.d.ts.map +1 -0
- package/lib/linked-list.js +138 -0
- package/lib/linked-list.js.map +1 -0
- package/lib/linked-text.d.ts +13 -0
- package/lib/linked-text.d.ts.map +1 -0
- package/lib/linked-text.js +50 -0
- package/lib/linked-text.js.map +1 -0
- package/lib/lru-map.d.ts +41 -0
- package/lib/lru-map.d.ts.map +1 -0
- package/lib/lru-map.js +120 -0
- package/lib/lru-map.js.map +1 -0
- package/lib/map.d.ts +124 -0
- package/lib/map.d.ts.map +1 -0
- package/lib/map.js +819 -0
- package/lib/map.js.map +1 -0
- package/lib/marshalling.d.ts +7 -0
- package/lib/marshalling.d.ts.map +1 -0
- package/lib/marshalling.js +59 -0
- package/lib/marshalling.js.map +1 -0
- package/lib/objects.d.ts +6 -0
- package/lib/objects.d.ts.map +1 -0
- package/lib/objects.js +103 -0
- package/lib/objects.js.map +1 -0
- package/lib/os.d.ts +40 -0
- package/lib/os.d.ts.map +1 -0
- package/lib/os.js +75 -0
- package/lib/os.js.map +1 -0
- package/lib/path.d.ts +101 -0
- package/lib/path.d.ts.map +1 -0
- package/lib/path.js +1747 -0
- package/lib/path.js.map +1 -0
- package/lib/platform.d.ts +48 -0
- package/lib/platform.d.ts.map +1 -0
- package/lib/platform.js +154 -0
- package/lib/platform.js.map +1 -0
- package/lib/process.d.ts +5 -0
- package/lib/process.d.ts.map +1 -0
- package/lib/process.js +23 -0
- package/lib/process.js.map +1 -0
- package/lib/progress.d.ts +56 -0
- package/lib/progress.d.ts.map +1 -0
- package/lib/progress.js +27 -0
- package/lib/progress.js.map +1 -0
- package/lib/promise-util.d.ts +10 -0
- package/lib/promise-util.d.ts.map +1 -0
- package/lib/promise-util.js +17 -0
- package/lib/promise-util.js.map +1 -0
- package/lib/sequence.d.ts +20 -0
- package/lib/sequence.d.ts.map +1 -0
- package/lib/sequence.js +17 -0
- package/lib/sequence.js.map +1 -0
- package/lib/strings.d.ts +181 -0
- package/lib/strings.d.ts.map +1 -0
- package/lib/strings.js +858 -0
- package/lib/strings.js.map +1 -0
- package/lib/types.d.ts +69 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +201 -0
- package/lib/types.js.map +1 -0
- package/lib/uint.d.ts +32 -0
- package/lib/uint.d.ts.map +1 -0
- package/lib/uint.js +28 -0
- package/lib/uint.js.map +1 -0
- package/lib/uri.d.ts +94 -0
- package/lib/uri.d.ts.map +1 -0
- package/lib/uri.js +231 -0
- package/lib/uri.js.map +1 -0
- package/lib/uuid.d.ts +2 -0
- package/lib/uuid.d.ts.map +1 -0
- package/lib/uuid.js +10 -0
- package/lib/uuid.js.map +1 -0
- package/package.json +25 -0
package/lib/map.js
ADDED
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CaseInsensitiveMap = exports.SetMap = exports.LRUCache = exports.LinkedMap = exports.ResourceMap = exports.TernarySearchTree = exports.PathIterator = exports.StringIterator = exports.serializableToMap = exports.mapToSerializable = exports.setToString = exports.mapToString = exports.getOrSet = exports.keys = exports.values = void 0;
|
|
4
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
5
|
+
const iterator_1 = require("./iterator");
|
|
6
|
+
function values(forEachable) {
|
|
7
|
+
const result = [];
|
|
8
|
+
forEachable.forEach((value) => result.push(value));
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
exports.values = values;
|
|
12
|
+
function keys(map) {
|
|
13
|
+
const result = [];
|
|
14
|
+
map.forEach((value, key) => result.push(key));
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
exports.keys = keys;
|
|
18
|
+
function getOrSet(map, key, value) {
|
|
19
|
+
let result = map.get(key);
|
|
20
|
+
if (result === undefined) {
|
|
21
|
+
result = value;
|
|
22
|
+
map.set(key, result);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
exports.getOrSet = getOrSet;
|
|
27
|
+
function mapToString(map) {
|
|
28
|
+
const entries = [];
|
|
29
|
+
map.forEach((value, key) => {
|
|
30
|
+
entries.push(`${key} => ${value}`);
|
|
31
|
+
});
|
|
32
|
+
return `Map(${map.size}) {${entries.join(', ')}}`;
|
|
33
|
+
}
|
|
34
|
+
exports.mapToString = mapToString;
|
|
35
|
+
function setToString(set) {
|
|
36
|
+
const entries = [];
|
|
37
|
+
set.forEach((value) => {
|
|
38
|
+
entries.push(value);
|
|
39
|
+
});
|
|
40
|
+
return `Set(${set.size}) {${entries.join(', ')}}`;
|
|
41
|
+
}
|
|
42
|
+
exports.setToString = setToString;
|
|
43
|
+
function mapToSerializable(map) {
|
|
44
|
+
const serializable = [];
|
|
45
|
+
map.forEach((value, key) => {
|
|
46
|
+
serializable.push([key, value]);
|
|
47
|
+
});
|
|
48
|
+
return serializable;
|
|
49
|
+
}
|
|
50
|
+
exports.mapToSerializable = mapToSerializable;
|
|
51
|
+
function serializableToMap(serializable) {
|
|
52
|
+
const items = new Map();
|
|
53
|
+
for (const [key, value] of serializable) {
|
|
54
|
+
items.set(key, value);
|
|
55
|
+
}
|
|
56
|
+
return items;
|
|
57
|
+
}
|
|
58
|
+
exports.serializableToMap = serializableToMap;
|
|
59
|
+
class StringIterator {
|
|
60
|
+
constructor() {
|
|
61
|
+
this._value = '';
|
|
62
|
+
this._pos = 0;
|
|
63
|
+
}
|
|
64
|
+
reset(key) {
|
|
65
|
+
this._value = key;
|
|
66
|
+
this._pos = 0;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
next() {
|
|
70
|
+
this._pos += 1;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
hasNext() {
|
|
74
|
+
return this._pos < this._value.length - 1;
|
|
75
|
+
}
|
|
76
|
+
cmp(a) {
|
|
77
|
+
const aCode = a.charCodeAt(0);
|
|
78
|
+
const thisCode = this._value.charCodeAt(this._pos);
|
|
79
|
+
return aCode - thisCode;
|
|
80
|
+
}
|
|
81
|
+
value() {
|
|
82
|
+
return this._value[this._pos];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.StringIterator = StringIterator;
|
|
86
|
+
class PathIterator {
|
|
87
|
+
reset(key) {
|
|
88
|
+
this._value = key.replace(/\\$|\/$/, '');
|
|
89
|
+
this._from = 0;
|
|
90
|
+
this._to = 0;
|
|
91
|
+
return this.next();
|
|
92
|
+
}
|
|
93
|
+
hasNext() {
|
|
94
|
+
return this._to < this._value.length;
|
|
95
|
+
}
|
|
96
|
+
next() {
|
|
97
|
+
// this._data = key.split(/[\\/]/).filter(s => !!s);
|
|
98
|
+
this._from = this._to;
|
|
99
|
+
let justSeps = true;
|
|
100
|
+
for (; this._to < this._value.length; this._to++) {
|
|
101
|
+
const ch = this._value.charCodeAt(this._to);
|
|
102
|
+
if (ch === 47 /* Slash */ || ch === 92 /* Backslash */) {
|
|
103
|
+
if (justSeps) {
|
|
104
|
+
this._from++;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
justSeps = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
cmp(a) {
|
|
117
|
+
let aPos = 0;
|
|
118
|
+
const aLen = a.length;
|
|
119
|
+
let thisPos = this._from;
|
|
120
|
+
while (aPos < aLen && thisPos < this._to) {
|
|
121
|
+
const cmp = a.charCodeAt(aPos) - this._value.charCodeAt(thisPos);
|
|
122
|
+
if (cmp !== 0) {
|
|
123
|
+
return cmp;
|
|
124
|
+
}
|
|
125
|
+
aPos += 1;
|
|
126
|
+
thisPos += 1;
|
|
127
|
+
}
|
|
128
|
+
if (aLen === this._to - this._from) {
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
else if (aPos < aLen) {
|
|
132
|
+
return -1;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
value() {
|
|
139
|
+
return this._value.substring(this._from, this._to);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.PathIterator = PathIterator;
|
|
143
|
+
class TernarySearchTreeNode {
|
|
144
|
+
isEmpty() {
|
|
145
|
+
return !this.left && !this.mid && !this.right && !this.value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
class TernarySearchTree {
|
|
149
|
+
constructor(segments) {
|
|
150
|
+
this._iter = segments;
|
|
151
|
+
}
|
|
152
|
+
static forPaths() {
|
|
153
|
+
return new TernarySearchTree(new PathIterator());
|
|
154
|
+
}
|
|
155
|
+
static forStrings() {
|
|
156
|
+
return new TernarySearchTree(new StringIterator());
|
|
157
|
+
}
|
|
158
|
+
clear() {
|
|
159
|
+
this._root = undefined;
|
|
160
|
+
}
|
|
161
|
+
set(key, element) {
|
|
162
|
+
const iter = this._iter.reset(key);
|
|
163
|
+
let node;
|
|
164
|
+
if (!this._root) {
|
|
165
|
+
this._root = new TernarySearchTreeNode();
|
|
166
|
+
this._root.segment = iter.value();
|
|
167
|
+
}
|
|
168
|
+
node = this._root;
|
|
169
|
+
while (true) {
|
|
170
|
+
const val = iter.cmp(node.segment);
|
|
171
|
+
if (val > 0) {
|
|
172
|
+
// left
|
|
173
|
+
if (!node.left) {
|
|
174
|
+
node.left = new TernarySearchTreeNode();
|
|
175
|
+
node.left.segment = iter.value();
|
|
176
|
+
}
|
|
177
|
+
node = node.left;
|
|
178
|
+
}
|
|
179
|
+
else if (val < 0) {
|
|
180
|
+
// right
|
|
181
|
+
if (!node.right) {
|
|
182
|
+
node.right = new TernarySearchTreeNode();
|
|
183
|
+
node.right.segment = iter.value();
|
|
184
|
+
}
|
|
185
|
+
node = node.right;
|
|
186
|
+
}
|
|
187
|
+
else if (iter.hasNext()) {
|
|
188
|
+
// mid
|
|
189
|
+
iter.next();
|
|
190
|
+
if (!node.mid) {
|
|
191
|
+
node.mid = new TernarySearchTreeNode();
|
|
192
|
+
node.mid.segment = iter.value();
|
|
193
|
+
}
|
|
194
|
+
node = node.mid;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const oldElement = node.value;
|
|
201
|
+
node.value = element;
|
|
202
|
+
node.key = key;
|
|
203
|
+
return oldElement;
|
|
204
|
+
}
|
|
205
|
+
get(key) {
|
|
206
|
+
const iter = this._iter.reset(key);
|
|
207
|
+
let node = this._root;
|
|
208
|
+
while (node) {
|
|
209
|
+
const val = iter.cmp(node.segment);
|
|
210
|
+
if (val > 0) {
|
|
211
|
+
// left
|
|
212
|
+
node = node.left;
|
|
213
|
+
}
|
|
214
|
+
else if (val < 0) {
|
|
215
|
+
// right
|
|
216
|
+
node = node.right;
|
|
217
|
+
}
|
|
218
|
+
else if (iter.hasNext()) {
|
|
219
|
+
// mid
|
|
220
|
+
iter.next();
|
|
221
|
+
node = node.mid;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return node ? node.value : undefined;
|
|
228
|
+
}
|
|
229
|
+
delete(key) {
|
|
230
|
+
const iter = this._iter.reset(key);
|
|
231
|
+
const stack = [];
|
|
232
|
+
let node = this._root;
|
|
233
|
+
// find and unset node
|
|
234
|
+
while (node) {
|
|
235
|
+
const val = iter.cmp(node.segment);
|
|
236
|
+
if (val > 0) {
|
|
237
|
+
// left
|
|
238
|
+
stack.push([1, node]);
|
|
239
|
+
node = node.left;
|
|
240
|
+
}
|
|
241
|
+
else if (val < 0) {
|
|
242
|
+
// right
|
|
243
|
+
stack.push([-1, node]);
|
|
244
|
+
node = node.right;
|
|
245
|
+
}
|
|
246
|
+
else if (iter.hasNext()) {
|
|
247
|
+
// mid
|
|
248
|
+
iter.next();
|
|
249
|
+
stack.push([0, node]);
|
|
250
|
+
node = node.mid;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
// remove element
|
|
254
|
+
node.value = undefined;
|
|
255
|
+
// clean up empty nodes
|
|
256
|
+
while (stack.length > 0 && node.isEmpty()) {
|
|
257
|
+
const [dir, parent] = stack.pop();
|
|
258
|
+
switch (dir) {
|
|
259
|
+
case 1:
|
|
260
|
+
parent.left = undefined;
|
|
261
|
+
break;
|
|
262
|
+
case 0:
|
|
263
|
+
parent.mid = undefined;
|
|
264
|
+
break;
|
|
265
|
+
case -1:
|
|
266
|
+
parent.right = undefined;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
node = parent;
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
findSubstr(key) {
|
|
276
|
+
const iter = this._iter.reset(key);
|
|
277
|
+
let node = this._root;
|
|
278
|
+
let candidate;
|
|
279
|
+
while (node) {
|
|
280
|
+
const val = iter.cmp(node.segment);
|
|
281
|
+
if (val > 0) {
|
|
282
|
+
// left
|
|
283
|
+
node = node.left;
|
|
284
|
+
}
|
|
285
|
+
else if (val < 0) {
|
|
286
|
+
// right
|
|
287
|
+
node = node.right;
|
|
288
|
+
}
|
|
289
|
+
else if (iter.hasNext()) {
|
|
290
|
+
// mid
|
|
291
|
+
iter.next();
|
|
292
|
+
candidate = node.value || candidate;
|
|
293
|
+
node = node.mid;
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return (node && node.value) || candidate;
|
|
300
|
+
}
|
|
301
|
+
findSuperstr(key) {
|
|
302
|
+
const iter = this._iter.reset(key);
|
|
303
|
+
let node = this._root;
|
|
304
|
+
while (node) {
|
|
305
|
+
const val = iter.cmp(node.segment);
|
|
306
|
+
if (val > 0) {
|
|
307
|
+
// left
|
|
308
|
+
node = node.left;
|
|
309
|
+
}
|
|
310
|
+
else if (val < 0) {
|
|
311
|
+
// right
|
|
312
|
+
node = node.right;
|
|
313
|
+
}
|
|
314
|
+
else if (iter.hasNext()) {
|
|
315
|
+
// mid
|
|
316
|
+
iter.next();
|
|
317
|
+
node = node.mid;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
// collect
|
|
321
|
+
if (!node.mid) {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return this._nodeIterator(node.mid);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
_nodeIterator(node) {
|
|
332
|
+
let res;
|
|
333
|
+
let idx;
|
|
334
|
+
let data;
|
|
335
|
+
const next = () => {
|
|
336
|
+
if (!data) {
|
|
337
|
+
// lazy till first invocation
|
|
338
|
+
data = [];
|
|
339
|
+
idx = 0;
|
|
340
|
+
this._forEach(node, (value) => data.push(value));
|
|
341
|
+
}
|
|
342
|
+
if (idx >= data.length) {
|
|
343
|
+
return iterator_1.FIN;
|
|
344
|
+
}
|
|
345
|
+
if (!res) {
|
|
346
|
+
res = { done: false, value: data[idx++] };
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
res.value = data[idx++];
|
|
350
|
+
}
|
|
351
|
+
return res;
|
|
352
|
+
};
|
|
353
|
+
return { next };
|
|
354
|
+
}
|
|
355
|
+
forEach(callback) {
|
|
356
|
+
this._forEach(this._root, callback);
|
|
357
|
+
}
|
|
358
|
+
_forEach(node, callback) {
|
|
359
|
+
if (node) {
|
|
360
|
+
// left
|
|
361
|
+
this._forEach(node.left, callback);
|
|
362
|
+
// node
|
|
363
|
+
if (node.value) {
|
|
364
|
+
// callback(node.value, this._iter.join(parts));
|
|
365
|
+
callback(node.value, node.key);
|
|
366
|
+
}
|
|
367
|
+
// mid
|
|
368
|
+
this._forEach(node.mid, callback);
|
|
369
|
+
// right
|
|
370
|
+
this._forEach(node.right, callback);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
exports.TernarySearchTree = TernarySearchTree;
|
|
375
|
+
class ResourceMap {
|
|
376
|
+
constructor() {
|
|
377
|
+
this.map = new Map();
|
|
378
|
+
this.ignoreCase = false; // in the future this should be an uri-comparator
|
|
379
|
+
}
|
|
380
|
+
set(resource, value) {
|
|
381
|
+
this.map.set(this.toKey(resource), value);
|
|
382
|
+
}
|
|
383
|
+
get(resource) {
|
|
384
|
+
return this.map.get(this.toKey(resource));
|
|
385
|
+
}
|
|
386
|
+
has(resource) {
|
|
387
|
+
return this.map.has(this.toKey(resource));
|
|
388
|
+
}
|
|
389
|
+
get size() {
|
|
390
|
+
return this.map.size;
|
|
391
|
+
}
|
|
392
|
+
clear() {
|
|
393
|
+
this.map.clear();
|
|
394
|
+
}
|
|
395
|
+
delete(resource) {
|
|
396
|
+
return this.map.delete(this.toKey(resource));
|
|
397
|
+
}
|
|
398
|
+
forEach(clb) {
|
|
399
|
+
this.map.forEach(clb);
|
|
400
|
+
}
|
|
401
|
+
values() {
|
|
402
|
+
return values(this.map);
|
|
403
|
+
}
|
|
404
|
+
toKey(resource) {
|
|
405
|
+
let key = resource.toString();
|
|
406
|
+
if (this.ignoreCase) {
|
|
407
|
+
key = key.toLowerCase();
|
|
408
|
+
}
|
|
409
|
+
return key;
|
|
410
|
+
}
|
|
411
|
+
keys() {
|
|
412
|
+
return keys(this.map).map((k) => vscode_uri_1.URI.parse(k));
|
|
413
|
+
}
|
|
414
|
+
clone() {
|
|
415
|
+
const resourceMap = new ResourceMap();
|
|
416
|
+
this.map.forEach((value, key) => resourceMap.map.set(key, value));
|
|
417
|
+
return resourceMap;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
exports.ResourceMap = ResourceMap;
|
|
421
|
+
class LinkedMap {
|
|
422
|
+
constructor() {
|
|
423
|
+
this._map = new Map();
|
|
424
|
+
this._head = undefined;
|
|
425
|
+
this._tail = undefined;
|
|
426
|
+
this._size = 0;
|
|
427
|
+
}
|
|
428
|
+
clear() {
|
|
429
|
+
this._map.clear();
|
|
430
|
+
this._head = undefined;
|
|
431
|
+
this._tail = undefined;
|
|
432
|
+
this._size = 0;
|
|
433
|
+
}
|
|
434
|
+
isEmpty() {
|
|
435
|
+
return !this._head && !this._tail;
|
|
436
|
+
}
|
|
437
|
+
get size() {
|
|
438
|
+
return this._size;
|
|
439
|
+
}
|
|
440
|
+
has(key) {
|
|
441
|
+
return this._map.has(key);
|
|
442
|
+
}
|
|
443
|
+
get(key, touch = 0 /* None */) {
|
|
444
|
+
const item = this._map.get(key);
|
|
445
|
+
if (!item) {
|
|
446
|
+
return undefined;
|
|
447
|
+
}
|
|
448
|
+
if (touch !== 0 /* None */) {
|
|
449
|
+
this.touch(item, touch);
|
|
450
|
+
}
|
|
451
|
+
return item.value;
|
|
452
|
+
}
|
|
453
|
+
set(key, value, touch = 0 /* None */) {
|
|
454
|
+
let item = this._map.get(key);
|
|
455
|
+
if (item) {
|
|
456
|
+
item.value = value;
|
|
457
|
+
if (touch !== 0 /* None */) {
|
|
458
|
+
this.touch(item, touch);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
item = { key, value, next: undefined, previous: undefined };
|
|
463
|
+
switch (touch) {
|
|
464
|
+
case 0 /* None */:
|
|
465
|
+
this.addItemLast(item);
|
|
466
|
+
break;
|
|
467
|
+
case 1 /* AsOld */:
|
|
468
|
+
this.addItemFirst(item);
|
|
469
|
+
break;
|
|
470
|
+
case 2 /* AsNew */:
|
|
471
|
+
this.addItemLast(item);
|
|
472
|
+
break;
|
|
473
|
+
default:
|
|
474
|
+
this.addItemLast(item);
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
this._map.set(key, item);
|
|
478
|
+
this._size++;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
delete(key) {
|
|
482
|
+
return !!this.remove(key);
|
|
483
|
+
}
|
|
484
|
+
remove(key) {
|
|
485
|
+
const item = this._map.get(key);
|
|
486
|
+
if (!item) {
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
this._map.delete(key);
|
|
490
|
+
this.removeItem(item);
|
|
491
|
+
this._size--;
|
|
492
|
+
return item.value;
|
|
493
|
+
}
|
|
494
|
+
shift() {
|
|
495
|
+
if (!this._head && !this._tail) {
|
|
496
|
+
return undefined;
|
|
497
|
+
}
|
|
498
|
+
if (!this._head || !this._tail) {
|
|
499
|
+
throw new Error('Invalid list');
|
|
500
|
+
}
|
|
501
|
+
const item = this._head;
|
|
502
|
+
this._map.delete(item.key);
|
|
503
|
+
this.removeItem(item);
|
|
504
|
+
this._size--;
|
|
505
|
+
return item.value;
|
|
506
|
+
}
|
|
507
|
+
forEach(callbackfn, thisArg) {
|
|
508
|
+
let current = this._head;
|
|
509
|
+
while (current) {
|
|
510
|
+
if (thisArg) {
|
|
511
|
+
callbackfn.bind(thisArg)(current.value, current.key, this);
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
callbackfn(current.value, current.key, this);
|
|
515
|
+
}
|
|
516
|
+
current = current.next;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
values() {
|
|
520
|
+
const result = [];
|
|
521
|
+
let current = this._head;
|
|
522
|
+
while (current) {
|
|
523
|
+
result.push(current.value);
|
|
524
|
+
current = current.next;
|
|
525
|
+
}
|
|
526
|
+
return result;
|
|
527
|
+
}
|
|
528
|
+
keys() {
|
|
529
|
+
const result = [];
|
|
530
|
+
let current = this._head;
|
|
531
|
+
while (current) {
|
|
532
|
+
result.push(current.key);
|
|
533
|
+
current = current.next;
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
/* VS Code / Monaco editor runs on es5 which has no Symbol.iterator
|
|
538
|
+
keys(): IterableIterator<K> {
|
|
539
|
+
const current = this._head;
|
|
540
|
+
const iterator: IterableIterator<K> = {
|
|
541
|
+
[Symbol.iterator]() {
|
|
542
|
+
return iterator;
|
|
543
|
+
},
|
|
544
|
+
next():IteratorResult<K> {
|
|
545
|
+
if (current) {
|
|
546
|
+
const result = { value: current.key, done: false };
|
|
547
|
+
current = current.next;
|
|
548
|
+
return result;
|
|
549
|
+
} else {
|
|
550
|
+
return { value: undefined, done: true };
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
return iterator;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
values(): IterableIterator<V> {
|
|
558
|
+
const current = this._head;
|
|
559
|
+
const iterator: IterableIterator<V> = {
|
|
560
|
+
[Symbol.iterator]() {
|
|
561
|
+
return iterator;
|
|
562
|
+
},
|
|
563
|
+
next():IteratorResult<V> {
|
|
564
|
+
if (current) {
|
|
565
|
+
const result = { value: current.value, done: false };
|
|
566
|
+
current = current.next;
|
|
567
|
+
return result;
|
|
568
|
+
} else {
|
|
569
|
+
return { value: undefined, done: true };
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
return iterator;
|
|
574
|
+
}
|
|
575
|
+
*/
|
|
576
|
+
trimOld(newSize) {
|
|
577
|
+
if (newSize >= this.size) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (newSize === 0) {
|
|
581
|
+
this.clear();
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
let current = this._head;
|
|
585
|
+
let currentSize = this.size;
|
|
586
|
+
while (current && currentSize > newSize) {
|
|
587
|
+
this._map.delete(current.key);
|
|
588
|
+
current = current.next;
|
|
589
|
+
currentSize--;
|
|
590
|
+
}
|
|
591
|
+
this._head = current;
|
|
592
|
+
this._size = currentSize;
|
|
593
|
+
if (current) {
|
|
594
|
+
current.previous = undefined;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
addItemFirst(item) {
|
|
598
|
+
// First time Insert
|
|
599
|
+
if (!this._head && !this._tail) {
|
|
600
|
+
this._tail = item;
|
|
601
|
+
}
|
|
602
|
+
else if (!this._head) {
|
|
603
|
+
throw new Error('Invalid list');
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
item.next = this._head;
|
|
607
|
+
this._head.previous = item;
|
|
608
|
+
}
|
|
609
|
+
this._head = item;
|
|
610
|
+
}
|
|
611
|
+
addItemLast(item) {
|
|
612
|
+
// First time Insert
|
|
613
|
+
if (!this._head && !this._tail) {
|
|
614
|
+
this._head = item;
|
|
615
|
+
}
|
|
616
|
+
else if (!this._tail) {
|
|
617
|
+
throw new Error('Invalid list');
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
item.previous = this._tail;
|
|
621
|
+
this._tail.next = item;
|
|
622
|
+
}
|
|
623
|
+
this._tail = item;
|
|
624
|
+
}
|
|
625
|
+
removeItem(item) {
|
|
626
|
+
if (item === this._head && item === this._tail) {
|
|
627
|
+
this._head = undefined;
|
|
628
|
+
this._tail = undefined;
|
|
629
|
+
}
|
|
630
|
+
else if (item === this._head) {
|
|
631
|
+
// This can only happend if size === 1 which is handle
|
|
632
|
+
// by the case above.
|
|
633
|
+
if (!item.next) {
|
|
634
|
+
throw new Error('Invalid list');
|
|
635
|
+
}
|
|
636
|
+
item.next.previous = undefined;
|
|
637
|
+
this._head = item.next;
|
|
638
|
+
}
|
|
639
|
+
else if (item === this._tail) {
|
|
640
|
+
// This can only happend if size === 1 which is handle
|
|
641
|
+
// by the case above.
|
|
642
|
+
if (!item.previous) {
|
|
643
|
+
throw new Error('Invalid list');
|
|
644
|
+
}
|
|
645
|
+
item.previous.next = undefined;
|
|
646
|
+
this._tail = item.previous;
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
const next = item.next;
|
|
650
|
+
const previous = item.previous;
|
|
651
|
+
if (!next || !previous) {
|
|
652
|
+
throw new Error('Invalid list');
|
|
653
|
+
}
|
|
654
|
+
next.previous = previous;
|
|
655
|
+
previous.next = next;
|
|
656
|
+
}
|
|
657
|
+
item.next = undefined;
|
|
658
|
+
item.previous = undefined;
|
|
659
|
+
}
|
|
660
|
+
touch(item, touch) {
|
|
661
|
+
if (!this._head || !this._tail) {
|
|
662
|
+
throw new Error('Invalid list');
|
|
663
|
+
}
|
|
664
|
+
if (touch !== 1 /* AsOld */ && touch !== 2 /* AsNew */) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (touch === 1 /* AsOld */) {
|
|
668
|
+
if (item === this._head) {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const next = item.next;
|
|
672
|
+
const previous = item.previous;
|
|
673
|
+
// Unlink the item
|
|
674
|
+
if (item === this._tail) {
|
|
675
|
+
// previous must be defined since item was not head but is tail
|
|
676
|
+
// So there are more than on item in the map
|
|
677
|
+
previous.next = undefined;
|
|
678
|
+
this._tail = previous;
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
// Both next and previous are not undefined since item was neither head nor tail.
|
|
682
|
+
next.previous = previous;
|
|
683
|
+
previous.next = next;
|
|
684
|
+
}
|
|
685
|
+
// Insert the node at head
|
|
686
|
+
item.previous = undefined;
|
|
687
|
+
item.next = this._head;
|
|
688
|
+
this._head.previous = item;
|
|
689
|
+
this._head = item;
|
|
690
|
+
}
|
|
691
|
+
else if (touch === 2 /* AsNew */) {
|
|
692
|
+
if (item === this._tail) {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const next = item.next;
|
|
696
|
+
const previous = item.previous;
|
|
697
|
+
// Unlink the item.
|
|
698
|
+
if (item === this._head) {
|
|
699
|
+
// next must be defined since item was not tail but is head
|
|
700
|
+
// So there are more than on item in the map
|
|
701
|
+
next.previous = undefined;
|
|
702
|
+
this._head = next;
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
// Both next and previous are not undefined since item was neither head nor tail.
|
|
706
|
+
next.previous = previous;
|
|
707
|
+
previous.next = next;
|
|
708
|
+
}
|
|
709
|
+
item.next = undefined;
|
|
710
|
+
item.previous = this._tail;
|
|
711
|
+
this._tail.next = item;
|
|
712
|
+
this._tail = item;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
toJSON() {
|
|
716
|
+
const data = [];
|
|
717
|
+
this.forEach((value, key) => {
|
|
718
|
+
data.push([key, value]);
|
|
719
|
+
});
|
|
720
|
+
return data;
|
|
721
|
+
}
|
|
722
|
+
fromJSON(data) {
|
|
723
|
+
this.clear();
|
|
724
|
+
for (const [key, value] of data) {
|
|
725
|
+
this.set(key, value);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
exports.LinkedMap = LinkedMap;
|
|
730
|
+
class LRUCache extends LinkedMap {
|
|
731
|
+
constructor(limit, ratio = 1) {
|
|
732
|
+
super();
|
|
733
|
+
this._limit = limit;
|
|
734
|
+
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
735
|
+
}
|
|
736
|
+
get limit() {
|
|
737
|
+
return this._limit;
|
|
738
|
+
}
|
|
739
|
+
set limit(limit) {
|
|
740
|
+
this._limit = limit;
|
|
741
|
+
this.checkTrim();
|
|
742
|
+
}
|
|
743
|
+
get ratio() {
|
|
744
|
+
return this._ratio;
|
|
745
|
+
}
|
|
746
|
+
set ratio(ratio) {
|
|
747
|
+
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
748
|
+
this.checkTrim();
|
|
749
|
+
}
|
|
750
|
+
get(key) {
|
|
751
|
+
return super.get(key, 2 /* AsNew */);
|
|
752
|
+
}
|
|
753
|
+
peek(key) {
|
|
754
|
+
return super.get(key, 0 /* None */);
|
|
755
|
+
}
|
|
756
|
+
set(key, value) {
|
|
757
|
+
super.set(key, value, 2 /* AsNew */);
|
|
758
|
+
this.checkTrim();
|
|
759
|
+
}
|
|
760
|
+
checkTrim() {
|
|
761
|
+
if (this.size > this._limit) {
|
|
762
|
+
this.trimOld(Math.round(this._limit * this._ratio));
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
exports.LRUCache = LRUCache;
|
|
767
|
+
class SetMap {
|
|
768
|
+
constructor() {
|
|
769
|
+
this.map = new Map();
|
|
770
|
+
}
|
|
771
|
+
add(key, value) {
|
|
772
|
+
let values = this.map.get(key);
|
|
773
|
+
if (!values) {
|
|
774
|
+
values = new Set();
|
|
775
|
+
this.map.set(key, values);
|
|
776
|
+
}
|
|
777
|
+
values.add(value);
|
|
778
|
+
}
|
|
779
|
+
delete(key, value) {
|
|
780
|
+
const values = this.map.get(key);
|
|
781
|
+
if (!values) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
values.delete(value);
|
|
785
|
+
if (values.size === 0) {
|
|
786
|
+
this.map.delete(key);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
forEach(key, fn) {
|
|
790
|
+
const values = this.map.get(key);
|
|
791
|
+
if (!values) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
values.forEach(fn);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
exports.SetMap = SetMap;
|
|
798
|
+
class CaseInsensitiveMap extends Map {
|
|
799
|
+
set(key, value) {
|
|
800
|
+
if (typeof key === 'string') {
|
|
801
|
+
key = key.toLowerCase();
|
|
802
|
+
}
|
|
803
|
+
return super.set(key, value);
|
|
804
|
+
}
|
|
805
|
+
get(key) {
|
|
806
|
+
if (typeof key === 'string') {
|
|
807
|
+
key = key.toLowerCase();
|
|
808
|
+
}
|
|
809
|
+
return super.get(key);
|
|
810
|
+
}
|
|
811
|
+
has(key) {
|
|
812
|
+
if (typeof key === 'string') {
|
|
813
|
+
key = key.toLowerCase();
|
|
814
|
+
}
|
|
815
|
+
return super.has(key);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
exports.CaseInsensitiveMap = CaseInsensitiveMap;
|
|
819
|
+
//# sourceMappingURL=map.js.map
|