@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.
@@ -0,0 +1,199 @@
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.IconTheme = void 0;
37
+ exports.getLanguage = getLanguage;
38
+ exports.getIconTheme = getIconTheme;
39
+ exports.loadIconTheme = loadIconTheme;
40
+ const vscode = __importStar(require("vscode"));
41
+ const path = __importStar(require("path"));
42
+ function getLanguage(ext) {
43
+ const ext2 = ext[0] == '.' ? ext.slice(1) : '.' + ext;
44
+ for (const extension of vscode.extensions.all) {
45
+ const languages = extension.packageJSON.contributes?.languages;
46
+ if (languages) {
47
+ for (const lang of languages) {
48
+ if (lang.extensions?.includes(ext) || lang.extensions?.includes(ext2))
49
+ return lang.id;
50
+ }
51
+ }
52
+ }
53
+ }
54
+ class IconTheme {
55
+ themeFolder;
56
+ theme;
57
+ constructor(themeFolder, theme) {
58
+ this.themeFolder = themeFolder;
59
+ this.theme = theme;
60
+ for (const def of Object.values(theme.iconDefinitions)) {
61
+ if ('fontCharacter' in def)
62
+ def.fontCharacter = String.fromCharCode(parseInt(def.fontCharacter.slice(1), 16));
63
+ }
64
+ }
65
+ getUri(webview, file) {
66
+ return webview.asWebviewUri(vscode.Uri.file(path.join(this.themeFolder.fsPath, file)));
67
+ }
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
+ }
79
+ `).join('\n') : '';
80
+ }
81
+ csp(webview) {
82
+ return webview.asWebviewUri(this.themeFolder);
83
+ }
84
+ get_def(webview, icon) {
85
+ if (icon) {
86
+ const def = this.theme.iconDefinitions[icon];
87
+ if (def) {
88
+ if ('iconPath' in def)
89
+ return {
90
+ icon: this.getUri(webview, def.iconPath)
91
+ };
92
+ return {
93
+ font: def.fontId || this.theme.fonts[0].id,
94
+ icon: def.fontCharacter,
95
+ ...(def.fontColor ? { style: `--icon-color: ${def.fontColor}` } : {})
96
+ };
97
+ }
98
+ }
99
+ }
100
+ getLanguageIcon(ext) {
101
+ const lang = getLanguage(ext);
102
+ return lang && this.theme.languageIds[lang];
103
+ }
104
+ getFileIcon(name) {
105
+ let icon = this.theme.fileNames[name];
106
+ if (!icon && (this.theme.fileExtensions || this.theme.languageIds)) {
107
+ const exts = name.split('.');
108
+ while (!icon && exts.length > 1) {
109
+ exts.shift();
110
+ const ext = exts.join('.');
111
+ if (this.theme.languageIds && (icon = this.getLanguageIcon(ext)))
112
+ return icon;
113
+ icon = this.theme.fileExtensions?.[ext];
114
+ }
115
+ }
116
+ return icon || this.theme.file;
117
+ }
118
+ getFolderIcon(name, expanded = false) {
119
+ return (expanded && this.theme.folderNamesExpanded?.[name])
120
+ || this.theme.folderNames?.[name]
121
+ || (expanded && this.theme.folderExpanded)
122
+ || this.theme.folder;
123
+ }
124
+ getRootFolderIcon(name, expanded = false) {
125
+ return (expanded && this.theme.rootFolderNamesExpanded?.[name])
126
+ || this.theme.rootFolderNames?.[name]
127
+ || (expanded && this.theme.folderNamesExpanded?.[name])
128
+ || this.theme.folderNames?.[name]
129
+ || (expanded && this.theme.rootFolderExpanded)
130
+ || this.theme.rootFolder
131
+ || (expanded && this.theme.folderExpanded)
132
+ || this.theme.folder;
133
+ }
134
+ getFileIconForUri(uri) {
135
+ const comps = uri.fsPath.split(path.sep);
136
+ const last = comps.at(-1);
137
+ let icon = this.theme.fileNames[comps.slice(-2).join('/')] || this.theme.fileNames[last];
138
+ if (!icon && (this.theme.fileExtensions || this.theme.languageIds)) {
139
+ const exts = last.split('.');
140
+ const dir = comps.at(-2);
141
+ while (!icon && exts.length > 1) {
142
+ exts.shift();
143
+ const ext = exts.join('.');
144
+ if (this.theme.languageIds && (icon = this.getLanguageIcon(ext)))
145
+ return icon;
146
+ if (this.theme.fileExtensions)
147
+ icon = this.theme.fileExtensions[ext] || this.theme.fileExtensions[`${dir}/${ext}`];
148
+ }
149
+ }
150
+ return icon || this.theme.file;
151
+ }
152
+ getFolderIconForUri(uri, expanded = false, root) {
153
+ if (root && uri.fsPath.startsWith(root.fsPath))
154
+ return this.getRootFolderIcon(root.fsPath.slice(root.fsPath.length), expanded);
155
+ const comps = uri.fsPath.split(path.sep);
156
+ const last = comps.at(-1);
157
+ const last2 = comps.slice(-2).join('/');
158
+ return (expanded ? this.theme.folderNamesExpanded?.[last2] : this.theme.folderNames?.[last2])
159
+ || this.getFolderIcon(last, expanded);
160
+ }
161
+ async copyAssets(dest, changeFolder = false) {
162
+ const srce = this.themeFolder;
163
+ function copy(name) {
164
+ return vscode.workspace.fs.copy(vscode.Uri.joinPath(srce, name), vscode.Uri.joinPath(dest, name), { overwrite: true });
165
+ }
166
+ if (this.theme.iconDefinitions) {
167
+ for (const def of Object.values(this.theme.iconDefinitions)) {
168
+ if ('iconPath' in def)
169
+ await copy(def.iconPath);
170
+ }
171
+ }
172
+ if (this.theme.fonts) {
173
+ for (const font of this.theme.fonts) {
174
+ for (const src of font.src) {
175
+ if (src.path)
176
+ await copy(src.path);
177
+ }
178
+ }
179
+ }
180
+ if (changeFolder)
181
+ this.themeFolder = dest;
182
+ }
183
+ }
184
+ exports.IconTheme = IconTheme;
185
+ function getIconTheme(id) {
186
+ for (const extension of vscode.extensions.all) {
187
+ const themes = extension.packageJSON.contributes?.iconThemes;
188
+ const theme = themes && themes.find((theme) => theme.id === id);
189
+ if (theme)
190
+ return vscode.Uri.joinPath(extension.extensionUri, theme.path);
191
+ }
192
+ }
193
+ async function loadIconTheme() {
194
+ const theme = vscode.workspace.getConfiguration("workbench").get("iconTheme");
195
+ const source = theme && getIconTheme(theme);
196
+ if (source) {
197
+ return new IconTheme(source.with({ path: path.dirname(source.path) }), await vscode.workspace.fs.readFile(source).then(buffer => JSON.parse(buffer.toString()), () => ({})));
198
+ }
199
+ }
@@ -0,0 +1,91 @@
1
+ export declare class Lazy<T> {
2
+ private factory;
3
+ private _value;
4
+ constructor(factory: () => T);
5
+ get value(): T;
6
+ }
7
+ export declare class AsyncLazy<T> {
8
+ private factory;
9
+ private _value;
10
+ constructor(factory: () => Promise<T>);
11
+ get value(): (T & {}) | null;
12
+ }
13
+ export declare class CallCombiner0 {
14
+ private timeout;
15
+ combine(delay: number, func: () => void): void;
16
+ pending(): boolean;
17
+ }
18
+ export declare class CallCombiner extends CallCombiner0 {
19
+ private func;
20
+ private delay;
21
+ constructor(func: () => void, delay: number);
22
+ trigger(): void;
23
+ }
24
+ export declare function makeCache<T>(load: (key: string) => T): {
25
+ get: (fullpath: string) => T;
26
+ remove: (fullpath: string) => void;
27
+ };
28
+ export declare function compare<T>(a: T, b: T): number;
29
+ export declare function reverse_compare<T>(a: T, b: T): number;
30
+ export declare function reverse<T, R>(func: (a: T, b: T) => R): (a: T, b: T) => R;
31
+ export declare function merge(...list: Record<string, any>[]): Record<string, any>;
32
+ type PartitionIndex<U> = U extends boolean ? 'true' | 'false' : U;
33
+ export declare function partition<T, U extends keyof any | boolean>(array: Iterable<T>, func: (v: T) => U): Record<PartitionIndex<U>, T[]>;
34
+ export declare function isEmpty(obj: object): boolean;
35
+ export declare function clone<T extends object>(obj: T): T;
36
+ export declare function lowerBound<T>(array: T[], value: T, func: (a: T, b: T, i: number) => boolean): number;
37
+ export declare function argmin<T>(array: T[], fn?: (i: T) => number): number;
38
+ type Constructor<T, D, O = void> = new (arg: T, opt: O) => D;
39
+ type Factory<T, D, O = void> = (arg: T, opt: O) => D;
40
+ export type ClassOrFactory<T, D, O = void> = Constructor<T, D, O> | Factory<T, D, O>;
41
+ export declare function make<T, D, O>(maker: ClassOrFactory<T, D, O>, arg: T, opt?: O): D;
42
+ export type SpreadType<T> = T extends Iterable<infer U> ? U[] : never;
43
+ export declare function arrayAppend<T, U extends Iterable<T>>(array: T[], items: U): void;
44
+ export declare function arrayRemove<T>(array: T[], item: T): boolean;
45
+ export declare function arrayCompare<T>(arr1: T[], arr2: T[]): number;
46
+ export declare function arrayEqual<T>(arr1: T[], arr2: T[]): boolean;
47
+ export declare function arrayRotate<T>(array: T[], start: number, end: number, shift: number): void;
48
+ export declare function arrayReverse<T>(array: T[], start: number, end: number): void;
49
+ export declare function array_make<T>(n: number, constructor: new () => T): T[];
50
+ export declare function eachIterable<T>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => void): void;
51
+ export declare function findIterable<T>(iterable: Iterable<T> | undefined, func: (v: T) => boolean): T | undefined;
52
+ export declare function mapIterable<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => U): U[];
53
+ export declare function asyncMap<T, U>(iterable: Iterable<T> | undefined, func: (v: T, i: number) => Promise<U>): Promise<U[]>;
54
+ export declare function asyncReduce<T, U>(array: T[], func: (acc: U, v: T, i: number, array: T[]) => Promise<U>, initialValue: U): Promise<U>;
55
+ export declare function parallel(...fns: (() => any)[]): Promise<any[]>;
56
+ export declare function serial(...fns: (() => any)[]): Promise<any[]>;
57
+ export declare function filterIterable<T>(iterable: Iterable<T>, func: (v: T, i: number) => boolean): T[];
58
+ export declare function asyncFilter<T>(iterable: Iterable<T>, func: (v: T) => Promise<boolean>): Promise<T[]>;
59
+ export declare function mapObject<T, U>(obj: Record<string, T>, func: (x: [k: string, v: T]) => [k: string, v: U]): Record<string, U>;
60
+ export declare function filterObject<T>(obj: Record<string, T>, func: (x: [k: string, v: T]) => boolean): Record<string, T>;
61
+ export declare function firstOf(value: string, find: string): number;
62
+ export declare function lastOf(value: string, find: string): number;
63
+ export declare function splitFirstOf(value: string, find: string): (string | undefined)[];
64
+ export declare function splitLastOf(value: string, find: string): (string | undefined)[];
65
+ export declare function trim0(value: string): string;
66
+ export declare function replace(value: string, re: RegExp, process: (match: RegExpExecArray) => string): string;
67
+ export declare function async_replace(value: string, re: RegExp, process: (match: RegExpExecArray) => Promise<string>): Promise<string>;
68
+ export declare function replace_back(value: string, re: RegExp, process: (match: RegExpExecArray, right: string) => string): string;
69
+ export declare function async_replace_back(value: string, re: RegExp, process: (match: RegExpExecArray, right: string) => Promise<string>): Promise<string>;
70
+ export declare function splitEvery(s: string, n: number): string[];
71
+ export declare function tag(strings: TemplateStringsArray, ...keys: any[]): (...values: any[]) => string;
72
+ export declare function stringCode(s: string): number;
73
+ export declare function stringCodeBig(s: string): bigint;
74
+ export declare function previousChar(str: string, pos: number): string;
75
+ export declare function hasCustomToString(value: any): boolean;
76
+ export declare class StringParser {
77
+ subject: string;
78
+ pos: number;
79
+ constructor(subject: string, pos?: number);
80
+ remaining(): number;
81
+ remainder(): string;
82
+ processed(): string;
83
+ peek(): string;
84
+ peekn(n: number): string;
85
+ get(n: number): string;
86
+ skip(c: string): boolean;
87
+ expect(c: string): void;
88
+ match(re: RegExp): string | undefined;
89
+ exec(re: RegExp): RegExpExecArray | undefined;
90
+ }
91
+ export {};