fix(extensions): improve VS Code launch on Windows in diff/files (#2288)
Use cmd-based VS Code launcher on win32 in /diff and /files. Show explicit error details when open fails. In /diff, surface git difftool failure and troubleshooting hint. Refs #2186
This commit is contained in:
@@ -66,12 +66,26 @@ export default function (pi: ExtensionAPI) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openWithCode = async (file: string) => {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
return pi.exec("cmd", ["/d", "/s", "/c", "code", "-g", file], { cwd: ctx.cwd });
|
||||||
|
}
|
||||||
|
return pi.exec("code", ["-g", file], { cwd: ctx.cwd });
|
||||||
|
};
|
||||||
|
|
||||||
const openSelected = async (fileInfo: FileInfo): Promise<void> => {
|
const openSelected = async (fileInfo: FileInfo): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
// Open in VS Code diff view.
|
// Open in VS Code diff view.
|
||||||
// For untracked files, git difftool won't work, so fall back to just opening the file.
|
// For untracked files, git difftool won't work, so fall back to just opening the file.
|
||||||
if (fileInfo.status === "?") {
|
if (fileInfo.status === "?") {
|
||||||
await pi.exec("code", ["-g", fileInfo.file], { cwd: ctx.cwd });
|
const openResult = await openWithCode(fileInfo.file);
|
||||||
|
if (openResult.code !== 0) {
|
||||||
|
const openStderr = openResult.stderr.trim();
|
||||||
|
ctx.ui.notify(
|
||||||
|
`Failed to open ${fileInfo.file} (exit ${openResult.code})${openStderr ? `: ${openStderr}` : ""}`,
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +93,24 @@ export default function (pi: ExtensionAPI) {
|
|||||||
cwd: ctx.cwd,
|
cwd: ctx.cwd,
|
||||||
});
|
});
|
||||||
if (diffResult.code !== 0) {
|
if (diffResult.code !== 0) {
|
||||||
await pi.exec("code", ["-g", fileInfo.file], { cwd: ctx.cwd });
|
const diffStderr = diffResult.stderr.trim();
|
||||||
|
ctx.ui.notify(
|
||||||
|
`Failed to show diff with vscode for ${fileInfo.file} (exit ${diffResult.code})${diffStderr ? `: ${diffStderr}` : ""}`,
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
ctx.ui.notify(
|
||||||
|
"Troubleshooting: check git difftool config (e.g. `git config --get difftool.vscode.cmd`).",
|
||||||
|
"info",
|
||||||
|
);
|
||||||
|
|
||||||
|
const openResult = await openWithCode(fileInfo.file);
|
||||||
|
if (openResult.code !== 0) {
|
||||||
|
const openStderr = openResult.stderr.trim();
|
||||||
|
ctx.ui.notify(
|
||||||
|
`Failed to open ${fileInfo.file} (exit ${openResult.code})${openStderr ? `: ${openStderr}` : ""}`,
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
|||||||
@@ -89,9 +89,23 @@ export default function (pi: ExtensionAPI) {
|
|||||||
// Sort by most recent first
|
// Sort by most recent first
|
||||||
const files = Array.from(fileMap.values()).sort((a, b) => b.lastTimestamp - a.lastTimestamp);
|
const files = Array.from(fileMap.values()).sort((a, b) => b.lastTimestamp - a.lastTimestamp);
|
||||||
|
|
||||||
|
const openWithCode = async (path: string) => {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
return pi.exec("cmd", ["/d", "/s", "/c", "code", "-g", path], { cwd: ctx.cwd });
|
||||||
|
}
|
||||||
|
return pi.exec("code", ["-g", path], { cwd: ctx.cwd });
|
||||||
|
};
|
||||||
|
|
||||||
const openSelected = async (file: FileEntry): Promise<void> => {
|
const openSelected = async (file: FileEntry): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await pi.exec("code", ["-g", file.path], { cwd: ctx.cwd });
|
const openResult = await openWithCode(file.path);
|
||||||
|
if (openResult.code !== 0) {
|
||||||
|
const openStderr = openResult.stderr.trim();
|
||||||
|
ctx.ui.notify(
|
||||||
|
`Failed to open ${file.path} (exit ${openResult.code})${openStderr ? `: ${openStderr}` : ""}`,
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
ctx.ui.notify(`Failed to open ${file.path}: ${message}`, "error");
|
ctx.ui.notify(`Failed to open ${file.path}: ${message}`, "error");
|
||||||
|
|||||||
Reference in New Issue
Block a user