@opensumi/ide-utils 2.21.13 → 2.22.0

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.
Files changed (114) hide show
  1. package/lib/arrays.d.ts +3 -3
  2. package/lib/arrays.d.ts.map +1 -1
  3. package/lib/arrays.js.map +1 -1
  4. package/lib/async.d.ts +3 -3
  5. package/lib/async.d.ts.map +1 -1
  6. package/lib/buffer.js +4 -4
  7. package/lib/buffer.js.map +1 -1
  8. package/lib/character-classifier.js +3 -3
  9. package/lib/character-classifier.js.map +1 -1
  10. package/lib/decorators.d.ts +1 -1
  11. package/lib/decorators.d.ts.map +1 -1
  12. package/lib/encoding.d.ts +7 -1
  13. package/lib/encoding.d.ts.map +1 -1
  14. package/lib/encoding.js +15 -2
  15. package/lib/encoding.js.map +1 -1
  16. package/lib/errors.d.ts +2 -2
  17. package/lib/errors.d.ts.map +1 -1
  18. package/lib/event.d.ts +2 -2
  19. package/lib/event.d.ts.map +1 -1
  20. package/lib/filters.d.ts +3 -3
  21. package/lib/filters.d.ts.map +1 -1
  22. package/lib/filters.js +25 -25
  23. package/lib/filters.js.map +1 -1
  24. package/lib/glob.d.ts +2 -2
  25. package/lib/glob.d.ts.map +1 -1
  26. package/lib/glob.js +1 -1
  27. package/lib/glob.js.map +1 -1
  28. package/lib/hash.js +10 -10
  29. package/lib/hash.js.map +1 -1
  30. package/lib/iterator.d.ts +1 -1
  31. package/lib/iterator.d.ts.map +1 -1
  32. package/lib/linked-text.d.ts +1 -1
  33. package/lib/linked-text.d.ts.map +1 -1
  34. package/lib/linked-text.js.map +1 -1
  35. package/lib/map.js +17 -17
  36. package/lib/map.js.map +1 -1
  37. package/lib/objects.d.ts +1 -0
  38. package/lib/objects.d.ts.map +1 -1
  39. package/lib/objects.js +38 -1
  40. package/lib/objects.js.map +1 -1
  41. package/lib/os.d.ts +1 -8
  42. package/lib/os.d.ts.map +1 -1
  43. package/lib/os.js +4 -8
  44. package/lib/os.js.map +1 -1
  45. package/lib/path.d.ts +1 -1
  46. package/lib/path.d.ts.map +1 -1
  47. package/lib/path.js +29 -29
  48. package/lib/path.js.map +1 -1
  49. package/lib/platform.js +8 -8
  50. package/lib/platform.js.map +1 -1
  51. package/lib/process.d.ts.map +1 -1
  52. package/lib/process.js +28 -13
  53. package/lib/process.js.map +1 -1
  54. package/lib/progress.js +3 -3
  55. package/lib/progress.js.map +1 -1
  56. package/lib/strings.js +9 -9
  57. package/lib/strings.js.map +1 -1
  58. package/lib/types.d.ts +5 -1
  59. package/lib/types.d.ts.map +1 -1
  60. package/lib/types.js +8 -1
  61. package/lib/types.js.map +1 -1
  62. package/lib/uint.js +4 -4
  63. package/lib/uint.js.map +1 -1
  64. package/lib/uri.js +8 -8
  65. package/lib/uri.js.map +1 -1
  66. package/lib/uuid.d.ts +1 -1
  67. package/lib/uuid.d.ts.map +1 -1
  68. package/lib/uuid.js +3 -2
  69. package/lib/uuid.js.map +1 -1
  70. package/package.json +8 -6
  71. package/src/ansi.ts +10 -0
  72. package/src/argv.ts +57 -0
  73. package/src/arrays.ts +328 -0
  74. package/src/async.ts +580 -0
  75. package/src/buffer.ts +290 -0
  76. package/src/cache.ts +37 -0
  77. package/src/cancellation.ts +136 -0
  78. package/src/charCode.ts +425 -0
  79. package/src/character-classifier.ts +82 -0
  80. package/src/const/encoding.ts +242 -0
  81. package/src/const/index.ts +1 -0
  82. package/src/date.ts +36 -0
  83. package/src/decorators.ts +166 -0
  84. package/src/disposable.ts +377 -0
  85. package/src/encoding.ts +278 -0
  86. package/src/errors.ts +192 -0
  87. package/src/event.ts +1024 -0
  88. package/src/file-uri.ts +41 -0
  89. package/src/filters.ts +887 -0
  90. package/src/functional.ts +43 -0
  91. package/src/glob.ts +752 -0
  92. package/src/hash.ts +336 -0
  93. package/src/iconLabels.ts +149 -0
  94. package/src/index.ts +40 -0
  95. package/src/iterator.ts +36 -0
  96. package/src/lifecycle.ts +48 -0
  97. package/src/linked-list.ts +144 -0
  98. package/src/linked-text.ts +55 -0
  99. package/src/lru-map.ts +133 -0
  100. package/src/map.ts +934 -0
  101. package/src/marshalling.ts +62 -0
  102. package/src/objects.ts +145 -0
  103. package/src/os.ts +76 -0
  104. package/src/path.ts +1885 -0
  105. package/src/platform.ts +194 -0
  106. package/src/process.ts +43 -0
  107. package/src/progress.ts +83 -0
  108. package/src/promises.ts +23 -0
  109. package/src/sequence.ts +28 -0
  110. package/src/strings.ts +1002 -0
  111. package/src/types.ts +214 -0
  112. package/src/uint.ts +59 -0
  113. package/src/uri.ts +298 -0
  114. package/src/uuid.ts +6 -0
package/src/hash.ts ADDED
@@ -0,0 +1,336 @@
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 * as strings from './strings';
7
+
8
+ /**
9
+ * Return a hash value for an object.
10
+ */
11
+ export function hash(obj: any): number {
12
+ return doHash(obj, 0);
13
+ }
14
+
15
+ export function doHash(obj: any, hashVal: number): number {
16
+ switch (typeof obj) {
17
+ case 'object':
18
+ if (obj === null) {
19
+ return numberHash(349, hashVal);
20
+ } else if (Array.isArray(obj)) {
21
+ return arrayHash(obj, hashVal);
22
+ }
23
+ return objectHash(obj, hashVal);
24
+ case 'string':
25
+ return stringHash(obj, hashVal);
26
+ case 'boolean':
27
+ return booleanHash(obj, hashVal);
28
+ case 'number':
29
+ return numberHash(obj, hashVal);
30
+ case 'undefined':
31
+ return numberHash(937, hashVal);
32
+ default:
33
+ return numberHash(617, hashVal);
34
+ }
35
+ }
36
+
37
+ export function numberHash(val: number, initialHashVal: number): number {
38
+ return ((initialHashVal << 5) - initialHashVal + val) | 0; // hashVal * 31 + ch, keep as int32
39
+ }
40
+
41
+ function booleanHash(b: boolean, initialHashVal: number): number {
42
+ return numberHash(b ? 433 : 863, initialHashVal);
43
+ }
44
+
45
+ export function stringHash(s: string, hashVal: number) {
46
+ hashVal = numberHash(149417, hashVal);
47
+ for (let i = 0, length = s.length; i < length; i++) {
48
+ hashVal = numberHash(s.charCodeAt(i), hashVal);
49
+ }
50
+ return hashVal;
51
+ }
52
+
53
+ function arrayHash(arr: any[], initialHashVal: number): number {
54
+ initialHashVal = numberHash(104579, initialHashVal);
55
+ return arr.reduce((hashVal, item) => doHash(item, hashVal), initialHashVal);
56
+ }
57
+
58
+ function objectHash(obj: any, initialHashVal: number): number {
59
+ initialHashVal = numberHash(181387, initialHashVal);
60
+ return Object.keys(obj)
61
+ .sort()
62
+ .reduce((hashVal, key) => {
63
+ hashVal = stringHash(key, hashVal);
64
+ return doHash(obj[key], hashVal);
65
+ }, initialHashVal);
66
+ }
67
+
68
+ export class Hasher {
69
+ private _value = 0;
70
+
71
+ get value(): number {
72
+ return this._value;
73
+ }
74
+
75
+ hash(obj: any): number {
76
+ this._value = doHash(obj, this._value);
77
+ return this._value;
78
+ }
79
+ }
80
+
81
+ const enum SHA1Constant {
82
+ BLOCK_SIZE = 64, // 512 / 8
83
+ UNICODE_REPLACEMENT = 0xfffd,
84
+ }
85
+
86
+ function leftRotate(value: number, bits: number, totalBits = 32): number {
87
+ // delta + bits = totalBits
88
+ const delta = totalBits - bits;
89
+
90
+ // All ones, expect `delta` zeros aligned to the right
91
+ const mask = ~((1 << delta) - 1);
92
+
93
+ // Join (value left-shifted `bits` bits) with (masked value right-shifted `delta` bits)
94
+ return ((value << bits) | ((mask & value) >>> delta)) >>> 0;
95
+ }
96
+
97
+ function fill(dest: Uint8Array, index = 0, count: number = dest.byteLength, value = 0): void {
98
+ for (let i = 0; i < count; i++) {
99
+ dest[index + i] = value;
100
+ }
101
+ }
102
+
103
+ function leftPad(value: string, length: number, char = '0'): string {
104
+ while (value.length < length) {
105
+ value = char + value;
106
+ }
107
+ return value;
108
+ }
109
+
110
+ export function toHexString(buffer: ArrayBuffer): string;
111
+ export function toHexString(value: number, bitsize?: number): string;
112
+ export function toHexString(bufferOrValue: ArrayBuffer | number, bitsize = 32): string {
113
+ if (bufferOrValue instanceof ArrayBuffer) {
114
+ return Array.from(new Uint8Array(bufferOrValue))
115
+ .map((b) => b.toString(16).padStart(2, '0'))
116
+ .join('');
117
+ }
118
+
119
+ return leftPad((bufferOrValue >>> 0).toString(16), bitsize / 4);
120
+ }
121
+
122
+ /**
123
+ * A SHA1 implementation that works with strings and does not allocate.
124
+ */
125
+ export class StringSHA1 {
126
+ private static _bigBlock32 = new DataView(new ArrayBuffer(320)); // 80 * 4 = 320
127
+
128
+ private _h0 = 0x67452301;
129
+ private _h1 = 0xefcdab89;
130
+ private _h2 = 0x98badcfe;
131
+ private _h3 = 0x10325476;
132
+ private _h4 = 0xc3d2e1f0;
133
+
134
+ private readonly _buff: Uint8Array;
135
+ private readonly _buffDV: DataView;
136
+ private _buffLen: number;
137
+ private _totalLen: number;
138
+ private _leftoverHighSurrogate: number;
139
+ private _finished: boolean;
140
+
141
+ constructor() {
142
+ this._buff = new Uint8Array(SHA1Constant.BLOCK_SIZE + 3 /* to fit any utf-8 */);
143
+ this._buffDV = new DataView(this._buff.buffer);
144
+ this._buffLen = 0;
145
+ this._totalLen = 0;
146
+ this._leftoverHighSurrogate = 0;
147
+ this._finished = false;
148
+ }
149
+
150
+ public update(str: string): void {
151
+ const strLen = str.length;
152
+ if (strLen === 0) {
153
+ return;
154
+ }
155
+
156
+ const buff = this._buff;
157
+ let buffLen = this._buffLen;
158
+ let leftoverHighSurrogate = this._leftoverHighSurrogate;
159
+ let charCode: number;
160
+ let offset: number;
161
+
162
+ if (leftoverHighSurrogate !== 0) {
163
+ charCode = leftoverHighSurrogate;
164
+ offset = -1;
165
+ leftoverHighSurrogate = 0;
166
+ } else {
167
+ charCode = str.charCodeAt(0);
168
+ offset = 0;
169
+ }
170
+
171
+ while (true) {
172
+ let codePoint = charCode;
173
+ if (strings.isHighSurrogate(charCode)) {
174
+ if (offset + 1 < strLen) {
175
+ const nextCharCode = str.charCodeAt(offset + 1);
176
+ if (strings.isLowSurrogate(nextCharCode)) {
177
+ offset++;
178
+ codePoint = strings.computeCodePoint(charCode, nextCharCode);
179
+ } else {
180
+ // illegal => unicode replacement character
181
+ codePoint = SHA1Constant.UNICODE_REPLACEMENT;
182
+ }
183
+ } else {
184
+ // last character is a surrogate pair
185
+ leftoverHighSurrogate = charCode;
186
+ break;
187
+ }
188
+ } else if (strings.isLowSurrogate(charCode)) {
189
+ // illegal => unicode replacement character
190
+ codePoint = SHA1Constant.UNICODE_REPLACEMENT;
191
+ }
192
+
193
+ buffLen = this._push(buff, buffLen, codePoint);
194
+ offset++;
195
+ if (offset < strLen) {
196
+ charCode = str.charCodeAt(offset);
197
+ } else {
198
+ break;
199
+ }
200
+ }
201
+
202
+ this._buffLen = buffLen;
203
+ this._leftoverHighSurrogate = leftoverHighSurrogate;
204
+ }
205
+
206
+ private _push(buff: Uint8Array, buffLen: number, codePoint: number): number {
207
+ if (codePoint < 0x0080) {
208
+ buff[buffLen++] = codePoint;
209
+ } else if (codePoint < 0x0800) {
210
+ buff[buffLen++] = 0b11000000 | ((codePoint & 0b00000000000000000000011111000000) >>> 6);
211
+ buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
212
+ } else if (codePoint < 0x10000) {
213
+ buff[buffLen++] = 0b11100000 | ((codePoint & 0b00000000000000001111000000000000) >>> 12);
214
+ buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6);
215
+ buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
216
+ } else {
217
+ buff[buffLen++] = 0b11110000 | ((codePoint & 0b00000000000111000000000000000000) >>> 18);
218
+ buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000111111000000000000) >>> 12);
219
+ buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6);
220
+ buff[buffLen++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
221
+ }
222
+
223
+ if (buffLen >= SHA1Constant.BLOCK_SIZE) {
224
+ this._step();
225
+ buffLen -= SHA1Constant.BLOCK_SIZE;
226
+ this._totalLen += SHA1Constant.BLOCK_SIZE;
227
+ // take last 3 in case of UTF8 overflow
228
+ buff[0] = buff[SHA1Constant.BLOCK_SIZE + 0];
229
+ buff[1] = buff[SHA1Constant.BLOCK_SIZE + 1];
230
+ buff[2] = buff[SHA1Constant.BLOCK_SIZE + 2];
231
+ }
232
+
233
+ return buffLen;
234
+ }
235
+
236
+ public digest(): string {
237
+ if (!this._finished) {
238
+ this._finished = true;
239
+ if (this._leftoverHighSurrogate) {
240
+ // illegal => unicode replacement character
241
+ this._leftoverHighSurrogate = 0;
242
+ this._buffLen = this._push(this._buff, this._buffLen, SHA1Constant.UNICODE_REPLACEMENT);
243
+ }
244
+ this._totalLen += this._buffLen;
245
+ this._wrapUp();
246
+ }
247
+
248
+ return (
249
+ toHexString(this._h0) +
250
+ toHexString(this._h1) +
251
+ toHexString(this._h2) +
252
+ toHexString(this._h3) +
253
+ toHexString(this._h4)
254
+ );
255
+ }
256
+
257
+ private _wrapUp(): void {
258
+ this._buff[this._buffLen++] = 0x80;
259
+ fill(this._buff, this._buffLen);
260
+
261
+ if (this._buffLen > 56) {
262
+ this._step();
263
+ fill(this._buff);
264
+ }
265
+
266
+ // this will fit because the mantissa can cover up to 52 bits
267
+ const ml = 8 * this._totalLen;
268
+
269
+ this._buffDV.setUint32(56, Math.floor(ml / 4294967296), false);
270
+ this._buffDV.setUint32(60, ml % 4294967296, false);
271
+
272
+ this._step();
273
+ }
274
+
275
+ private _step(): void {
276
+ const bigBlock32 = StringSHA1._bigBlock32;
277
+ const data = this._buffDV;
278
+
279
+ for (let j = 0; j < 64 /* 16*4 */; j += 4) {
280
+ bigBlock32.setUint32(j, data.getUint32(j, false), false);
281
+ }
282
+
283
+ for (let j = 64; j < 320 /* 80*4 */; j += 4) {
284
+ bigBlock32.setUint32(
285
+ j,
286
+ leftRotate(
287
+ bigBlock32.getUint32(j - 12, false) ^
288
+ bigBlock32.getUint32(j - 32, false) ^
289
+ bigBlock32.getUint32(j - 56, false) ^
290
+ bigBlock32.getUint32(j - 64, false),
291
+ 1,
292
+ ),
293
+ false,
294
+ );
295
+ }
296
+
297
+ let a = this._h0;
298
+ let b = this._h1;
299
+ let c = this._h2;
300
+ let d = this._h3;
301
+ let e = this._h4;
302
+
303
+ let f: number;
304
+ let k: number;
305
+ let temp: number;
306
+
307
+ for (let j = 0; j < 80; j++) {
308
+ if (j < 20) {
309
+ f = (b & c) | (~b & d);
310
+ k = 0x5a827999;
311
+ } else if (j < 40) {
312
+ f = b ^ c ^ d;
313
+ k = 0x6ed9eba1;
314
+ } else if (j < 60) {
315
+ f = (b & c) | (b & d) | (c & d);
316
+ k = 0x8f1bbcdc;
317
+ } else {
318
+ f = b ^ c ^ d;
319
+ k = 0xca62c1d6;
320
+ }
321
+
322
+ temp = (leftRotate(a, 5) + f + e + k + bigBlock32.getUint32(j * 4, false)) & 0xffffffff;
323
+ e = d;
324
+ d = c;
325
+ c = leftRotate(b, 30);
326
+ b = a;
327
+ a = temp;
328
+ }
329
+
330
+ this._h0 = (this._h0 + a) & 0xffffffff;
331
+ this._h1 = (this._h1 + b) & 0xffffffff;
332
+ this._h2 = (this._h2 + c) & 0xffffffff;
333
+ this._h3 = (this._h3 + d) & 0xffffffff;
334
+ this._h4 = (this._h4 + e) & 0xffffffff;
335
+ }
336
+ }
@@ -0,0 +1,149 @@
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
+ // Some code copied and modified from https://github.com/microsoft/vscode/blob/main/src/vs/base/common/iconLabels.ts
6
+
7
+ import { matchesFuzzy } from './filters';
8
+ import { ltrim } from './strings';
9
+
10
+ export const iconStartMarker = '$(';
11
+
12
+ const iconNameCharacterRegexp = new RegExp('[A-Za-z0-9~-]');
13
+
14
+ export interface IParsedLabelWithIcons {
15
+ readonly text: string;
16
+ readonly iconOffsets?: readonly number[];
17
+ }
18
+
19
+ export function parseLabelWithIcons(text: string): IParsedLabelWithIcons {
20
+ const firstIconIndex = text.indexOf(iconStartMarker);
21
+ if (firstIconIndex === -1) {
22
+ return { text }; // return early if the word does not include an icon
23
+ }
24
+
25
+ return doParseLabelWithIcons(text, firstIconIndex);
26
+ }
27
+
28
+ function doParseLabelWithIcons(text: string, firstIconIndex: number): IParsedLabelWithIcons {
29
+ const iconOffsets: number[] = [];
30
+ let textWithoutIcons = '';
31
+
32
+ function appendChars(chars: string) {
33
+ if (chars) {
34
+ textWithoutIcons += chars;
35
+
36
+ for (const _ of chars) {
37
+ iconOffsets.push(iconsOffset); // make sure to fill in icon offsets
38
+ }
39
+ }
40
+ }
41
+
42
+ let currentIconStart = -1;
43
+ let currentIconValue = '';
44
+ let iconsOffset = 0;
45
+
46
+ let char: string;
47
+ let nextChar: string;
48
+
49
+ let offset = firstIconIndex;
50
+ const length = text.length;
51
+
52
+ // Append all characters until the first icon
53
+ appendChars(text.substr(0, firstIconIndex));
54
+
55
+ // example: $(file-symlink-file) my cool $(other-icon) entry
56
+ while (offset < length) {
57
+ char = text[offset];
58
+ nextChar = text[offset + 1];
59
+
60
+ // beginning of icon: some value $( <--
61
+ if (char === iconStartMarker[0] && nextChar === iconStartMarker[1]) {
62
+ currentIconStart = offset;
63
+
64
+ // if we had a previous potential icon value without
65
+ // the closing ')', it was actually not an icon and
66
+ // so we have to add it to the actual value
67
+ appendChars(currentIconValue);
68
+
69
+ currentIconValue = iconStartMarker;
70
+
71
+ offset++; // jump over '('
72
+ }
73
+
74
+ // end of icon: some value $(some-icon) <--
75
+ else if (char === ')' && currentIconStart !== -1) {
76
+ const currentIconLength = offset - currentIconStart + 1; // +1 to include the closing ')'
77
+ iconsOffset += currentIconLength;
78
+ currentIconStart = -1;
79
+ currentIconValue = '';
80
+ }
81
+
82
+ // within icon
83
+ else if (currentIconStart !== -1) {
84
+ // Make sure this is a real icon name
85
+ if (iconNameCharacterRegexp.test(char)) {
86
+ currentIconValue += char;
87
+ } else {
88
+ // This is not a real icon, treat it as text
89
+ appendChars(currentIconValue);
90
+
91
+ currentIconStart = -1;
92
+ currentIconValue = '';
93
+ }
94
+ }
95
+
96
+ // any value outside of icon
97
+ else {
98
+ appendChars(char);
99
+ }
100
+
101
+ offset++;
102
+ }
103
+
104
+ // if we had a previous potential icon value without
105
+ // the closing ')', it was actually not an icon and
106
+ // so we have to add it to the actual value
107
+ appendChars(currentIconValue);
108
+
109
+ return { text: textWithoutIcons, iconOffsets };
110
+ }
111
+
112
+ export function matchesFuzzyIconAware(
113
+ query: string,
114
+ target: IParsedLabelWithIcons,
115
+ enableSeparateSubstringMatching = false,
116
+ ):
117
+ | {
118
+ start: number;
119
+ end: number;
120
+ }[]
121
+ | null {
122
+ const { text, iconOffsets } = target;
123
+
124
+ // Return early if there are no icon markers in the word to match against
125
+ if (!iconOffsets || iconOffsets.length === 0) {
126
+ return matchesFuzzy(query, text, enableSeparateSubstringMatching);
127
+ }
128
+
129
+ // Trim the word to match against because it could have leading
130
+ // whitespace now if the word started with an icon
131
+ const wordToMatchAgainstWithoutIconsTrimmed = ltrim(text, ' ');
132
+ const leadingWhitespaceOffset = text.length - wordToMatchAgainstWithoutIconsTrimmed.length;
133
+
134
+ // match on value without icon
135
+ const matches = matchesFuzzy(query, wordToMatchAgainstWithoutIconsTrimmed, enableSeparateSubstringMatching);
136
+
137
+ // Map matches back to offsets with icon and trimming
138
+ if (matches) {
139
+ for (const match of matches) {
140
+ const iconOffset =
141
+ iconOffsets[match.start + leadingWhitespaceOffset] /* icon offsets at index */ +
142
+ leadingWhitespaceOffset; /* overall leading whitespace offset */
143
+ match.start += iconOffset;
144
+ match.end += iconOffset;
145
+ }
146
+ }
147
+
148
+ return matches;
149
+ }
package/src/index.ts ADDED
@@ -0,0 +1,40 @@
1
+ export * from './ansi';
2
+ export * from './async';
3
+ export * from './buffer';
4
+ export * from './cache';
5
+ export * from './cancellation';
6
+ export * from './character-classifier';
7
+ export * from './charCode';
8
+ export * from './date';
9
+ export * from './disposable';
10
+ export * from './decorators';
11
+ export * from './encoding';
12
+ export * from './errors';
13
+ export * from './event';
14
+ export * from './file-uri';
15
+ export * from './filters';
16
+ export * from './functional';
17
+ export * from './glob';
18
+ export * from './hash';
19
+ export * from './iterator';
20
+ export * from './lifecycle';
21
+ export * from './lru-map';
22
+ export * from './linked-list';
23
+ export * from './linked-text';
24
+ export * from './map';
25
+ export * from './marshalling';
26
+ export * from './os';
27
+ export * from './platform';
28
+ export * from './progress';
29
+ export * from './promises';
30
+ export * from './sequence';
31
+ export * from './types';
32
+ export * from './uint';
33
+ export * from './uri';
34
+ export * from './uuid';
35
+ export * from './const';
36
+ export * as process from './process';
37
+ export * as strings from './strings';
38
+ export * as arrays from './arrays';
39
+ export * as objects from './objects';
40
+ export * as path from './path';
@@ -0,0 +1,36 @@
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
+ export interface IteratorDefinedResult<T> {
7
+ readonly done: false;
8
+ readonly value: T;
9
+ }
10
+ export interface IteratorUndefinedResult {
11
+ readonly done: true;
12
+ readonly value: undefined;
13
+ }
14
+ export const FIN: IteratorUndefinedResult = { done: true, value: undefined };
15
+ export type IteratorResult<T> = IteratorDefinedResult<T> | IteratorUndefinedResult;
16
+
17
+ export interface Iterator<T> {
18
+ next(): IteratorResult<T>;
19
+ }
20
+
21
+ export function filter<T, R extends T>(iterable: Iterable<T>, predicate: (t: T) => t is R): Iterable<R>;
22
+ export function filter<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): Iterable<T>;
23
+ export function* filter<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): Iterable<T> {
24
+ for (const element of iterable) {
25
+ if (predicate(element)) {
26
+ yield element;
27
+ }
28
+ }
29
+ }
30
+
31
+ export function* map<T, R>(iterable: Iterable<T>, fn: (t: T, index: number) => R): Iterable<R> {
32
+ let index = 0;
33
+ for (const element of iterable) {
34
+ yield fn(element, index++);
35
+ }
36
+ }
@@ -0,0 +1,48 @@
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 { IDisposable } from './disposable';
7
+ import { once } from './functional';
8
+
9
+ // 保留
10
+ export interface IReference<T> extends IDisposable {
11
+ readonly object: T;
12
+ }
13
+
14
+ export abstract class ReferenceCollection<T> {
15
+ private references: { [key: string]: { readonly object: T; counter: number } } = Object.create(null);
16
+
17
+ constructor() {}
18
+
19
+ acquire(key: string): IReference<T> {
20
+ let reference = this.references[key];
21
+
22
+ if (!reference) {
23
+ reference = this.references[key] = { counter: 0, object: this.createReferencedObject(key) };
24
+ }
25
+
26
+ const { object } = reference;
27
+ const dispose = once(() => {
28
+ if (--reference.counter === 0) {
29
+ this.destroyReferencedObject(key, reference.object);
30
+ delete this.references[key];
31
+ }
32
+ });
33
+
34
+ reference.counter++;
35
+
36
+ return { object, dispose };
37
+ }
38
+
39
+ protected abstract createReferencedObject(key: string): T;
40
+ protected abstract destroyReferencedObject(key: string, object: T): void;
41
+ }
42
+
43
+ export class ImmortalReference<T> implements IReference<T> {
44
+ constructor(public object: T) {}
45
+ dispose(): void {
46
+ /* noop */
47
+ }
48
+ }