@lune_99/pi-lune-extensions-core 0.1.0 → 0.2.1
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/CHANGELOG.md +77 -0
- package/README.md +117 -36
- package/dist/core/panel.d.ts +6 -1
- package/dist/core/panel.js +26 -1
- package/dist/core/settings.d.ts +9 -1
- package/dist/core/settings.js +36 -2
- package/dist/dock/registry.js +1 -0
- package/dist/extension.js +10 -2
- package/dist/mention/autocomplete.d.ts +25 -0
- package/dist/mention/autocomplete.js +140 -0
- package/dist/mention/budget.d.ts +8 -0
- package/dist/mention/budget.js +10 -0
- package/dist/mention/catalog.d.ts +43 -0
- package/dist/mention/catalog.js +117 -0
- package/dist/mention/claude.d.ts +2 -0
- package/dist/mention/claude.js +118 -0
- package/dist/mention/codex.d.ts +3 -0
- package/dist/mention/codex.js +135 -0
- package/dist/mention/external.d.ts +15 -0
- package/dist/mention/external.js +145 -0
- package/dist/mention/index.d.ts +17 -0
- package/dist/mention/index.js +151 -0
- package/dist/mention/jsonl.d.ts +9 -0
- package/dist/mention/jsonl.js +54 -0
- package/dist/mention/mention.d.ts +19 -0
- package/dist/mention/mention.js +60 -0
- package/dist/mention/pi.d.ts +11 -0
- package/dist/mention/pi.js +172 -0
- package/dist/mention/session-index.d.ts +66 -0
- package/dist/mention/session-index.js +303 -0
- package/dist/mention/session.d.ts +18 -0
- package/dist/mention/session.js +8 -0
- package/dist/mention/text.d.ts +12 -0
- package/dist/mention/text.js +47 -0
- package/dist/mention/transcript.d.ts +10 -0
- package/dist/mention/transcript.js +129 -0
- package/dist/panel/defined-section.js +34 -8
- package/dist/panel/definition.d.ts +26 -1
- package/dist/panel/definition.js +32 -2
- package/dist/panel/index.d.ts +3 -2
- package/dist/panel/index.js +1 -0
- package/dist/panel/panel.js +109 -29
- package/dist/panel/section.d.ts +49 -3
- package/dist/panel/section.js +59 -12
- package/dist/resources/scoped-extension.js +1 -0
- package/dist/settings/file-store.js +1 -0
- package/docs/dock.md +9 -3
- package/docs/panel.md +69 -2
- package/docs/public-api-design.md +9 -9
- package/docs/recipes.md +3 -8
- package/docs/settings.md +1 -1
- package/package.json +4 -4
- package/src/core/panel.ts +29 -1
- package/src/core/settings.ts +42 -2
- package/src/dock/registry.ts +1 -0
- package/src/extension.ts +11 -2
- package/src/mention/autocomplete.ts +177 -0
- package/src/mention/budget.ts +11 -0
- package/src/mention/catalog.ts +133 -0
- package/src/mention/claude.ts +127 -0
- package/src/mention/codex.ts +144 -0
- package/src/mention/external.ts +190 -0
- package/src/mention/index.ts +193 -0
- package/src/mention/jsonl.ts +56 -0
- package/src/mention/mention.ts +90 -0
- package/src/mention/pi.ts +192 -0
- package/src/mention/session-index.ts +356 -0
- package/src/mention/session.ts +27 -0
- package/src/mention/text.ts +52 -0
- package/src/mention/transcript.ts +155 -0
- package/src/panel/defined-section.ts +40 -7
- package/src/panel/definition.ts +67 -2
- package/src/panel/index.ts +4 -0
- package/src/panel/panel.ts +115 -29
- package/src/panel/section.ts +111 -15
- package/src/resources/scoped-extension.ts +1 -0
- package/src/settings/file-store.ts +1 -0
package/src/panel/panel.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
settingsEditor,
|
|
33
33
|
valueAtScope,
|
|
34
34
|
type SettingsEditorComponent,
|
|
35
|
+
type SettingsMenu,
|
|
35
36
|
type SettingsPanelField,
|
|
36
37
|
type SettingsSection,
|
|
37
38
|
} from "./section.ts";
|
|
@@ -66,7 +67,9 @@ function message(error: unknown): string {
|
|
|
66
67
|
/**
|
|
67
68
|
* Frame-level state machine: navigation -> text/number/JSON/secret input, choice editor
|
|
68
69
|
* or custom editor -> navigation. The edited field is captured on entry because
|
|
69
|
-
* conditional visibility may rebuild the list while an editor is open.
|
|
70
|
+
* conditional visibility may rebuild the list while an editor is open. Navigation can
|
|
71
|
+
* descend into secondary menus; the open path is kept as field IDs and resolved again
|
|
72
|
+
* on every refresh, so a menu whose row disappears closes instead of showing stale fields.
|
|
70
73
|
* busy serializes accepted persistence operations; disposed prevents their completion
|
|
71
74
|
* from refreshing a retired interaction. Dynamic membership follows stable ctx.ui,
|
|
72
75
|
* not Settings IDs across runners. Child editors must not draw a second shared frame.
|
|
@@ -80,6 +83,10 @@ class SettingsPanel implements Component, Focusable {
|
|
|
80
83
|
private choiceEditor?: SettingsChoiceEditor;
|
|
81
84
|
private customEditor: SettingsEditorComponent | undefined;
|
|
82
85
|
private editing: SettingsPanelField | undefined;
|
|
86
|
+
// IDs of the open menu rows, outermost first, and the pages they resolved to.
|
|
87
|
+
private menuPath: string[] = [];
|
|
88
|
+
private menus: { field: SettingsPanelField; menu: SettingsMenu }[] = [];
|
|
89
|
+
private menuError = "";
|
|
83
90
|
// List rows that are group headings; navigation steps over them.
|
|
84
91
|
private headings = new Set<string>();
|
|
85
92
|
private visibleFields = 0;
|
|
@@ -140,9 +147,12 @@ class SettingsPanel implements Component, Focusable {
|
|
|
140
147
|
return this.sections[this.activeSection];
|
|
141
148
|
}
|
|
142
149
|
// An unavailable section has no trustworthy fields to list or edit.
|
|
143
|
-
private get
|
|
150
|
+
private get sectionFields(): readonly SettingsPanelField[] {
|
|
144
151
|
return this.section?.unavailable === undefined ? (this.section?.fields ?? []) : [];
|
|
145
152
|
}
|
|
153
|
+
private get fields(): readonly SettingsPanelField[] {
|
|
154
|
+
return this.menus.at(-1)?.menu.fields ?? this.sectionFields;
|
|
155
|
+
}
|
|
146
156
|
private get field(): SettingsPanelField | undefined {
|
|
147
157
|
const id = this.list?.getSelectedItem()?.value;
|
|
148
158
|
return this.fields.find((field) => field.id === id);
|
|
@@ -209,6 +219,7 @@ class SettingsPanel implements Component, Focusable {
|
|
|
209
219
|
);
|
|
210
220
|
if (previous && previous !== this.section) {
|
|
211
221
|
this.list = undefined;
|
|
222
|
+
this.menuPath = [];
|
|
212
223
|
this.input = undefined;
|
|
213
224
|
this.editing = undefined;
|
|
214
225
|
this.choiceEditor?.dispose();
|
|
@@ -218,10 +229,47 @@ class SettingsPanel implements Component, Focusable {
|
|
|
218
229
|
this.refresh();
|
|
219
230
|
}
|
|
220
231
|
|
|
232
|
+
// A menu is built again from its row, so the page follows values and files changed meanwhile.
|
|
233
|
+
private resolveMenus(): void {
|
|
234
|
+
this.menus = [];
|
|
235
|
+
this.menuError = "";
|
|
236
|
+
let fields = this.sectionFields;
|
|
237
|
+
for (const id of this.menuPath) {
|
|
238
|
+
const field = fields.find((candidate) => candidate.id === id && candidate.menu);
|
|
239
|
+
if (!field) break;
|
|
240
|
+
let menu: SettingsMenu;
|
|
241
|
+
try {
|
|
242
|
+
menu = field.menu!(this.ctx, this.scope);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
this.menuError = `Could not open ${field.label}: ${message(error)}`;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
this.menus.push({ field, menu });
|
|
248
|
+
fields = menu.fields;
|
|
249
|
+
}
|
|
250
|
+
this.menuPath = this.menus.map(({ field }) => field.id);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private openMenu(field: SettingsPanelField): void {
|
|
254
|
+
this.menuPath = [...this.menuPath, field.id];
|
|
255
|
+
this.list = undefined;
|
|
256
|
+
this.refresh();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Back to the parent list with the menu's own row selected.
|
|
260
|
+
private closeMenu(): void {
|
|
261
|
+
const id = this.menuPath.at(-1);
|
|
262
|
+
this.menuPath = this.menuPath.slice(0, -1);
|
|
263
|
+
this.list = undefined;
|
|
264
|
+
this.error = "";
|
|
265
|
+
this.refresh(id);
|
|
266
|
+
}
|
|
267
|
+
|
|
221
268
|
// The list is rebuilt because values, visibility and registered sections change while it is open.
|
|
222
|
-
private refresh(): void {
|
|
269
|
+
private refresh(select?: string): void {
|
|
223
270
|
if (this.disposed) return;
|
|
224
|
-
const selected = this.list?.getSelectedItem()?.value;
|
|
271
|
+
const selected = select ?? this.list?.getSelectedItem()?.value;
|
|
272
|
+
this.resolveMenus();
|
|
225
273
|
this.visibilityErrors = [];
|
|
226
274
|
const fields = this.fields.filter((field) => {
|
|
227
275
|
try {
|
|
@@ -252,19 +300,11 @@ class SettingsPanel implements Component, Focusable {
|
|
|
252
300
|
});
|
|
253
301
|
}
|
|
254
302
|
group = field.group;
|
|
255
|
-
const
|
|
256
|
-
// The mask length is fixed so it cannot leak the secret's length.
|
|
257
|
-
const label = field.secret
|
|
258
|
-
? typeof value === "string" && value
|
|
259
|
-
? SECRET_MASK
|
|
260
|
-
: "(not set)"
|
|
261
|
-
: (field.choices?.find((choice) => isDeepStrictEqual(choice.value, value))?.label ??
|
|
262
|
-
field.formatValue?.(value, this.ctx, this.scope) ??
|
|
263
|
-
formatValue(value));
|
|
303
|
+
const label = this.rowValue(field);
|
|
264
304
|
const globalOnly = !this.projectDisabled && !field.scopes.includes(this.scope);
|
|
265
305
|
items.push({
|
|
266
306
|
value: field.id,
|
|
267
|
-
label: field.label,
|
|
307
|
+
label: field.menu ? `${field.label} →` : field.label,
|
|
268
308
|
description: [label, globalOnly && "global only", this.disabledReason(field)]
|
|
269
309
|
.filter(Boolean)
|
|
270
310
|
.join(" · "),
|
|
@@ -291,11 +331,31 @@ class SettingsPanel implements Component, Focusable {
|
|
|
291
331
|
this.updatePreview();
|
|
292
332
|
};
|
|
293
333
|
this.list.onSelect = () => this.edit();
|
|
294
|
-
this.list.onCancel = () => this.
|
|
334
|
+
this.list.onCancel = () => this.back();
|
|
295
335
|
this.updatePreview();
|
|
296
336
|
this.tui.requestRender();
|
|
297
337
|
}
|
|
298
338
|
|
|
339
|
+
// A menu row has no value; its summary stands in, and a failing summary is shown, not thrown.
|
|
340
|
+
private rowValue(field: SettingsPanelField): string {
|
|
341
|
+
if (field.menu) {
|
|
342
|
+
try {
|
|
343
|
+
return field.formatValue?.(undefined, this.ctx, this.scope) ?? "";
|
|
344
|
+
} catch (error) {
|
|
345
|
+
return this.theme.fg("error", message(error));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const value = valueAtScope(field.inspect(), this.scope);
|
|
349
|
+
// The mask length is fixed so it cannot leak the secret's length.
|
|
350
|
+
return field.secret
|
|
351
|
+
? typeof value === "string" && value
|
|
352
|
+
? SECRET_MASK
|
|
353
|
+
: "(not set)"
|
|
354
|
+
: (field.choices?.find((choice) => isDeepStrictEqual(choice.value, value))?.label ??
|
|
355
|
+
field.formatValue?.(value, this.ctx, this.scope) ??
|
|
356
|
+
formatValue(value));
|
|
357
|
+
}
|
|
358
|
+
|
|
299
359
|
// A failing preview must not close the panel; the error line replaces it.
|
|
300
360
|
private updatePreview(): void {
|
|
301
361
|
this.preview?.dispose?.();
|
|
@@ -358,6 +418,10 @@ class SettingsPanel implements Component, Focusable {
|
|
|
358
418
|
this.openCustomEditor(field);
|
|
359
419
|
return;
|
|
360
420
|
}
|
|
421
|
+
if (editor === "menu") {
|
|
422
|
+
this.openMenu(field);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
361
425
|
if (editor === "cycle" && field.choices?.length) {
|
|
362
426
|
const current = valueAtScope(field.inspect(), this.scope);
|
|
363
427
|
const index = field.choices.findIndex(({ value }) => isDeepStrictEqual(value, current));
|
|
@@ -504,6 +568,7 @@ class SettingsPanel implements Component, Focusable {
|
|
|
504
568
|
isSettingsNotificationError(error)
|
|
505
569
|
? `Reloaded; ${message}`
|
|
506
570
|
: `Retry failed: ${message}`,
|
|
571
|
+
{ cause: error },
|
|
507
572
|
);
|
|
508
573
|
}
|
|
509
574
|
});
|
|
@@ -544,6 +609,7 @@ class SettingsPanel implements Component, Focusable {
|
|
|
544
609
|
* Route input to exactly one mode; persistence suppresses further actions.
|
|
545
610
|
* Ctrl+G changes persistence scope only in navigation. Inside a selector, Tab
|
|
546
611
|
* changes its candidate range and Ctrl+R refreshes discovery rather than reset.
|
|
612
|
+
* Left/Right switch sections only in navigation; open inputs and editors keep them.
|
|
547
613
|
*/
|
|
548
614
|
handleInput(data: string): void {
|
|
549
615
|
// Key-release events would otherwise repeat the action on terminals that report them.
|
|
@@ -576,12 +642,15 @@ class SettingsPanel implements Component, Focusable {
|
|
|
576
642
|
this.error = "";
|
|
577
643
|
this.updatePreview();
|
|
578
644
|
}
|
|
579
|
-
} else if (
|
|
645
|
+
} else if (
|
|
646
|
+
(["tab", "shift+tab", "left", "right"] as const).some((key) => matchesKey(data, key))
|
|
647
|
+
) {
|
|
580
648
|
if (this.sections.length) {
|
|
581
|
-
const delta = matchesKey(data, "shift+tab") ? -1 : 1;
|
|
649
|
+
const delta = matchesKey(data, "shift+tab") || matchesKey(data, "left") ? -1 : 1;
|
|
582
650
|
this.activeSection =
|
|
583
651
|
(this.activeSection + delta + this.sections.length) % this.sections.length;
|
|
584
652
|
this.list = undefined;
|
|
653
|
+
this.menuPath = [];
|
|
585
654
|
this.error = "";
|
|
586
655
|
this.refresh();
|
|
587
656
|
}
|
|
@@ -595,9 +664,10 @@ class SettingsPanel implements Component, Focusable {
|
|
|
595
664
|
const field = this.field;
|
|
596
665
|
const blocked = field && this.scopeError(field);
|
|
597
666
|
if (blocked) this.error = blocked;
|
|
667
|
+
else if (field?.menu) this.error = `Open ${field.label} to reset the settings in it`;
|
|
598
668
|
else if (field) void this.apply(() => this.commit(() => field.reset(this.scope)));
|
|
599
669
|
} else if (matchesKey(data, "escape")) {
|
|
600
|
-
this.
|
|
670
|
+
this.back();
|
|
601
671
|
} else if (data === " ") {
|
|
602
672
|
this.edit();
|
|
603
673
|
} else {
|
|
@@ -613,6 +683,11 @@ class SettingsPanel implements Component, Focusable {
|
|
|
613
683
|
this.tui.requestRender();
|
|
614
684
|
}
|
|
615
685
|
|
|
686
|
+
private back(): void {
|
|
687
|
+
if (this.menuPath.length) this.closeMenu();
|
|
688
|
+
else this.close();
|
|
689
|
+
}
|
|
690
|
+
|
|
616
691
|
private isHeading(value: string | undefined): boolean {
|
|
617
692
|
return value !== undefined && this.headings.has(value);
|
|
618
693
|
}
|
|
@@ -637,15 +712,19 @@ class SettingsPanel implements Component, Focusable {
|
|
|
637
712
|
)
|
|
638
713
|
.join(this.theme.fg("dim", " / "));
|
|
639
714
|
const field = this.editing ?? this.field;
|
|
640
|
-
const inspection = field
|
|
715
|
+
const inspection = field && !field.menu ? field.inspect() : undefined;
|
|
641
716
|
// Side-by-side preview needs room; below this width it is stacked under the list.
|
|
642
717
|
const split = width >= 88 && !this.input && !!field?.preview;
|
|
643
718
|
const bodyWidth = split ? Math.floor((width - 3) / 2) : width;
|
|
644
|
-
let body =
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
719
|
+
let body = [
|
|
720
|
+
...(this.input
|
|
721
|
+
? this.input.render(bodyWidth)
|
|
722
|
+
: this.customEditor
|
|
723
|
+
? this.renderCustomEditor(bodyWidth)
|
|
724
|
+
: (this.choiceEditor?.renderBody(bodyWidth) ??
|
|
725
|
+
this.list?.render(bodyWidth) ??
|
|
726
|
+
[])),
|
|
727
|
+
];
|
|
649
728
|
if (!this.sections.length)
|
|
650
729
|
body = [this.theme.fg("muted", "No extensions have registered settings.")];
|
|
651
730
|
else if (this.section?.unavailable !== undefined)
|
|
@@ -655,6 +734,13 @@ class SettingsPanel implements Component, Focusable {
|
|
|
655
734
|
"",
|
|
656
735
|
this.theme.fg("muted", "Fix the problem, then press Ctrl+S to retry."),
|
|
657
736
|
];
|
|
737
|
+
else if (this.menus.length && !this.fields.length)
|
|
738
|
+
body = [
|
|
739
|
+
this.theme.fg(
|
|
740
|
+
"muted",
|
|
741
|
+
this.menus.at(-1)!.menu.emptyMessage ?? "This menu is empty.",
|
|
742
|
+
),
|
|
743
|
+
];
|
|
658
744
|
else if (!this.section?.fields.length)
|
|
659
745
|
body = [this.theme.fg("muted", "No settings are available in this section yet.")];
|
|
660
746
|
else if (!this.visibleFields)
|
|
@@ -708,14 +794,14 @@ class SettingsPanel implements Component, Focusable {
|
|
|
708
794
|
});
|
|
709
795
|
} else body.push("", rule, ...preview);
|
|
710
796
|
}
|
|
711
|
-
const errors = [this.error, ...this.visibilityErrors].filter(Boolean);
|
|
797
|
+
const errors = [this.error, this.menuError, ...this.visibilityErrors].filter(Boolean);
|
|
712
798
|
if (errors.length) body.push("", ...errors.map((text) => this.theme.fg("error", text)));
|
|
713
799
|
return [
|
|
714
800
|
rule,
|
|
715
801
|
this.theme.fg(
|
|
716
802
|
"accent",
|
|
717
803
|
this.choiceEditor?.title ??
|
|
718
|
-
`${this.editing ? this.editing.label : "Lune settings"} · ${this.scope}${this.busy ? " · Saving / loading…" : ""}`,
|
|
804
|
+
`${this.editing ? this.editing.label : ["Lune settings", ...this.menus.map(({ field }) => field.label)].join(" › ")} · ${this.scope}${this.busy ? " · Saving / loading…" : ""}`,
|
|
719
805
|
),
|
|
720
806
|
tabs,
|
|
721
807
|
rule,
|
|
@@ -731,15 +817,15 @@ class SettingsPanel implements Component, Focusable {
|
|
|
731
817
|
: this.input
|
|
732
818
|
? "Enter save · Ctrl+S save/reload · Esc back"
|
|
733
819
|
: this.section?.unavailable !== undefined
|
|
734
|
-
? "Tab section · Ctrl+S retry · Esc close"
|
|
735
|
-
:
|
|
820
|
+
? "Tab/←→ section · Ctrl+S retry · Esc close"
|
|
821
|
+
: `↑↓ select · Enter change · Tab/←→ section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · ${this.menus.length ? "Esc back" : "Esc close"}`),
|
|
736
822
|
),
|
|
737
823
|
rule,
|
|
738
824
|
].map((line) => truncateToWidth(line, width));
|
|
739
825
|
}
|
|
740
826
|
|
|
741
827
|
// A throwing editor render must not take down the shared frame; Esc still closes it.
|
|
742
|
-
private renderCustomEditor(width: number): string[] {
|
|
828
|
+
private renderCustomEditor(width: number): readonly string[] {
|
|
743
829
|
try {
|
|
744
830
|
return this.customEditor!.render(width);
|
|
745
831
|
} catch (error) {
|
package/src/panel/section.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* candidates only in clones. Validation/editor resolution stays usable without TUI.
|
|
8
8
|
*/
|
|
9
9
|
import { Value } from "typebox/value";
|
|
10
|
-
import type
|
|
10
|
+
import { Type, type Static, type TObject, type TSchema } from "typebox";
|
|
11
11
|
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
import type { Component } from "@earendil-works/pi-tui";
|
|
13
13
|
import type {
|
|
@@ -121,13 +121,26 @@ export type SettingsCustomEditor<T, TValues> = (
|
|
|
121
121
|
context: SettingsCustomEditorContext<T, TValues>,
|
|
122
122
|
) => SettingsEditorComponent;
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* A secondary menu: a page of fields that one row opens inside the panel frame.
|
|
126
|
+
* Renderers build it again on every refresh, so its fields can follow changes made
|
|
127
|
+
* outside Settings, such as files the menu edits. Its fields may open further menus.
|
|
128
|
+
*/
|
|
129
|
+
export interface SettingsMenu {
|
|
130
|
+
/** Unique IDs within the menu; a renderer keeps an open menu by the IDs on its path. */
|
|
131
|
+
readonly fields: readonly SettingsPanelField[];
|
|
132
|
+
/** Shown instead of the list when fields is empty. */
|
|
133
|
+
readonly emptyMessage?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
124
136
|
/**
|
|
125
137
|
* cycle commits static choices immediately; select confirms a candidate list.
|
|
126
138
|
* text accepts raw strings only; number accepts one finite number for number/integer
|
|
127
139
|
* schemas; json parses then validates complete JSON values; custom hands editing to
|
|
128
|
-
* the field's customEditor
|
|
140
|
+
* the field's customEditor; menu opens the field's secondary menu. Preview
|
|
141
|
+
* availability does not determine the editor.
|
|
129
142
|
*/
|
|
130
|
-
export type SettingsEditor = "cycle" | "select" | "text" | "number" | "json" | "custom";
|
|
143
|
+
export type SettingsEditor = "cycle" | "select" | "text" | "number" | "json" | "custom" | "menu";
|
|
131
144
|
|
|
132
145
|
/**
|
|
133
146
|
* Field presentation/editing metadata, not storage policy.
|
|
@@ -143,6 +156,11 @@ export type SettingsFieldOptions<T, TValues> = {
|
|
|
143
156
|
* ungrouped fields come before every group.
|
|
144
157
|
*/
|
|
145
158
|
group?: string;
|
|
159
|
+
/**
|
|
160
|
+
* ID of a menu of the same panel that lists the field on its page instead of in the
|
|
161
|
+
* section. That menu declares no open function; see SettingsMenuDefinition.
|
|
162
|
+
*/
|
|
163
|
+
inMenu?: string;
|
|
146
164
|
/**
|
|
147
165
|
* Hide the field while this returns false, e.g. options of a disabled feature.
|
|
148
166
|
* Hidden fields keep their stored values. Runs on every refresh: keep it cheap and pure.
|
|
@@ -218,6 +236,12 @@ export interface SettingsPanelField {
|
|
|
218
236
|
customEditor?(
|
|
219
237
|
context: Omit<SettingsCustomEditorContext<unknown, unknown>, "values">,
|
|
220
238
|
): SettingsEditorComponent;
|
|
239
|
+
/**
|
|
240
|
+
* Present exactly when editor is "menu". A menu row holds no value: renderers show
|
|
241
|
+
* formatValue(undefined) as its summary and never inspect, set or reset it.
|
|
242
|
+
* createSettingsMenuField builds such a field.
|
|
243
|
+
*/
|
|
244
|
+
menu?(context: ExtensionContext, scope: SettingsScope): SettingsMenu;
|
|
221
245
|
/** Current precedence explanation; renderers use explicit scope overrides for editing. */
|
|
222
246
|
inspect(): SettingInspection<unknown>;
|
|
223
247
|
/** Validate/commit a candidate at this explicit persistence scope, not a candidate range. */
|
|
@@ -286,21 +310,24 @@ function schemaChoices(schema: SettingsPanelSchema): SettingsChoice[] | undefine
|
|
|
286
310
|
export function settingsEditor(
|
|
287
311
|
field: Pick<SettingsPanelField, "editor" | "choiceSource" | "choices" | "schema"> & {
|
|
288
312
|
customEditor?: unknown;
|
|
313
|
+
menu?: unknown;
|
|
289
314
|
},
|
|
290
315
|
): SettingsEditor {
|
|
291
316
|
return (
|
|
292
317
|
field.editor ??
|
|
293
|
-
(field.
|
|
294
|
-
? "
|
|
295
|
-
: field.
|
|
296
|
-
? "
|
|
297
|
-
: field.
|
|
298
|
-
? "
|
|
299
|
-
: field.
|
|
300
|
-
? "
|
|
301
|
-
: field.schema.type === "
|
|
302
|
-
? "
|
|
303
|
-
: "
|
|
318
|
+
(field.menu
|
|
319
|
+
? "menu"
|
|
320
|
+
: field.customEditor
|
|
321
|
+
? "custom"
|
|
322
|
+
: field.choiceSource
|
|
323
|
+
? "select"
|
|
324
|
+
: field.choices?.length
|
|
325
|
+
? "cycle"
|
|
326
|
+
: field.schema.type === "string"
|
|
327
|
+
? "text"
|
|
328
|
+
: field.schema.type === "number" || field.schema.type === "integer"
|
|
329
|
+
? "number"
|
|
330
|
+
: "json")
|
|
304
331
|
);
|
|
305
332
|
}
|
|
306
333
|
|
|
@@ -321,6 +348,7 @@ export function resolveSettingsFieldOptions(
|
|
|
321
348
|
visible?: unknown;
|
|
322
349
|
disabled?: unknown;
|
|
323
350
|
customEditor?: unknown;
|
|
351
|
+
menu?: unknown;
|
|
324
352
|
},
|
|
325
353
|
) {
|
|
326
354
|
if (metadata?.presentation && !metadata.preview) {
|
|
@@ -331,9 +359,24 @@ export function resolveSettingsFieldOptions(
|
|
|
331
359
|
(typeof metadata.group !== "string" || !metadata.group.trim())
|
|
332
360
|
)
|
|
333
361
|
throw new TypeError(`Settings group for "${id}" must be a non-empty string`);
|
|
334
|
-
for (const name of ["visible", "disabled", "customEditor"] as const)
|
|
362
|
+
for (const name of ["visible", "disabled", "customEditor", "menu"] as const)
|
|
335
363
|
if (metadata?.[name] !== undefined && typeof metadata[name] !== "function")
|
|
336
364
|
throw new TypeError(`Settings ${name} for "${id}" must be a function`);
|
|
365
|
+
if (metadata?.menu) {
|
|
366
|
+
if ((metadata.editor ?? "menu") !== "menu")
|
|
367
|
+
throw new TypeError(`Menu "${id}" conflicts with editor "${metadata.editor}"`);
|
|
368
|
+
if (
|
|
369
|
+
metadata.customEditor ||
|
|
370
|
+
metadata.choices ||
|
|
371
|
+
metadata.choiceSource ||
|
|
372
|
+
metadata.secret ||
|
|
373
|
+
metadata.preview
|
|
374
|
+
)
|
|
375
|
+
throw new TypeError(
|
|
376
|
+
`Menu "${id}" cannot use a custom editor, choices, secret or a preview; it opens its own fields`,
|
|
377
|
+
);
|
|
378
|
+
} else if (metadata?.editor === "menu")
|
|
379
|
+
throw new TypeError(`Editor "menu" requires a menu for "${id}"`);
|
|
337
380
|
if (metadata?.customEditor) {
|
|
338
381
|
if ((metadata.editor ?? "custom") !== "custom")
|
|
339
382
|
throw new TypeError(
|
|
@@ -359,6 +402,7 @@ export function resolveSettingsFieldOptions(
|
|
|
359
402
|
const editor = settingsEditor({
|
|
360
403
|
editor: metadata?.editor,
|
|
361
404
|
customEditor: metadata?.customEditor,
|
|
405
|
+
menu: metadata?.menu,
|
|
362
406
|
choiceSource: metadata?.choiceSource,
|
|
363
407
|
choices,
|
|
364
408
|
schema,
|
|
@@ -411,6 +455,58 @@ export function assertSettingsGroups(fields: readonly { group?: string }[]): voi
|
|
|
411
455
|
}
|
|
412
456
|
}
|
|
413
457
|
|
|
458
|
+
/** A row that opens a secondary menu; see createSettingsMenuField. */
|
|
459
|
+
export interface SettingsMenuFieldOptions {
|
|
460
|
+
/** Unique among the fields of the section or menu that lists the row. */
|
|
461
|
+
id: string;
|
|
462
|
+
label: string;
|
|
463
|
+
description?: string;
|
|
464
|
+
group?: string;
|
|
465
|
+
/** Scopes at which the menu can open; its own fields keep their own scopes. */
|
|
466
|
+
scopes: readonly SettingsScope[];
|
|
467
|
+
/** Text beside the label, such as a count of the menu's entries. */
|
|
468
|
+
summary?(context: ExtensionContext, scope: SettingsScope): string;
|
|
469
|
+
visible?(context: ExtensionContext, scope: SettingsScope): boolean;
|
|
470
|
+
disabled?(context: ExtensionContext, scope: SettingsScope): string | undefined;
|
|
471
|
+
/** Build the page; renderers call it again on every refresh while it is open. */
|
|
472
|
+
menu(context: ExtensionContext, scope: SettingsScope): SettingsMenu;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Build a field whose row opens a secondary menu. The row has no value of its own, so
|
|
477
|
+
* set and reset reject: the menu's fields hold the values.
|
|
478
|
+
*/
|
|
479
|
+
export function createSettingsMenuField(options: SettingsMenuFieldOptions): SettingsPanelField {
|
|
480
|
+
const schema = Type.Null() as SettingsPanelSchema;
|
|
481
|
+
resolveSettingsFieldOptions(options.id, schema, options);
|
|
482
|
+
const refuse = () =>
|
|
483
|
+
Promise.reject(
|
|
484
|
+
new TypeError(`${options.label} is a menu; change the settings inside it instead`),
|
|
485
|
+
);
|
|
486
|
+
return {
|
|
487
|
+
id: options.id,
|
|
488
|
+
label: options.label,
|
|
489
|
+
description: options.description,
|
|
490
|
+
schema,
|
|
491
|
+
editor: "menu",
|
|
492
|
+
group: options.group,
|
|
493
|
+
scopes: options.scopes,
|
|
494
|
+
visible: options.visible,
|
|
495
|
+
disabled: options.disabled,
|
|
496
|
+
menu: options.menu,
|
|
497
|
+
formatValue: (_value, context, scope) => options.summary?.(context, scope) ?? "",
|
|
498
|
+
inspect: () => ({
|
|
499
|
+
defaultValue: null,
|
|
500
|
+
globalValue: undefined,
|
|
501
|
+
projectValue: undefined,
|
|
502
|
+
value: null,
|
|
503
|
+
source: "default",
|
|
504
|
+
}),
|
|
505
|
+
set: refuse,
|
|
506
|
+
reset: refuse,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
414
510
|
/**
|
|
415
511
|
* Adapt top-level Settings keys to a custom section; no acquisition/hooks are installed.
|
|
416
512
|
*
|
|
@@ -35,6 +35,7 @@ export function scopedExtension(
|
|
|
35
35
|
try {
|
|
36
36
|
await resources.dispose();
|
|
37
37
|
} catch (cleanupError) {
|
|
38
|
+
// eslint-disable-next-line preserve-caught-error -- AggregateError.errors retains both failures.
|
|
38
39
|
throw new AggregateError(
|
|
39
40
|
[error, cleanupError],
|
|
40
41
|
"Extension setup and cleanup failed",
|
|
@@ -117,6 +117,7 @@ async function writeStored(file: string, stored: StoredSettings): Promise<void>
|
|
|
117
117
|
try {
|
|
118
118
|
await fs.rm(tmpPath, { force: true });
|
|
119
119
|
} catch (cleanupError) {
|
|
120
|
+
// eslint-disable-next-line preserve-caught-error -- AggregateError.errors retains both failures.
|
|
120
121
|
throw new AggregateError(
|
|
121
122
|
[error, cleanupError],
|
|
122
123
|
"Settings write and temporary file cleanup failed",
|