@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/dist/fs.js ADDED
@@ -0,0 +1,625 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Change = exports.Glob = exports.SubfileFileSystem = exports.ReadOnlyFilesystem = exports.NormalFile = exports.BaseFileSystem = void 0;
37
+ exports.isFile = isFile;
38
+ exports.withOffset = withOffset;
39
+ exports.openFile = openFile;
40
+ exports.toOSPath = toOSPath;
41
+ exports.readDirectory = readDirectory;
42
+ exports.directories = directories;
43
+ exports.files = files;
44
+ exports.search = search;
45
+ exports.mapDirs = mapDirs;
46
+ exports.stat_reject = stat_reject;
47
+ exports.exists = exists;
48
+ exports.getStat = getStat;
49
+ exports.isDirectory = isDirectory;
50
+ exports.loadFile = loadFile;
51
+ exports.writeFile = writeFile;
52
+ exports.deleteFile = deleteFile;
53
+ exports.createDirectory = createDirectory;
54
+ exports.createNewName = createNewName;
55
+ exports.copyFile = copyFile;
56
+ exports.copyFileToDir = copyFileToDir;
57
+ exports.copyDirectory = copyDirectory;
58
+ exports.onChange = onChange;
59
+ exports.arrayRemove = arrayRemove;
60
+ exports.removeOnChange = removeOnChange;
61
+ const vscode = __importStar(require("vscode"));
62
+ const nodefs = __importStar(require("fs"));
63
+ const path = __importStar(require("path"));
64
+ function uri(value) {
65
+ return value instanceof vscode.Uri ? value : vscode.Uri.file(value);
66
+ }
67
+ function file(value) {
68
+ return value instanceof vscode.Uri ? value.fsPath : value;
69
+ }
70
+ function file_id(value) {
71
+ return typeof (value) === 'string' ? value : value.scheme === 'file' ? value.fsPath : value.toString();
72
+ }
73
+ function basename(value) {
74
+ return path.basename(file(value));
75
+ }
76
+ function ext(value) {
77
+ return path.extname(file(value));
78
+ }
79
+ function dirname(value) {
80
+ return path.dirname(file(value));
81
+ }
82
+ function pathComponents(value) {
83
+ return path.parse(file(value));
84
+ }
85
+ function withPathComponents(value, ...comp) {
86
+ const p = path.join(...comp);
87
+ return value instanceof vscode.Uri ? value.with({ path: p }) : p;
88
+ }
89
+ function join(directory, ...comp) {
90
+ return withPathComponents(directory, file(directory), ...comp);
91
+ }
92
+ function isFile(obj) {
93
+ return obj && typeof obj.dispose === 'function' && typeof obj.read === 'function' && typeof obj.write === 'function';
94
+ }
95
+ const filesystems = {};
96
+ class BaseFileSystem {
97
+ _onDidChangeFile = new vscode.EventEmitter();
98
+ constructor(context, scheme) {
99
+ filesystems[scheme] = this;
100
+ context.subscriptions.push(vscode.workspace.registerFileSystemProvider(scheme, this, { isCaseSensitive: true }));
101
+ }
102
+ get onDidChangeFile() { return this._onDidChangeFile.event; }
103
+ //stubs
104
+ watch(_uri, _options) { throw 'not implemented'; }
105
+ stat(_uri) { throw 'not implemented'; }
106
+ readDirectory(_uri) { throw 'not implemented'; }
107
+ createDirectory(_uri) { throw 'not implemented'; }
108
+ writeFile(_uri, _content, _options) { throw 'not implemented'; }
109
+ delete(_uri, _options) { throw 'not implemented'; }
110
+ rename(_oldUri, _newUri, _options) { throw 'not implemented'; }
111
+ }
112
+ exports.BaseFileSystem = BaseFileSystem;
113
+ function withOffset(file, offset) {
114
+ if (file instanceof vscode.Uri)
115
+ return SubfileFileSystem.makeUri(file, offset);
116
+ return new class {
117
+ length = offset.toOffset - offset.fromOffset;
118
+ dispose() { file.dispose(); }
119
+ read(pos, length) {
120
+ const start = pos + offset.fromOffset;
121
+ const end = Math.min(start + length, offset.toOffset);
122
+ return file.read(start, end - start);
123
+ }
124
+ write(pos, data) {
125
+ const start = pos + offset.fromOffset;
126
+ const end = Math.min(start + data.length, offset.toOffset);
127
+ return file.write(start, data.subarray(0, end - start));
128
+ }
129
+ };
130
+ }
131
+ function openFile(uri) {
132
+ switch (uri.scheme) {
133
+ case 'file':
134
+ return NormalFile.open(uri);
135
+ default:
136
+ return filesystems[uri.scheme]?.openFile(uri);
137
+ }
138
+ }
139
+ class NormalFile {
140
+ fd;
141
+ constructor(fd) {
142
+ this.fd = fd;
143
+ }
144
+ static open(uri) {
145
+ return new Promise((resolve, reject) => {
146
+ nodefs.open(uri.fsPath, 'r', (err, fd) => {
147
+ if (err)
148
+ reject(err);
149
+ else
150
+ resolve(new NormalFile(fd));
151
+ });
152
+ });
153
+ }
154
+ dispose() {
155
+ nodefs.close(this.fd);
156
+ }
157
+ read(pos, length) {
158
+ return new Promise((resolve, reject) => {
159
+ const buffer = Buffer.alloc(length);
160
+ nodefs.read(this.fd, buffer, 0, length, pos, (err, bytesRead, buffer) => {
161
+ if (err)
162
+ reject(err);
163
+ else
164
+ resolve(new Uint8Array(buffer));
165
+ });
166
+ });
167
+ }
168
+ write(pos, data) {
169
+ return new Promise((resolve, reject) => {
170
+ nodefs.write(this.fd, data, 0, data.length, pos, (err, bytesWritten) => {
171
+ if (err)
172
+ reject(err);
173
+ else
174
+ resolve(bytesWritten);
175
+ });
176
+ });
177
+ }
178
+ }
179
+ exports.NormalFile = NormalFile;
180
+ function getEncapsulatedUri(uri) {
181
+ return uri.with({
182
+ scheme: uri.authority,
183
+ authority: '',
184
+ });
185
+ // return vscode.Uri.parse(uri.fsPath);
186
+ }
187
+ class ReadOnlyFilesystem extends BaseFileSystem {
188
+ static SCHEME = 'readonly';
189
+ constructor(context) {
190
+ super(context, ReadOnlyFilesystem.SCHEME);
191
+ }
192
+ async stat(uri) {
193
+ return { ...await vscode.workspace.fs.stat(getEncapsulatedUri(uri)), permissions: vscode.FilePermission.Readonly };
194
+ }
195
+ openFile(uri) {
196
+ return openFile(getEncapsulatedUri(uri));
197
+ }
198
+ readFile(uri) {
199
+ return vscode.workspace.fs.readFile(getEncapsulatedUri(uri));
200
+ }
201
+ }
202
+ exports.ReadOnlyFilesystem = ReadOnlyFilesystem;
203
+ class SubfileFileSystem extends BaseFileSystem {
204
+ static SCHEME = 'subfile';
205
+ static makeUri(uri, offset) {
206
+ return uri.with({
207
+ scheme: 'subfile',
208
+ authority: uri.scheme,
209
+ fragment: `${offset.fromOffset};${offset.toOffset}`
210
+ });
211
+ }
212
+ static parseUri(uri) {
213
+ const parts = uri.fragment.split(';');
214
+ return {
215
+ uri: getEncapsulatedUri(uri),
216
+ offset: { fromOffset: +parts[0], toOffset: +parts[1] }
217
+ };
218
+ }
219
+ constructor(context) {
220
+ super(context, SubfileFileSystem.SCHEME);
221
+ }
222
+ async stat(uri) {
223
+ const { uri: uri2, offset } = SubfileFileSystem.parseUri(uri);
224
+ return { ...await vscode.workspace.fs.stat(uri2), size: offset.toOffset - offset.fromOffset };
225
+ }
226
+ async readFile(uri) {
227
+ const { uri: uri2, offset } = SubfileFileSystem.parseUri(uri);
228
+ const file = await openFile(uri2);
229
+ if (file) {
230
+ try {
231
+ return file.read(offset.fromOffset, offset.toOffset - offset.fromOffset);
232
+ }
233
+ finally {
234
+ file.dispose();
235
+ }
236
+ }
237
+ else {
238
+ const data = await vscode.workspace.fs.readFile(uri2);
239
+ return data.subarray(offset.fromOffset, offset.toOffset);
240
+ }
241
+ }
242
+ async openFile(uri) {
243
+ const { uri: uri2, offset } = SubfileFileSystem.parseUri(uri);
244
+ return withOffset(await openFile(uri2), offset);
245
+ }
246
+ }
247
+ exports.SubfileFileSystem = SubfileFileSystem;
248
+ //-----------------------------------------------------------------------------
249
+ // Glob
250
+ //-----------------------------------------------------------------------------
251
+ class Glob {
252
+ regexp;
253
+ constructor(pattern) {
254
+ if (typeof pattern === 'string' && pattern.includes(';'))
255
+ pattern = pattern.split(';');
256
+ const re = Array.isArray(pattern)
257
+ ? '(' + pattern.map(s => toRegExp(s)).join('|') + ')'
258
+ : toRegExp(pattern);
259
+ this.regexp = new RegExp(re + '$');
260
+ }
261
+ test(input) {
262
+ return this.regexp?.test(input) ?? false;
263
+ }
264
+ }
265
+ exports.Glob = Glob;
266
+ function toOSPath(input) {
267
+ if (!input)
268
+ return '';
269
+ return input
270
+ .replace(/\\/g, path.sep)
271
+ .trim();
272
+ //.replace(new RegExp(`${path.sep}$`), '');
273
+ }
274
+ function toRegExp(pattern) {
275
+ let re = "", range = false, block = false;
276
+ for (let i = 0; i < pattern.length; i++) {
277
+ const c = pattern[i];
278
+ switch (c) {
279
+ default:
280
+ re += c;
281
+ break;
282
+ case ".":
283
+ case "/":
284
+ case "\\":
285
+ case "$":
286
+ case "^":
287
+ re += "\\" + c;
288
+ break;
289
+ case "?":
290
+ re += ".";
291
+ break;
292
+ case "[":
293
+ re += "[";
294
+ range = true;
295
+ break;
296
+ case "]":
297
+ re += "]";
298
+ range = false;
299
+ break;
300
+ case "!":
301
+ re += range ? "^" : "!";
302
+ break;
303
+ case "{":
304
+ re += "(";
305
+ block = true;
306
+ break;
307
+ case "}":
308
+ re += ")";
309
+ block = false;
310
+ break;
311
+ case ",":
312
+ re += block ? "|" : "\\,";
313
+ break;
314
+ case "*":
315
+ if (pattern[i + 1] === "*") {
316
+ re += ".*";
317
+ i++;
318
+ if (pattern[i + 1] === "/" || pattern[i + 1] === "\\")
319
+ i++;
320
+ }
321
+ else {
322
+ re += "[^/\\\\]*";
323
+ }
324
+ break;
325
+ }
326
+ }
327
+ return re;
328
+ }
329
+ function readDirectory(dir) {
330
+ return vscode.workspace.fs.stat(uri(dir)).then(stat => {
331
+ if (stat.type == vscode.FileType.Directory) {
332
+ return vscode.workspace.fs.readDirectory(uri(dir)).then(items => items, error => {
333
+ console.log(`readDirectory failed with ${error}`);
334
+ return [];
335
+ });
336
+ }
337
+ else {
338
+ console.log(`readDirectory ${dir} is not a directory`);
339
+ return Promise.resolve([]);
340
+ }
341
+ }, error => {
342
+ console.log(`readDirectory failed with ${error}`);
343
+ return Promise.resolve([]);
344
+ });
345
+ }
346
+ function directories(entries) {
347
+ return entries.filter(e => e[1] == vscode.FileType.Directory).map(e => e[0]);
348
+ }
349
+ function files(entries, glob) {
350
+ if (glob) {
351
+ const include = typeof glob === 'string' ? new Glob(glob) : glob;
352
+ return entries.filter(e => e[1] == vscode.FileType.File && include.test(e[0])).map(e => e[0]);
353
+ }
354
+ else {
355
+ return entries.filter(e => e[1] == vscode.FileType.File).map(e => e[0]);
356
+ }
357
+ }
358
+ async function search(pattern, _exclude, want = vscode.FileType.Unknown) {
359
+ const m = /[*?[{}]/.exec(pattern);
360
+ if (!m)
361
+ return [pattern];
362
+ const sep = pattern.lastIndexOf('\\', m.index);
363
+ const basePath = pattern.substring(0, sep);
364
+ const include = new Glob(pattern.substring(sep + 1));
365
+ const exclude = _exclude ? new Glob(_exclude) : undefined;
366
+ const keep = want || vscode.FileType.File;
367
+ const recurse = async (basePath) => {
368
+ const items = await readDirectory(basePath);
369
+ const result = [];
370
+ for (const i of items) {
371
+ if (want && i[1] !== want)
372
+ continue;
373
+ const filename = path.join(basePath, i[0]);
374
+ if (exclude && exclude.test(filename))
375
+ continue;
376
+ if (i[1] === keep && include.test(filename))
377
+ result.push(filename);
378
+ if (i[1] == vscode.FileType.Directory)
379
+ result.push(...await recurse(filename));
380
+ }
381
+ return result;
382
+ };
383
+ return recurse(basePath);
384
+ }
385
+ async function mapDirs(root, glob, onFile, combine) {
386
+ const glob2 = typeof glob === 'string' ? new Glob(glob) : glob;
387
+ return readDirectory(root).then(async (dir) => combine(...await Promise.all(files(dir, glob).map(i => onFile(path.join(root, i)))), ...await Promise.all(directories(dir).map(async (i) => mapDirs(path.join(root, i), glob2, onFile, combine)))));
388
+ }
389
+ //-----------------------------------------------------------------------------
390
+ // helpers
391
+ //-----------------------------------------------------------------------------
392
+ function stat_reject(value) {
393
+ return vscode.workspace.fs.stat(uri(value));
394
+ }
395
+ function exists(value) {
396
+ return vscode.workspace.fs.stat(uri(value)).then(() => true, () => false);
397
+ }
398
+ function getStat(value) {
399
+ return vscode.workspace.fs.stat(uri(value)).then(stat => stat, () => undefined);
400
+ }
401
+ function isDirectory(value) {
402
+ return vscode.workspace.fs.stat(uri(value)).then(stat => stat.type == vscode.FileType.Directory, () => ext(value) === "");
403
+ }
404
+ async function loadFile(file) {
405
+ return vscode.workspace.fs.readFile(uri(file)).then(bytes => bytes, error => console.log(`Failed to load ${file} : ${error}`));
406
+ }
407
+ function writeFile(file, bytes) {
408
+ return vscode.workspace.fs.writeFile(uri(file), bytes).then(() => true, error => (console.log(`Failed to save ${file} : ${error}`), false));
409
+ }
410
+ function deleteFile(file) {
411
+ return vscode.workspace.fs.delete(uri(file)).then(() => true, error => (console.log(`Failed to delete ${file} : ${error}`), false));
412
+ }
413
+ function createDirectory(path) {
414
+ return vscode.workspace.fs.createDirectory(uri(path)).then(() => true, error => (console.log(`Failed to create ${path} : ${error}`), false));
415
+ }
416
+ async function createNewName(filepath) {
417
+ const parsed = pathComponents(filepath);
418
+ let counter = 0;
419
+ const m = /\d+$/.exec(parsed.name);
420
+ if (m) {
421
+ counter = parseInt(m[0]);
422
+ parsed.name = parsed.name.substring(0, m.index);
423
+ }
424
+ while (await exists(filepath))
425
+ filepath = withPathComponents(filepath, parsed.dir, `${parsed.name}${++counter}${parsed.ext}`);
426
+ return filepath;
427
+ }
428
+ async function createCopyName(filepath) {
429
+ const parsed = pathComponents(filepath);
430
+ let counter = 1;
431
+ while (await exists(filepath)) {
432
+ filepath = withPathComponents(filepath, parsed.dir, `${parsed.name} copy${(counter > 1 ? ' ' + counter : '')}${parsed.ext}`);
433
+ counter++;
434
+ }
435
+ return filepath;
436
+ }
437
+ async function copyFile(sourcepath, destpath) {
438
+ return vscode.workspace.fs.readFile(uri(sourcepath)).then(async (bytes) => vscode.workspace.fs.writeFile(uri(destpath), bytes));
439
+ }
440
+ async function copyFileToDir(sourcepath, destdir) {
441
+ const dest = createCopyName(join(destdir, basename(sourcepath)));
442
+ const bytes = await vscode.workspace.fs.readFile(uri(sourcepath));
443
+ const destpath = await dest;
444
+ vscode.workspace.fs.writeFile(uri(destpath), bytes);
445
+ return destpath;
446
+ }
447
+ async function copyDirectory(sourcepath, targetpath) {
448
+ const dest = createCopyName(join(targetpath, basename(sourcepath)));
449
+ const dir = await readDirectory(sourcepath);
450
+ let result = [];
451
+ for (const i of dir) {
452
+ const sourcepath2 = join(sourcepath, i[0]);
453
+ if (i[1] === vscode.FileType.Directory)
454
+ result = [...result, ...await copyDirectory(sourcepath2, await dest)];
455
+ else
456
+ result.push(await copyFileToDir(sourcepath2, await dest));
457
+ }
458
+ return result;
459
+ }
460
+ //-----------------------------------------------------------------------------
461
+ // watchers
462
+ //-----------------------------------------------------------------------------
463
+ exports.Change = {
464
+ changed: 0,
465
+ created: 1,
466
+ deleted: 2,
467
+ renamed: 3,
468
+ };
469
+ const recWatchers = {};
470
+ const dirWatchers = {};
471
+ const fileModTimes = {};
472
+ const recCallbacks = {};
473
+ const dirCallbacks = {};
474
+ const fileCallbacks = {};
475
+ let wait_create = Promise.resolve();
476
+ function runCallbacks(callbacks, id, mode) {
477
+ if (callbacks)
478
+ callbacks.forEach(func => func(id, mode));
479
+ }
480
+ function runGlobCallbacks(callbacks, id, mode) {
481
+ if (callbacks) {
482
+ const base = path.basename(id);
483
+ callbacks.forEach(func => func[0].test(base) && func[1](id, mode));
484
+ }
485
+ }
486
+ async function dirCallback(uri, mode) {
487
+ const id = file_id(uri);
488
+ switch (mode) {
489
+ case exports.Change.changed:
490
+ if (fileCallbacks[id] && await stat_reject(uri).then(stat => {
491
+ if (fileModTimes[stat.mtime] === id)
492
+ return false;
493
+ fileModTimes[stat.mtime] = id;
494
+ return true;
495
+ }, _ => true)) {
496
+ console.log(`Changed: ${uri}`);
497
+ runCallbacks(fileCallbacks[id], id, mode);
498
+ }
499
+ break;
500
+ case exports.Change.created:
501
+ console.log(`Created: ${uri}`);
502
+ wait_create = wait_create.then(() => stat_reject(uri).then(stat => {
503
+ const _renamed = fileModTimes[stat.mtime];
504
+ if (_renamed) {
505
+ const renamed = file_id(_renamed);
506
+ console.log(`Rename: ${renamed} to ${uri}`);
507
+ fileModTimes[stat.mtime] = id;
508
+ fileCallbacks[id] = fileCallbacks[renamed];
509
+ delete fileCallbacks[renamed];
510
+ runCallbacks(fileCallbacks[id], id, 3);
511
+ }
512
+ }, _ => { }));
513
+ break;
514
+ case exports.Change.deleted:
515
+ console.log(`Deleted: ${uri}`);
516
+ wait_create.then(() => runCallbacks(fileCallbacks[id], id, mode));
517
+ break;
518
+ }
519
+ runGlobCallbacks(dirCallbacks[dirname(uri)], id, mode);
520
+ }
521
+ function recCallback(uri, mode) {
522
+ const id = file_id(uri);
523
+ fileCallbacks[id]?.forEach(func => func(id, mode));
524
+ runGlobCallbacks(dirCallbacks[dirname(uri)], id, mode);
525
+ for (const i in recCallbacks) {
526
+ if (id.startsWith(i))
527
+ runCallbacks(recCallbacks[i], id, mode);
528
+ }
529
+ }
530
+ function onChange(filename, func) {
531
+ const fulluri = uri(filename);
532
+ let dir = dirname(filename);
533
+ const rec = dir.indexOf('*');
534
+ if (rec !== -1)
535
+ dir = dir.substring(0, rec - 1);
536
+ let watcher = rec === -1 ? dirWatchers[dir] : recWatchers[dir];
537
+ if (!watcher && !Object.keys(recWatchers).some(i => dir.startsWith(i))) {
538
+ if (rec >= 0) {
539
+ for (const i in dirWatchers) {
540
+ if (i.startsWith(dir)) {
541
+ dirWatchers[i].dispose();
542
+ delete dirWatchers[i];
543
+ }
544
+ }
545
+ watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(withPathComponents(fulluri, dir), "**/*.*"));
546
+ watcher.onDidChange((uri) => recCallback(uri, exports.Change.changed));
547
+ watcher.onDidCreate((uri) => recCallback(uri, exports.Change.created));
548
+ watcher.onDidDelete((uri) => recCallback(uri, exports.Change.deleted));
549
+ recWatchers[dir] = watcher;
550
+ }
551
+ else {
552
+ watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(withPathComponents(fulluri, dir), "*.*"));
553
+ watcher.onDidChange((uri) => dirCallback(uri, exports.Change.changed));
554
+ watcher.onDidCreate((uri) => dirCallback(uri, exports.Change.created));
555
+ watcher.onDidDelete((uri) => dirCallback(uri, exports.Change.deleted));
556
+ dirWatchers[dir] = watcher;
557
+ }
558
+ }
559
+ if (rec >= 0) {
560
+ //recursive
561
+ (recCallbacks[dir] ??= []).push(func);
562
+ }
563
+ else if (basename(filename).indexOf('*') >= 0) {
564
+ //directory
565
+ (dirCallbacks[dir] ??= []).push([new Glob(basename(filename)), func]);
566
+ }
567
+ else {
568
+ //file
569
+ stat_reject(filename).then(stat => fileModTimes[stat.mtime] = file_id(filename), _ => { });
570
+ (fileCallbacks[filename.toString()] ??= []).push(func);
571
+ }
572
+ }
573
+ function arrayRemove(array, item) {
574
+ const index = array.indexOf(item);
575
+ if (index === -1)
576
+ return false;
577
+ array.splice(index, 1);
578
+ return true;
579
+ }
580
+ function removeOnChange(filename, func) {
581
+ const dir = dirname(filename);
582
+ if (dir.indexOf('*') >= 0) {
583
+ //recursive
584
+ const callbacks = recCallbacks[dir];
585
+ if (callbacks) {
586
+ arrayRemove(callbacks, func);
587
+ if (callbacks.length === 0) {
588
+ delete recCallbacks[dir];
589
+ const watcher = recWatchers[dir];
590
+ if (watcher) {
591
+ watcher.dispose();
592
+ delete recWatchers[dir];
593
+ }
594
+ }
595
+ }
596
+ }
597
+ else {
598
+ if (basename(filename).indexOf('*') === -1) {
599
+ //file
600
+ const callbacks = fileCallbacks[filename.toString()];
601
+ if (callbacks) {
602
+ arrayRemove(callbacks, func);
603
+ if (callbacks.length)
604
+ return;
605
+ delete fileCallbacks[filename.toString()];
606
+ }
607
+ }
608
+ //directory
609
+ const callbacks = dirCallbacks[dir];
610
+ if (callbacks) {
611
+ const i = callbacks.findIndex(i => i[1] === func);
612
+ if (i !== -1) {
613
+ callbacks.splice(i, 1);
614
+ if (callbacks.length)
615
+ return;
616
+ delete dirCallbacks[dir];
617
+ const watcher = dirWatchers[dir];
618
+ if (watcher) {
619
+ watcher.dispose();
620
+ delete dirWatchers[dir];
621
+ }
622
+ }
623
+ }
624
+ }
625
+ }
@@ -0,0 +1,63 @@
1
+ import * as vscode from 'vscode';
2
+ interface ImageIcon {
3
+ iconPath: string;
4
+ }
5
+ interface FontIcon {
6
+ fontCharacter: string;
7
+ fontColor?: string;
8
+ fontSize?: number;
9
+ fontId?: string;
10
+ }
11
+ interface FontSource {
12
+ path: string;
13
+ format: string;
14
+ }
15
+ interface Font {
16
+ id: string;
17
+ src: FontSource[];
18
+ weight: string;
19
+ style: string;
20
+ size: string;
21
+ }
22
+ interface ThemeData {
23
+ iconDefinitions: Record<string, ImageIcon | FontIcon>;
24
+ fonts: Font[];
25
+ file: string;
26
+ folder: string;
27
+ folderExpanded: string;
28
+ rootFolder: string;
29
+ rootFolderExpanded: string;
30
+ folderNames: Record<string, string>;
31
+ folderNamesExpanded: Record<string, string>;
32
+ rootFolderNames: Record<string, string>;
33
+ rootFolderNamesExpanded: Record<string, string>;
34
+ languageIds: Record<string, string>;
35
+ fileExtensions: Record<string, string>;
36
+ fileNames: Record<string, string>;
37
+ }
38
+ export declare function getLanguage(ext: string): any;
39
+ export declare class IconTheme {
40
+ themeFolder: vscode.Uri;
41
+ theme: ThemeData;
42
+ constructor(themeFolder: vscode.Uri, theme: ThemeData);
43
+ private getUri;
44
+ style(webview: vscode.Webview): string;
45
+ csp(webview: vscode.Webview): vscode.Uri;
46
+ get_def(webview: vscode.Webview, icon?: string): {
47
+ icon: vscode.Uri;
48
+ } | {
49
+ style?: string | undefined;
50
+ font: string;
51
+ icon: string;
52
+ } | undefined;
53
+ getLanguageIcon(ext: string): string | undefined;
54
+ getFileIcon(name: string): string | undefined;
55
+ getFolderIcon(name: string, expanded?: boolean): string | undefined;
56
+ getRootFolderIcon(name: string, expanded?: boolean): string | undefined;
57
+ getFileIconForUri(uri: vscode.Uri): string | undefined;
58
+ getFolderIconForUri(uri: vscode.Uri, expanded?: boolean, root?: vscode.Uri): string | undefined;
59
+ copyAssets(dest: vscode.Uri, changeFolder?: boolean): Promise<void>;
60
+ }
61
+ export declare function getIconTheme(id: string): vscode.Uri | undefined;
62
+ export declare function loadIconTheme(): Promise<IconTheme | undefined>;
63
+ export {};