@isopodlabs/vscode_utils 0.0.2
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/README.md +8 -0
- package/assets/shared.css +204 -0
- package/assets/shared.js +336 -0
- package/assets/tree.css +24 -0
- package/assets/tree.js +81 -0
- package/dist/fs.d.ts +119 -0
- package/dist/fs.js +625 -0
- package/dist/icon-theme.d.ts +63 -0
- package/dist/icon-theme.js +199 -0
- package/dist/utils.d.ts +91 -0
- package/dist/utils.js +430 -0
- package/package.json +30 -0
package/dist/utils.js
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringParser = exports.CallCombiner = exports.CallCombiner0 = exports.AsyncLazy = exports.Lazy = void 0;
|
|
4
|
+
exports.makeCache = makeCache;
|
|
5
|
+
exports.compare = compare;
|
|
6
|
+
exports.reverse_compare = reverse_compare;
|
|
7
|
+
exports.reverse = reverse;
|
|
8
|
+
exports.merge = merge;
|
|
9
|
+
exports.partition = partition;
|
|
10
|
+
exports.isEmpty = isEmpty;
|
|
11
|
+
exports.clone = clone;
|
|
12
|
+
exports.lowerBound = lowerBound;
|
|
13
|
+
exports.argmin = argmin;
|
|
14
|
+
exports.make = make;
|
|
15
|
+
exports.arrayAppend = arrayAppend;
|
|
16
|
+
exports.arrayRemove = arrayRemove;
|
|
17
|
+
exports.arrayCompare = arrayCompare;
|
|
18
|
+
exports.arrayEqual = arrayEqual;
|
|
19
|
+
exports.arrayRotate = arrayRotate;
|
|
20
|
+
exports.arrayReverse = arrayReverse;
|
|
21
|
+
exports.array_make = array_make;
|
|
22
|
+
exports.eachIterable = eachIterable;
|
|
23
|
+
exports.findIterable = findIterable;
|
|
24
|
+
exports.mapIterable = mapIterable;
|
|
25
|
+
exports.asyncMap = asyncMap;
|
|
26
|
+
exports.asyncReduce = asyncReduce;
|
|
27
|
+
exports.parallel = parallel;
|
|
28
|
+
exports.serial = serial;
|
|
29
|
+
exports.filterIterable = filterIterable;
|
|
30
|
+
exports.asyncFilter = asyncFilter;
|
|
31
|
+
exports.mapObject = mapObject;
|
|
32
|
+
exports.filterObject = filterObject;
|
|
33
|
+
exports.firstOf = firstOf;
|
|
34
|
+
exports.lastOf = lastOf;
|
|
35
|
+
exports.splitFirstOf = splitFirstOf;
|
|
36
|
+
exports.splitLastOf = splitLastOf;
|
|
37
|
+
exports.trim0 = trim0;
|
|
38
|
+
exports.replace = replace;
|
|
39
|
+
exports.async_replace = async_replace;
|
|
40
|
+
exports.replace_back = replace_back;
|
|
41
|
+
exports.async_replace_back = async_replace_back;
|
|
42
|
+
exports.splitEvery = splitEvery;
|
|
43
|
+
exports.tag = tag;
|
|
44
|
+
exports.stringCode = stringCode;
|
|
45
|
+
exports.stringCodeBig = stringCodeBig;
|
|
46
|
+
exports.previousChar = previousChar;
|
|
47
|
+
exports.hasCustomToString = hasCustomToString;
|
|
48
|
+
class Lazy {
|
|
49
|
+
factory;
|
|
50
|
+
_value;
|
|
51
|
+
constructor(factory) {
|
|
52
|
+
this.factory = factory;
|
|
53
|
+
}
|
|
54
|
+
get value() {
|
|
55
|
+
if (this._value === undefined)
|
|
56
|
+
this._value = this.factory();
|
|
57
|
+
return this._value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Lazy = Lazy;
|
|
61
|
+
class AsyncLazy {
|
|
62
|
+
factory;
|
|
63
|
+
_value;
|
|
64
|
+
constructor(factory) {
|
|
65
|
+
this.factory = factory;
|
|
66
|
+
}
|
|
67
|
+
get value() {
|
|
68
|
+
if (this._value === undefined) {
|
|
69
|
+
this._value = null;
|
|
70
|
+
this.factory().then(v => this._value = v);
|
|
71
|
+
}
|
|
72
|
+
return this._value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.AsyncLazy = AsyncLazy;
|
|
76
|
+
class CallCombiner0 {
|
|
77
|
+
timeout = null;
|
|
78
|
+
combine(delay, func) {
|
|
79
|
+
if (this.timeout)
|
|
80
|
+
clearTimeout(this.timeout);
|
|
81
|
+
this.timeout = setTimeout(() => {
|
|
82
|
+
this.timeout = null;
|
|
83
|
+
func();
|
|
84
|
+
}, delay);
|
|
85
|
+
}
|
|
86
|
+
pending() {
|
|
87
|
+
return !!this.timeout;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.CallCombiner0 = CallCombiner0;
|
|
91
|
+
class CallCombiner extends CallCombiner0 {
|
|
92
|
+
func;
|
|
93
|
+
delay;
|
|
94
|
+
constructor(func, delay) {
|
|
95
|
+
super();
|
|
96
|
+
this.func = func;
|
|
97
|
+
this.delay = delay;
|
|
98
|
+
}
|
|
99
|
+
trigger() {
|
|
100
|
+
super.combine(this.delay, this.func);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.CallCombiner = CallCombiner;
|
|
104
|
+
function makeCache(load) {
|
|
105
|
+
const cache = {};
|
|
106
|
+
return {
|
|
107
|
+
get: (fullpath) => {
|
|
108
|
+
if (!cache[fullpath])
|
|
109
|
+
cache[fullpath] = load(fullpath);
|
|
110
|
+
return cache[fullpath];
|
|
111
|
+
},
|
|
112
|
+
remove: (fullpath) => {
|
|
113
|
+
delete cache[fullpath];
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function compare(a, b) {
|
|
118
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
119
|
+
}
|
|
120
|
+
function reverse_compare(a, b) {
|
|
121
|
+
return compare(b, a);
|
|
122
|
+
}
|
|
123
|
+
function reverse(func) {
|
|
124
|
+
return (a, b) => func(b, a);
|
|
125
|
+
}
|
|
126
|
+
function merge(...list) {
|
|
127
|
+
function isT(value) {
|
|
128
|
+
return typeof value === 'object' && value !== null;
|
|
129
|
+
}
|
|
130
|
+
function recurse(target, source) {
|
|
131
|
+
for (const key in source) {
|
|
132
|
+
if (isT(source[key]) && isT(target[key]))
|
|
133
|
+
recurse(target[key], source[key]);
|
|
134
|
+
else
|
|
135
|
+
target[key] = source[key];
|
|
136
|
+
}
|
|
137
|
+
return target;
|
|
138
|
+
}
|
|
139
|
+
return list.reduce((merged, r) => recurse(merged, r), {});
|
|
140
|
+
}
|
|
141
|
+
function partition(array, func) {
|
|
142
|
+
const partitions = {};
|
|
143
|
+
for (const i of array)
|
|
144
|
+
(partitions[func(i)] ??= []).push(i);
|
|
145
|
+
return partitions;
|
|
146
|
+
}
|
|
147
|
+
function isEmpty(obj) {
|
|
148
|
+
return Object.keys(obj).length === 0;
|
|
149
|
+
}
|
|
150
|
+
function clone(obj) {
|
|
151
|
+
return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
|
|
152
|
+
}
|
|
153
|
+
function lowerBound(array, value, func) {
|
|
154
|
+
let i = 0;
|
|
155
|
+
for (let n = array.length; n; n >>= 1) {
|
|
156
|
+
const mid = i + (n >> 1);
|
|
157
|
+
if (func(array[mid], value, mid)) {
|
|
158
|
+
i = mid + 1;
|
|
159
|
+
--n;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return i;
|
|
163
|
+
}
|
|
164
|
+
function argmin(array, fn) {
|
|
165
|
+
let mini = 0;
|
|
166
|
+
let minv = fn ? fn(array[0]) : array[0];
|
|
167
|
+
for (let i = 1; i < array.length; i++) {
|
|
168
|
+
const v = fn ? fn(array[i]) : array[i];
|
|
169
|
+
if (v < minv) {
|
|
170
|
+
mini = i;
|
|
171
|
+
minv = v;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return mini;
|
|
175
|
+
}
|
|
176
|
+
function isConstructor(maker) {
|
|
177
|
+
return maker.prototype?.constructor.name;
|
|
178
|
+
// return typeof maker === 'function' && maker.prototype && !!maker.prototype.constructor;
|
|
179
|
+
}
|
|
180
|
+
function make(maker, arg, opt) {
|
|
181
|
+
return isConstructor(maker) ? new maker(arg, opt) : maker(arg, opt);
|
|
182
|
+
}
|
|
183
|
+
function arrayAppend(array, items) {
|
|
184
|
+
for (const i of items)
|
|
185
|
+
array.push(i);
|
|
186
|
+
}
|
|
187
|
+
function arrayRemove(array, item) {
|
|
188
|
+
const index = array.indexOf(item);
|
|
189
|
+
if (index === -1)
|
|
190
|
+
return false;
|
|
191
|
+
array.splice(index, 1);
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
function arrayCompare(arr1, arr2) {
|
|
195
|
+
const length = Math.min(arr1.length, arr2.length);
|
|
196
|
+
for (let i = 0; i < length; i++) {
|
|
197
|
+
const r = compare(arr1[i], arr2[i]);
|
|
198
|
+
if (r)
|
|
199
|
+
return r;
|
|
200
|
+
}
|
|
201
|
+
return arr1.length - arr2.length;
|
|
202
|
+
}
|
|
203
|
+
function arrayEqual(arr1, arr2) {
|
|
204
|
+
if (arr1.length !== arr2.length)
|
|
205
|
+
return false;
|
|
206
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
207
|
+
if (arr1[i] !== arr2[i])
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
function arrayRotate(array, start, end, shift) {
|
|
213
|
+
const length = end - start;
|
|
214
|
+
if (length > 1 && shift % length) {
|
|
215
|
+
shift = ((shift % length) + length) % length;
|
|
216
|
+
arrayReverse(array, start, end - 1);
|
|
217
|
+
arrayReverse(array, start, start + shift - 1);
|
|
218
|
+
arrayReverse(array, start + shift, end - 1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function arrayReverse(array, start, end) {
|
|
222
|
+
while (start < end) {
|
|
223
|
+
[array[start], array[end]] = [array[end], array[start]];
|
|
224
|
+
start++;
|
|
225
|
+
end--;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function array_make(n, constructor) {
|
|
229
|
+
return Array.from({ length: n }, () => new constructor);
|
|
230
|
+
}
|
|
231
|
+
function eachIterable(iterable, func) {
|
|
232
|
+
if (iterable) {
|
|
233
|
+
let i = 0;
|
|
234
|
+
for (const v of iterable)
|
|
235
|
+
func(v, i++);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function findIterable(iterable, func) {
|
|
239
|
+
if (iterable) {
|
|
240
|
+
for (const v of iterable) {
|
|
241
|
+
if (func(v))
|
|
242
|
+
return v;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function mapIterable(iterable, func) {
|
|
247
|
+
return iterable ? Array.from(iterable, func) : [];
|
|
248
|
+
}
|
|
249
|
+
async function asyncMap(iterable, func) {
|
|
250
|
+
return Promise.all(mapIterable(iterable, func));
|
|
251
|
+
}
|
|
252
|
+
async function asyncReduce(array, func, initialValue) {
|
|
253
|
+
return array.reduce(async (promise, v, i, array) => func(await promise, v, i, array), Promise.resolve(initialValue));
|
|
254
|
+
}
|
|
255
|
+
async function parallel(...fns) {
|
|
256
|
+
return asyncMap(fns, f => f());
|
|
257
|
+
}
|
|
258
|
+
async function serial(...fns) {
|
|
259
|
+
const results = [];
|
|
260
|
+
for (const f of fns)
|
|
261
|
+
results.push(await f());
|
|
262
|
+
return results;
|
|
263
|
+
}
|
|
264
|
+
function filterIterable(iterable, func) {
|
|
265
|
+
const array = [];
|
|
266
|
+
let i = 0;
|
|
267
|
+
for (const v of iterable)
|
|
268
|
+
if (func(v, i++))
|
|
269
|
+
array.push(v);
|
|
270
|
+
return array;
|
|
271
|
+
}
|
|
272
|
+
async function asyncFilter(iterable, func) {
|
|
273
|
+
const filters = await Promise.all(mapIterable(iterable, func));
|
|
274
|
+
return filterIterable(iterable, (_, i) => filters[i]);
|
|
275
|
+
}
|
|
276
|
+
function mapObject(obj, func) {
|
|
277
|
+
return Object.fromEntries(Object.entries(obj).map(x => func(x)));
|
|
278
|
+
}
|
|
279
|
+
function filterObject(obj, func) {
|
|
280
|
+
return Object.fromEntries(Object.entries(obj).filter(x => func(x)));
|
|
281
|
+
}
|
|
282
|
+
//-----------------------------------------------------------------------------
|
|
283
|
+
// strings
|
|
284
|
+
//-----------------------------------------------------------------------------
|
|
285
|
+
function firstOf(value, find) {
|
|
286
|
+
let index = value.length;
|
|
287
|
+
for (const c of find) {
|
|
288
|
+
const i = value.indexOf(c);
|
|
289
|
+
if (i >= 0)
|
|
290
|
+
index = Math.min(i);
|
|
291
|
+
}
|
|
292
|
+
return index;
|
|
293
|
+
}
|
|
294
|
+
function lastOf(value, find) {
|
|
295
|
+
let index = -1;
|
|
296
|
+
for (const c of find)
|
|
297
|
+
index = Math.max(value.indexOf(c));
|
|
298
|
+
return index;
|
|
299
|
+
}
|
|
300
|
+
function splitFirstOf(value, find) {
|
|
301
|
+
const index = firstOf(value, find);
|
|
302
|
+
return index === -1 ? [undefined, value] : [value.substring(0, index), value.substring(index + 1)];
|
|
303
|
+
}
|
|
304
|
+
function splitLastOf(value, find) {
|
|
305
|
+
const index = lastOf(value, find);
|
|
306
|
+
return index === -1 ? [value, undefined] : [value.substring(0, index), value.substring(index + 1)];
|
|
307
|
+
}
|
|
308
|
+
function trim0(value) {
|
|
309
|
+
const index = value.indexOf('\0');
|
|
310
|
+
return index === -1 ? value : value.substring(0, index);
|
|
311
|
+
}
|
|
312
|
+
function replace(value, re, process) {
|
|
313
|
+
let m;
|
|
314
|
+
let result = "";
|
|
315
|
+
let i = 0;
|
|
316
|
+
while ((m = re.exec(value))) {
|
|
317
|
+
result += value.substring(i, m.index) + process(m);
|
|
318
|
+
i = re.lastIndex;
|
|
319
|
+
}
|
|
320
|
+
return result + value.substring(i);
|
|
321
|
+
}
|
|
322
|
+
async function async_replace(value, re, process) {
|
|
323
|
+
let m;
|
|
324
|
+
let result = "";
|
|
325
|
+
let i = 0;
|
|
326
|
+
while ((m = re.exec(value))) {
|
|
327
|
+
result += value.substring(i, m.index) + await process(m);
|
|
328
|
+
i = re.lastIndex;
|
|
329
|
+
}
|
|
330
|
+
return result + value.substring(i);
|
|
331
|
+
}
|
|
332
|
+
function replace_back(value, re, process) {
|
|
333
|
+
const start = re.lastIndex;
|
|
334
|
+
const m = re.exec(value);
|
|
335
|
+
if (m) {
|
|
336
|
+
const right = replace_back(value, re, process);
|
|
337
|
+
return value.substring(start, m.index) + process(m, right);
|
|
338
|
+
}
|
|
339
|
+
re.lastIndex = value.length;
|
|
340
|
+
return value.substring(start);
|
|
341
|
+
}
|
|
342
|
+
async function async_replace_back(value, re, process) {
|
|
343
|
+
const start = re.lastIndex;
|
|
344
|
+
const m = re.exec(value);
|
|
345
|
+
if (m) {
|
|
346
|
+
const right = await async_replace_back(value, re, process);
|
|
347
|
+
return value.substring(start, m.index) + await process(m, right);
|
|
348
|
+
}
|
|
349
|
+
re.lastIndex = value.length;
|
|
350
|
+
return value.substring(start);
|
|
351
|
+
}
|
|
352
|
+
function splitEvery(s, n) {
|
|
353
|
+
return Array.from({ length: Math.ceil(s.length / n) }, (_, i) => s.slice(i * n, (i + 1) * n));
|
|
354
|
+
}
|
|
355
|
+
function tag(strings, ...keys) {
|
|
356
|
+
return ((...values) => {
|
|
357
|
+
const dict = values.at(-1) || {};
|
|
358
|
+
return keys.map((key, i) => (Number.isInteger(key) ? values[key] : dict[key]) + strings[i + 1]).join('');
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function stringCode(s) {
|
|
362
|
+
let r = 0;
|
|
363
|
+
for (let i = 0; i < s.length; i++)
|
|
364
|
+
r += s.charCodeAt(i) << (i * 8);
|
|
365
|
+
return r;
|
|
366
|
+
}
|
|
367
|
+
function stringCodeBig(s) {
|
|
368
|
+
let r = 0n;
|
|
369
|
+
for (let i = 0; i < s.length; i++)
|
|
370
|
+
r += BigInt(s.charCodeAt(i)) << BigInt(i * 8);
|
|
371
|
+
return r;
|
|
372
|
+
}
|
|
373
|
+
function previousChar(str, pos) {
|
|
374
|
+
return pos === 0
|
|
375
|
+
? "\n"
|
|
376
|
+
// check for low surrogate (BMP)
|
|
377
|
+
: (str.charCodeAt(pos - 1) & 0xfc00) === 0xdc00 && (str.charCodeAt(pos - 2) & 0xfc00) === 0xd800
|
|
378
|
+
? str.slice(pos - 2, pos) : str.charAt(pos - 1);
|
|
379
|
+
}
|
|
380
|
+
function hasCustomToString(value) {
|
|
381
|
+
return value && value.toString !== Object.prototype.toString;
|
|
382
|
+
}
|
|
383
|
+
class StringParser {
|
|
384
|
+
subject;
|
|
385
|
+
pos;
|
|
386
|
+
constructor(subject, pos = 0) {
|
|
387
|
+
this.subject = subject;
|
|
388
|
+
this.pos = pos;
|
|
389
|
+
}
|
|
390
|
+
remaining() { return this.subject.length - this.pos; }
|
|
391
|
+
remainder() { return this.subject.slice(this.pos); }
|
|
392
|
+
processed() { return this.subject.slice(0, this.pos); }
|
|
393
|
+
peek() {
|
|
394
|
+
return this.subject[this.pos];
|
|
395
|
+
}
|
|
396
|
+
peekn(n) {
|
|
397
|
+
return this.subject.slice(this.pos, this.pos + n);
|
|
398
|
+
}
|
|
399
|
+
get(n) {
|
|
400
|
+
const pos = this.pos;
|
|
401
|
+
this.pos = Math.min(pos + n, this.subject.length);
|
|
402
|
+
return this.subject.slice(pos, this.pos);
|
|
403
|
+
}
|
|
404
|
+
skip(c) {
|
|
405
|
+
if (this.remainder().startsWith(c)) {
|
|
406
|
+
this.pos += c.length;
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
expect(c) {
|
|
412
|
+
if (!this.skip(c))
|
|
413
|
+
throw new Error(`Expected '${c}'`);
|
|
414
|
+
}
|
|
415
|
+
match(re) {
|
|
416
|
+
const m = re.exec(this.remainder());
|
|
417
|
+
if (m) {
|
|
418
|
+
this.pos += m.index + m[0].length;
|
|
419
|
+
return m[0];
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
exec(re) {
|
|
423
|
+
const m = re.exec(this.remainder());
|
|
424
|
+
if (m) {
|
|
425
|
+
this.pos += m.index + m[0].length;
|
|
426
|
+
return m;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
exports.StringParser = StringParser;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@isopodlabs/vscode_utils",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "vscode utilities",
|
|
5
|
+
"main": "dist/utils.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"assets",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "echo \"No tests specified\" && exit 0"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"vscode",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"author": "Adrian Stephens",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.13.8",
|
|
23
|
+
"eslint": "^9.21.0",
|
|
24
|
+
"typescript": "^5.8.2",
|
|
25
|
+
"typescript-eslint": "^8.26.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@types/vscode": "^1.98.0"
|
|
29
|
+
}
|
|
30
|
+
}
|