Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/test/vscode-settings-entry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as assert from "node:assert";
import { readFileSync } from "node:fs";
import { extensionSettingsQuery } from "../vscode-settings.js";

suite("VS Code settings entry", () => {
test("builds an @ext filter from publisher and name", () => {
assert.strictEqual(extensionSettingsQuery("auchan", "pion-code"), "@ext:auchan.pion-code");
});

test("falls back to the known extension identity", () => {
assert.strictEqual(extensionSettingsQuery(undefined, undefined), "@ext:auchan.pion-code");
assert.strictEqual(extensionSettingsQuery(" ", " "), "@ext:auchan.pion-code");
});

test("gear opens native settings and the panel executes the filtered command", () => {
const handlers = readFileSync(
new URL("../../src/webview/handlers/index.ts", import.meta.url),
"utf8",
);
assert.match(handlers, /pi-sb-settings/);
assert.match(handlers, /postMessage\(\{ type: "openVscodeSettings" \}\)/);

const panel = readFileSync(
new URL("../../src/webview-panel.ts", import.meta.url),
"utf8",
);
assert.match(panel, /case "openVscodeSettings"/);
assert.match(panel, /extensionSettingsQuery\(pkg\.publisher, pkg\.name\)/);
assert.match(panel, /"workbench\.action\.openSettings"/);
assert.match(panel, /Open Pi on Code settings in VS Code/);
});
});
13 changes: 13 additions & 0 deletions src/vscode-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Query string for the VS Code Settings editor that filters to this
* extension, e.g. `@ext:auchan.pion-code`.
*/
export function extensionSettingsQuery(publisher?: unknown, name?: unknown): string {
const resolvedPublisher = typeof publisher === "string" && publisher.trim()
? publisher.trim()
: "auchan";
const resolvedName = typeof name === "string" && name.trim()
? name.trim()
: "pion-code";
return `@ext:${resolvedPublisher}.${resolvedName}`;
}
16 changes: 15 additions & 1 deletion src/webview-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
resolveMarkdownImagePath,
} from "./local-markdown-image.js";
import { mergeInitialHistoryEvents } from "./history-event-sync.js";
import { extensionSettingsQuery } from "./vscode-settings.js";
import { SessionCapabilitySnapshot } from "./capability-snapshot.js";
import { piError } from "./logger.js";
import { getWorkspaceCwd } from "./workspace-context.js";
Expand Down Expand Up @@ -682,6 +683,19 @@ export class PiWebviewPanel {
this.piService.emitScopedModels();
break;

// Open the native VS Code Settings filtered to this extension
case "openVscodeSettings": {
const pkg = (this.context.extension?.packageJSON ?? {}) as {
publisher?: unknown;
name?: unknown;
};
await vscode.commands.executeCommand(
"workbench.action.openSettings",
extensionSettingsQuery(pkg.publisher, pkg.name),
);
break;
}

// Context budget picker
case "pickContextBudget":
void this.triggerContextBudgetPicker();
Expand Down Expand Up @@ -1063,7 +1077,7 @@ export class PiWebviewPanel {
<div class="pi-sb-item spacer"></div>
<div class="pi-sb-item" id="pi-sb-capabilities" title="Manage capabilities for this session">capabilities: 0</div>
<div class="pi-sb-item" id="pi-sb-usage" title="Click to set context budget">0%</div>
<div class="pi-sb-item" id="pi-sb-settings" title="Settings">⚙</div>
<div class="pi-sb-item" id="pi-sb-settings" title="Open Pi on Code settings in VS Code">⚙</div>
</div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion src/webview/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2213,7 +2213,8 @@ export function sendPrompt(modeOverride?: "steer" | "queue"): void {
let sbSettings = document.getElementById("pi-sb-settings");
if (sbSettings) {
sbSettings.addEventListener("click", function () {
toggleSettingsPanel();
// Gear opens the native VS Code Settings filtered to this extension.
window.__vscode.postMessage({ type: "openVscodeSettings" });
});
}

Expand Down
Loading