@henryqw/pi-open-in 1.0.0 → 1.0.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/README.md +4 -0
- package/extensions/open.ts +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,4 +51,8 @@ const { source, value } = loadOpenInConfig();
|
|
|
51
51
|
`source` is `"missing"` or `"file"`. `value.command` is validated.
|
|
52
52
|
Pass an agent directory to `loadOpenInConfig(agentDir)` when needed.
|
|
53
53
|
|
|
54
|
+
`configuredOpenUri(path)` returns a VS Code URI when the executable is `code`.
|
|
55
|
+
For `code -n` and `code --new-window`, it adds `windowId=_blank` so the link opens a new window.
|
|
56
|
+
It returns `undefined` for other commands or invalid config.
|
|
57
|
+
|
|
54
58
|
This extension owns command validation. `@henryqw/pi-config-store` owns the config home and storage.
|
package/extensions/open.ts
CHANGED
|
@@ -31,19 +31,23 @@ export function loadOpenInConfig(agentDir?: string): { source: "file" | "missing
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function configuredOpenUri(path: string): string | undefined {
|
|
34
|
+
let args: string[];
|
|
34
35
|
try {
|
|
35
|
-
|
|
36
|
+
const [executable, ...commandArgs] = loadOpenInConfig().value.command.split(/\s+/);
|
|
37
|
+
if (executable !== "code") return undefined;
|
|
38
|
+
args = commandArgs;
|
|
36
39
|
} catch {
|
|
37
40
|
// Invalid config must not break footer render; just omit the URI.
|
|
38
41
|
return undefined;
|
|
39
42
|
}
|
|
43
|
+
const query = args.includes("-n") || args.includes("--new-window") ? "?windowId=_blank" : "";
|
|
40
44
|
if (path.startsWith("\\\\")) {
|
|
41
45
|
const [host, ...parts] = path.slice(2).split("\\");
|
|
42
46
|
const uri = new URL(`file://${host}`);
|
|
43
47
|
uri.pathname = `/${parts.join("/")}`;
|
|
44
|
-
return `vscode://file//${uri.host}${uri.pathname}`;
|
|
48
|
+
return `vscode://file//${uri.host}${uri.pathname}${query}`;
|
|
45
49
|
}
|
|
46
|
-
return `vscode://file${pathToFileURL(path).pathname}`;
|
|
50
|
+
return `vscode://file${pathToFileURL(path).pathname}${query}`;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
export default function openInExtension(pi: ExtensionAPI): void {
|