refactor: optimize core engine and retrieval logic for v2.80.43

This commit is contained in:
2026-05-13 19:23:57 +09:00
parent c4260466b9
commit 089abf22db
17 changed files with 1311 additions and 88 deletions
+34 -2
View File
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { ApprovalQueue, Approval } from './approvalQueue';
import { wrapPanelAsView } from '../../sidebarProvider';
/**
* A small webview view that surfaces the currently pending approval, separate
@@ -14,6 +15,7 @@ export class ApprovalPanelProvider implements vscode.WebviewViewProvider {
public static readonly viewType = 'g1nation-approval-panel';
private _view?: vscode.WebviewView;
private _panel?: vscode.WebviewPanel;
private _subscription?: vscode.Disposable;
constructor(
@@ -22,6 +24,32 @@ export class ApprovalPanelProvider implements vscode.WebviewViewProvider {
) {}
public resolveWebviewView(view: vscode.WebviewView): void {
this._initView(view);
}
/** Open the approvals UI as an editor panel (Column 3 by default). */
public openAsPanel(column: vscode.ViewColumn = vscode.ViewColumn.Three): vscode.WebviewPanel {
if (this._panel) {
this._panel.reveal(column);
return this._panel;
}
const panel = vscode.window.createWebviewPanel(
ApprovalPanelProvider.viewType,
'Pending Approvals',
column,
{ enableScripts: true, localResourceRoots: [this._extensionUri], retainContextWhenHidden: true }
);
this._panel = panel;
const adapter = wrapPanelAsView(panel);
panel.onDidDispose(() => {
if (this._panel === panel) this._panel = undefined;
if (this._view === adapter) this._view = undefined;
});
this._initView(adapter);
return panel;
}
private _initView(view: vscode.WebviewView): void {
this._view = view;
view.webview.options = { enableScripts: true, localResourceRoots: [this._extensionUri] };
view.webview.html = this._render(this._queue.current());
@@ -40,13 +68,17 @@ export class ApprovalPanelProvider implements vscode.WebviewViewProvider {
view.onDidDispose(() => {
this._subscription?.dispose();
this._subscription = undefined;
this._view = undefined;
if (this._view === view) this._view = undefined;
});
}
/** Bring the panel into focus; used by the status bar badge. */
public focus(): void {
void vscode.commands.executeCommand(`${ApprovalPanelProvider.viewType}.focus`);
if (this._panel) {
this._panel.reveal(this._panel.viewColumn ?? vscode.ViewColumn.Three);
return;
}
this.openAsPanel();
}
private _render(approval: Approval | null): string {
+10 -36
View File
@@ -123,45 +123,23 @@ export class SettingsPanelProvider implements vscode.WebviewViewProvider {
}
public async focus(): Promise<void> {
// Reveal the Astra activity-bar container so a focus() doesn't silently
// no-op against a collapsed sidebar.
try {
await vscode.commands.executeCommand('workbench.view.extension.g1nation-sidebar');
} catch {
// Older VS Code versions may not expose this command.
}
try {
await vscode.commands.executeCommand(`${SettingsPanelProvider.viewType}.focus`);
} catch (e: any) {
// The view-focus command is auto-generated only when VS Code parsed
// the package.json `views` entry. If a stale .vsix is installed
// (or the user hasn't reloaded after a fresh install) the command
// is missing and we hit `command not found`. Fall back to a
// floating panel so the user still gets the same UI.
if (this._isCommandNotFound(e)) {
logInfo('Settings view command missing — opening as floating panel.');
await this.openAsPanel();
return;
}
throw e;
}
await this.openAsPanel();
}
/**
* Open the same settings UI as a stand-alone editor panel. Used when the
* sidebar `WebviewView` isn't registered yet (e.g. user installed a fresh
* .vsix without reloading) — keeps the feature reachable without forcing
* the user back through `vsce package` cycles.
* Open the settings UI as a stand-alone editor panel (Column 3 by default).
* Astra's sidebar view container was removed in 2.81 — all three webviews
* (Chat, Approvals, Settings) now live in the editor area.
*/
public async openAsPanel(): Promise<void> {
public async openAsPanel(column: vscode.ViewColumn = vscode.ViewColumn.Three): Promise<vscode.WebviewPanel> {
if (this._panel) {
this._panel.reveal(vscode.ViewColumn.Active);
return;
this._panel.reveal(column);
return this._panel;
}
const panel = vscode.window.createWebviewPanel(
'g1nation-settings-panel-floating',
SettingsPanelProvider.viewType,
'Astra Settings',
vscode.ViewColumn.Active,
column,
{ enableScripts: true, localResourceRoots: [this._deps.extensionUri], retainContextWhenHidden: true }
);
this._panel = panel;
@@ -169,11 +147,7 @@ export class SettingsPanelProvider implements vscode.WebviewViewProvider {
panel.onDidDispose(() => { this._panel = undefined; });
await this._refreshState();
void this._fetchModelsAndRefresh();
}
private _isCommandNotFound(e: unknown): boolean {
const msg = (e as any)?.message ?? String(e ?? '');
return /command\s+'.+'\s+not found/i.test(msg);
return panel;
}
/** Re-pull state from sources of truth and broadcast to the webview. */