@isopodlabs/vscode_utils 0.2.6 → 0.3.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.
package/dist/fs.js CHANGED
@@ -56,16 +56,15 @@ exports.copyFile = copyFile;
56
56
  exports.copyFileToDir = copyFileToDir;
57
57
  exports.copyDirectory = copyDirectory;
58
58
  exports.onChange = onChange;
59
- exports.arrayRemove = arrayRemove;
60
59
  exports.removeOnChange = removeOnChange;
61
- const vscode = __importStar(require("vscode"));
62
60
  const nodefs = __importStar(require("fs"));
63
61
  const path = __importStar(require("path"));
62
+ const vscode_1 = require("vscode");
64
63
  function uri(value) {
65
- return value instanceof vscode.Uri ? value : vscode.Uri.file(value);
64
+ return value instanceof vscode_1.Uri ? value : vscode_1.Uri.file(value);
66
65
  }
67
66
  function file(value) {
68
- return value instanceof vscode.Uri ? value.fsPath : value;
67
+ return value instanceof vscode_1.Uri ? value.fsPath : value;
69
68
  }
70
69
  function file_id(value) {
71
70
  return typeof (value) === 'string' ? value : value.scheme === 'file' ? value.fsPath : value.toString();
@@ -84,7 +83,7 @@ function pathComponents(value) {
84
83
  }
85
84
  function withPathComponents(value, ...comp) {
86
85
  const p = path.join(...comp);
87
- return value instanceof vscode.Uri ? value.with({ path: p }) : p;
86
+ return value instanceof vscode_1.Uri ? value.with({ path: p }) : p;
88
87
  }
89
88
  function join(directory, ...comp) {
90
89
  return withPathComponents(directory, file(directory), ...comp);
@@ -94,10 +93,10 @@ function isFile(obj) {
94
93
  }
95
94
  const filesystems = {};
96
95
  class BaseFileSystem {
97
- _onDidChangeFile = new vscode.EventEmitter();
96
+ _onDidChangeFile = new vscode_1.EventEmitter();
98
97
  constructor(context, scheme) {
99
98
  filesystems[scheme] = this;
100
- context.subscriptions.push(vscode.workspace.registerFileSystemProvider(scheme, this, { isCaseSensitive: true }));
99
+ context.subscriptions.push(vscode_1.workspace.registerFileSystemProvider(scheme, this, { isCaseSensitive: true }));
101
100
  }
102
101
  get onDidChangeFile() { return this._onDidChangeFile.event; }
103
102
  //stubs
@@ -111,7 +110,7 @@ class BaseFileSystem {
111
110
  }
112
111
  exports.BaseFileSystem = BaseFileSystem;
113
112
  function withOffset(file, offset) {
114
- if (file instanceof vscode.Uri)
113
+ if (file instanceof vscode_1.Uri)
115
114
  return SubfileFileSystem.makeUri(file, offset);
116
115
  return new class {
117
116
  length = offset.toOffset - offset.fromOffset;
@@ -182,7 +181,7 @@ function getEncapsulatedUri(uri) {
182
181
  scheme: uri.authority,
183
182
  authority: '',
184
183
  });
185
- // return vscode.Uri.parse(uri.fsPath);
184
+ // return Uri.parse(uri.fsPath);
186
185
  }
187
186
  class ReadOnlyFilesystem extends BaseFileSystem {
188
187
  static SCHEME = 'readonly';
@@ -190,13 +189,13 @@ class ReadOnlyFilesystem extends BaseFileSystem {
190
189
  super(context, ReadOnlyFilesystem.SCHEME);
191
190
  }
192
191
  async stat(uri) {
193
- return { ...await vscode.workspace.fs.stat(getEncapsulatedUri(uri)), permissions: vscode.FilePermission.Readonly };
192
+ return { ...await vscode_1.workspace.fs.stat(getEncapsulatedUri(uri)), permissions: vscode_1.FilePermission.Readonly };
194
193
  }
195
194
  openFile(uri) {
196
195
  return openFile(getEncapsulatedUri(uri));
197
196
  }
198
197
  readFile(uri) {
199
- return vscode.workspace.fs.readFile(getEncapsulatedUri(uri));
198
+ return vscode_1.workspace.fs.readFile(getEncapsulatedUri(uri));
200
199
  }
201
200
  }
202
201
  exports.ReadOnlyFilesystem = ReadOnlyFilesystem;
@@ -221,7 +220,7 @@ class SubfileFileSystem extends BaseFileSystem {
221
220
  }
222
221
  async stat(uri) {
223
222
  const { uri: uri2, offset } = SubfileFileSystem.parseUri(uri);
224
- return { ...await vscode.workspace.fs.stat(uri2), size: offset.toOffset - offset.fromOffset };
223
+ return { ...await vscode_1.workspace.fs.stat(uri2), size: offset.toOffset - offset.fromOffset };
225
224
  }
226
225
  async readFile(uri) {
227
226
  const { uri: uri2, offset } = SubfileFileSystem.parseUri(uri);
@@ -235,7 +234,7 @@ class SubfileFileSystem extends BaseFileSystem {
235
234
  }
236
235
  }
237
236
  else {
238
- const data = await vscode.workspace.fs.readFile(uri2);
237
+ const data = await vscode_1.workspace.fs.readFile(uri2);
239
238
  return data.subarray(offset.fromOffset, offset.toOffset);
240
239
  }
241
240
  }
@@ -327,9 +326,9 @@ function toRegExp(pattern) {
327
326
  return re;
328
327
  }
329
328
  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 => {
329
+ return vscode_1.workspace.fs.stat(uri(dir)).then(stat => {
330
+ if (stat.type == vscode_1.FileType.Directory) {
331
+ return vscode_1.workspace.fs.readDirectory(uri(dir)).then(items => items, error => {
333
332
  console.log(`readDirectory failed with ${error}`);
334
333
  return [];
335
334
  });
@@ -344,18 +343,18 @@ function readDirectory(dir) {
344
343
  });
345
344
  }
346
345
  function directories(entries) {
347
- return entries.filter(e => e[1] == vscode.FileType.Directory).map(e => e[0]);
346
+ return entries.filter(e => e[1] == vscode_1.FileType.Directory).map(e => e[0]);
348
347
  }
349
348
  function files(entries, glob) {
350
349
  if (glob) {
351
350
  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]);
351
+ return entries.filter(e => e[1] == vscode_1.FileType.File && include.test(e[0])).map(e => e[0]);
353
352
  }
354
353
  else {
355
- return entries.filter(e => e[1] == vscode.FileType.File).map(e => e[0]);
354
+ return entries.filter(e => e[1] == vscode_1.FileType.File).map(e => e[0]);
356
355
  }
357
356
  }
358
- async function search(pattern, _exclude, want = vscode.FileType.Unknown) {
357
+ async function search(pattern, _exclude, want = vscode_1.FileType.Unknown) {
359
358
  const m = /[*?[{}]/.exec(pattern);
360
359
  if (!m)
361
360
  return [pattern];
@@ -363,7 +362,7 @@ async function search(pattern, _exclude, want = vscode.FileType.Unknown) {
363
362
  const basePath = pattern.substring(0, sep);
364
363
  const include = new Glob(pattern.substring(sep + 1));
365
364
  const exclude = _exclude ? new Glob(_exclude) : undefined;
366
- const keep = want || vscode.FileType.File;
365
+ const keep = want || vscode_1.FileType.File;
367
366
  const recurse = async (basePath) => {
368
367
  const items = await readDirectory(basePath);
369
368
  const result = [];
@@ -375,7 +374,7 @@ async function search(pattern, _exclude, want = vscode.FileType.Unknown) {
375
374
  continue;
376
375
  if (i[1] === keep && include.test(filename))
377
376
  result.push(filename);
378
- if (i[1] == vscode.FileType.Directory)
377
+ if (i[1] == vscode_1.FileType.Directory)
379
378
  result.push(...await recurse(filename));
380
379
  }
381
380
  return result;
@@ -390,28 +389,28 @@ async function mapDirs(root, glob, onFile, combine) {
390
389
  // helpers
391
390
  //-----------------------------------------------------------------------------
392
391
  function stat_reject(value) {
393
- return vscode.workspace.fs.stat(uri(value));
392
+ return vscode_1.workspace.fs.stat(uri(value));
394
393
  }
395
394
  function exists(value) {
396
- return vscode.workspace.fs.stat(uri(value)).then(() => true, () => false);
395
+ return vscode_1.workspace.fs.stat(uri(value)).then(() => true, () => false);
397
396
  }
398
397
  function getStat(value) {
399
- return vscode.workspace.fs.stat(uri(value)).then(stat => stat, () => undefined);
398
+ return vscode_1.workspace.fs.stat(uri(value)).then(stat => stat, () => undefined);
400
399
  }
401
400
  function isDirectory(value) {
402
- return vscode.workspace.fs.stat(uri(value)).then(stat => stat.type == vscode.FileType.Directory, () => ext(value) === "");
401
+ return vscode_1.workspace.fs.stat(uri(value)).then(stat => stat.type == vscode_1.FileType.Directory, () => ext(value) === "");
403
402
  }
404
403
  async function loadFile(file) {
405
- return vscode.workspace.fs.readFile(uri(file)).then(bytes => bytes, error => console.log(`Failed to load ${file} : ${error}`));
404
+ return vscode_1.workspace.fs.readFile(uri(file)).then(bytes => bytes, error => console.log(`Failed to load ${file} : ${error}`));
406
405
  }
407
406
  function writeFile(file, bytes) {
408
- return vscode.workspace.fs.writeFile(uri(file), bytes).then(() => true, error => (console.log(`Failed to save ${file} : ${error}`), false));
407
+ return vscode_1.workspace.fs.writeFile(uri(file), bytes).then(() => true, error => (console.log(`Failed to save ${file} : ${error}`), false));
409
408
  }
410
409
  function deleteFile(file) {
411
- return vscode.workspace.fs.delete(uri(file)).then(() => true, error => (console.log(`Failed to delete ${file} : ${error}`), false));
410
+ return vscode_1.workspace.fs.delete(uri(file)).then(() => true, error => (console.log(`Failed to delete ${file} : ${error}`), false));
412
411
  }
413
412
  function createDirectory(path) {
414
- return vscode.workspace.fs.createDirectory(uri(path)).then(() => true, error => (console.log(`Failed to create ${path} : ${error}`), false));
413
+ return vscode_1.workspace.fs.createDirectory(uri(path)).then(() => true, error => (console.log(`Failed to create ${path} : ${error}`), false));
415
414
  }
416
415
  async function createNewName(filepath) {
417
416
  const parsed = pathComponents(filepath);
@@ -435,13 +434,13 @@ async function createCopyName(filepath) {
435
434
  return filepath;
436
435
  }
437
436
  async function copyFile(sourcepath, destpath) {
438
- return vscode.workspace.fs.readFile(uri(sourcepath)).then(async (bytes) => vscode.workspace.fs.writeFile(uri(destpath), bytes));
437
+ return vscode_1.workspace.fs.readFile(uri(sourcepath)).then(async (bytes) => vscode_1.workspace.fs.writeFile(uri(destpath), bytes));
439
438
  }
440
439
  async function copyFileToDir(sourcepath, destdir) {
441
440
  const dest = createCopyName(join(destdir, basename(sourcepath)));
442
- const bytes = await vscode.workspace.fs.readFile(uri(sourcepath));
441
+ const bytes = await vscode_1.workspace.fs.readFile(uri(sourcepath));
443
442
  const destpath = await dest;
444
- vscode.workspace.fs.writeFile(uri(destpath), bytes);
443
+ vscode_1.workspace.fs.writeFile(uri(destpath), bytes);
445
444
  return destpath;
446
445
  }
447
446
  async function copyDirectory(sourcepath, targetpath) {
@@ -450,7 +449,7 @@ async function copyDirectory(sourcepath, targetpath) {
450
449
  let result = [];
451
450
  for (const i of dir) {
452
451
  const sourcepath2 = join(sourcepath, i[0]);
453
- if (i[1] === vscode.FileType.Directory)
452
+ if (i[1] === vscode_1.FileType.Directory)
454
453
  result = [...result, ...await copyDirectory(sourcepath2, await dest)];
455
454
  else
456
455
  result.push(await copyFileToDir(sourcepath2, await dest));
@@ -542,14 +541,14 @@ function onChange(filename, func) {
542
541
  delete dirWatchers[i];
543
542
  }
544
543
  }
545
- watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(withPathComponents(fulluri, dir), "**/*.*"));
544
+ watcher = vscode_1.workspace.createFileSystemWatcher(new vscode_1.RelativePattern(withPathComponents(fulluri, dir), "**/*.*"));
546
545
  watcher.onDidChange((uri) => recCallback(uri, exports.Change.changed));
547
546
  watcher.onDidCreate((uri) => recCallback(uri, exports.Change.created));
548
547
  watcher.onDidDelete((uri) => recCallback(uri, exports.Change.deleted));
549
548
  recWatchers[dir] = watcher;
550
549
  }
551
550
  else {
552
- watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(withPathComponents(fulluri, dir), "*.*"));
551
+ watcher = vscode_1.workspace.createFileSystemWatcher(new vscode_1.RelativePattern(withPathComponents(fulluri, dir), "*.*"));
553
552
  watcher.onDidChange((uri) => dirCallback(uri, exports.Change.changed));
554
553
  watcher.onDidCreate((uri) => dirCallback(uri, exports.Change.created));
555
554
  watcher.onDidDelete((uri) => dirCallback(uri, exports.Change.deleted));
@@ -570,7 +569,7 @@ function onChange(filename, func) {
570
569
  (fileCallbacks[filename.toString()] ??= []).push(func);
571
570
  }
572
571
  }
573
- function arrayRemove(array, item) {
572
+ function array_remove(array, item) {
574
573
  const index = array.indexOf(item);
575
574
  if (index === -1)
576
575
  return false;
@@ -583,7 +582,7 @@ function removeOnChange(filename, func) {
583
582
  //recursive
584
583
  const callbacks = recCallbacks[dir];
585
584
  if (callbacks) {
586
- arrayRemove(callbacks, func);
585
+ array_remove(callbacks, func);
587
586
  if (callbacks.length === 0) {
588
587
  delete recCallbacks[dir];
589
588
  const watcher = recWatchers[dir];
@@ -599,7 +598,7 @@ function removeOnChange(filename, func) {
599
598
  //file
600
599
  const callbacks = fileCallbacks[filename.toString()];
601
600
  if (callbacks) {
602
- arrayRemove(callbacks, func);
601
+ array_remove(callbacks, func);
603
602
  if (callbacks.length)
604
603
  return;
605
604
  delete fileCallbacks[filename.toString()];
@@ -66,16 +66,16 @@ class IconTheme {
66
66
  return webview.asWebviewUri(vscode.Uri.file(path.join(this.themeFolder.fsPath, file)));
67
67
  }
68
68
  style(webview) {
69
- return this.theme.fonts ? this.theme.fonts.map(f => `@font-face {
70
- font-family: '${f.id}';
71
- src: ${f.src.map(s => `url('${this.getUri(webview, s.path)}') format('${s.format}')`).join(', ')};
72
- font-weight: ${f.weight};
73
- font-style: ${f.style};
74
- }
75
- [font=${f.id}]::before {
76
- font-family: ${f.id};
77
- font-size: ${f.size};
78
- }
69
+ return this.theme.fonts ? this.theme.fonts.map(f => `@font-face {
70
+ font-family: '${f.id}';
71
+ src: ${f.src.map(s => `url('${this.getUri(webview, s.path)}') format('${s.format}')`).join(', ')};
72
+ font-weight: ${f.weight};
73
+ font-style: ${f.style};
74
+ }
75
+ [font=${f.id}]::before {
76
+ font-family: ${f.id};
77
+ font-size: ${f.size};
78
+ }
79
79
  `).join('\n') : '';
80
80
  }
81
81
  csp(webview) {
@@ -1,5 +1,5 @@
1
1
  /** @jsxImportSource . */
2
- import * as vscode from 'vscode';
2
+ import { Uri, Webview } from 'vscode';
3
3
  export declare function jsx(type: any, props: any): any;
4
4
  export declare function jsxs(type: any, props: any): any;
5
5
  export declare function jsxFrag(props: any): {
@@ -16,20 +16,6 @@ export declare namespace JSX {
16
16
  function render(element: any): string;
17
17
  }
18
18
  export declare function id_selector(id: string | number): string;
19
- export declare const codicons: Record<string, string>;
20
- type IconType0 = string | vscode.Uri;
21
- export type IconType = IconType0 | vscode.ThemeIcon | {
22
- light: IconType0;
23
- dark: IconType0;
24
- };
25
- export declare function iconAttribute(icon: IconType0): string;
26
- export declare function iconAttributes(icon?: IconType): {
27
- icon: string;
28
- color?: undefined;
29
- } | {
30
- icon: string;
31
- color: string;
32
- } | undefined;
33
19
  export declare function Label({ id, display }: {
34
20
  id: string;
35
21
  display: string;
@@ -51,16 +37,23 @@ declare const CSPkeywords: {
51
37
  readonly inline_speculation_rules: "'inline-speculation-rules'";
52
38
  readonly strict_dynamic: "'strict-dynamic'";
53
39
  };
54
- type CSPSource = Hash | vscode.Uri | (typeof CSPkeywords)[keyof typeof CSPkeywords] | CSPSource[];
55
- export declare function CSPdefault(extension: vscode.Uri): CSPSource;
40
+ type CSPSource1 = Hash | Uri | (typeof CSPkeywords)[keyof typeof CSPkeywords] | CSPSource1[];
41
+ interface plus<T> {
42
+ source: T;
43
+ plus: boolean;
44
+ }
45
+ declare function plus(source: CSPSource1): plus<CSPSource1>;
46
+ type CSPSource = CSPSource1 | plus<CSPSource1>;
47
+ interface CSPSources {
48
+ main: CSPSource;
49
+ attr?: CSPSource;
50
+ elem?: CSPSource;
51
+ }
52
+ export declare function CSPdefault(extension: Uri): CSPSource1;
56
53
  declare function CSPFunction({ csp, ...others }: {
57
- csp: string;
58
- script?: CSPSource;
59
- script_elem?: CSPSource;
60
- script_attr?: CSPSource;
61
- style?: CSPSource;
62
- stype_elem?: CSPSource;
63
- style_attr?: CSPSource;
54
+ csp: CSPSource1;
55
+ script?: CSPSource | CSPSources;
56
+ style?: CSPSource | CSPSources;
64
57
  font?: CSPSource;
65
58
  img?: CSPSource;
66
59
  media?: CSPSource;
@@ -75,8 +68,8 @@ export declare const CSP: typeof CSPFunction & {
75
68
  readonly strict_dynamic: "'strict-dynamic'";
76
69
  };
77
70
  export declare function ImportMap(props: {
78
- map: Record<string, vscode.Uri>;
79
- webview: vscode.Webview;
71
+ map: Record<string, Uri>;
72
+ webview: Webview;
80
73
  nonce?: Hash;
81
74
  }): JSX.Element;
82
75
  export {};