fix(vscode): enhance Windows executable detection in opencode path resolution
This commit is contained in:
@@ -10,6 +10,7 @@ import { randomBytes } from 'crypto';
|
|||||||
import { normalizeWindowsDriveLetter } from './pathUtils';
|
import { normalizeWindowsDriveLetter } from './pathUtils';
|
||||||
|
|
||||||
const READY_CHECK_TIMEOUT_MS = 30000;
|
const READY_CHECK_TIMEOUT_MS = 30000;
|
||||||
|
const WINDOWS_EXECUTABLE_EXTENSIONS = ['', '.exe', '.cmd', '.bat', '.com'];
|
||||||
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
||||||
|
|
||||||
export type OpenCodeDebugInfo = {
|
export type OpenCodeDebugInfo = {
|
||||||
@@ -139,15 +140,18 @@ function findExecutableInPath(binaryName: string): string | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const extensions = process.platform === 'win32' ? WINDOWS_EXECUTABLE_EXTENSIONS : [''];
|
||||||
for (const segment of current.split(path.delimiter)) {
|
for (const segment of current.split(path.delimiter)) {
|
||||||
const dir = segment.trim();
|
const dir = segment.trim();
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const candidate = path.join(dir, trimmed);
|
for (const ext of extensions) {
|
||||||
if (isExecutable(candidate)) {
|
const candidate = path.join(dir, process.platform === 'win32' ? `${trimmed}${ext}` : trimmed);
|
||||||
return candidate;
|
if (isExecutable(candidate)) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,14 +313,18 @@ function resolveOpencodeCliPath(): string | null {
|
|||||||
|
|
||||||
const winFallbacks = (() => {
|
const winFallbacks = (() => {
|
||||||
const userProfile = process.env.USERPROFILE || home;
|
const userProfile = process.env.USERPROFILE || home;
|
||||||
const appData = process.env.APPDATA || '';
|
const appData = process.env.APPDATA || path.join(userProfile, 'AppData', 'Roaming');
|
||||||
const localAppData = process.env.LOCALAPPDATA || '';
|
const localAppData = process.env.LOCALAPPDATA || '';
|
||||||
const programData = process.env.ProgramData || 'C:\\ProgramData';
|
const programData = process.env.ProgramData || 'C:\\ProgramData';
|
||||||
|
const npmDir = path.join(appData, 'npm');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
path.join(userProfile, '.opencode', 'bin', 'opencode.exe'),
|
path.join(userProfile, '.opencode', 'bin', 'opencode.exe'),
|
||||||
path.join(userProfile, '.opencode', 'bin', 'opencode.cmd'),
|
path.join(userProfile, '.opencode', 'bin', 'opencode.cmd'),
|
||||||
path.join(appData, 'npm', 'opencode.cmd'),
|
path.join(npmDir, 'node_modules', 'opencode-ai', 'bin', 'opencode.exe'),
|
||||||
|
path.join(npmDir, 'opencode.exe'),
|
||||||
|
path.join(npmDir, 'opencode.cmd'),
|
||||||
|
path.join(npmDir, 'opencode.bat'),
|
||||||
path.join(userProfile, 'scoop', 'shims', 'opencode.cmd'),
|
path.join(userProfile, 'scoop', 'shims', 'opencode.cmd'),
|
||||||
path.join(programData, 'chocolatey', 'bin', 'opencode.exe'),
|
path.join(programData, 'chocolatey', 'bin', 'opencode.exe'),
|
||||||
path.join(programData, 'chocolatey', 'bin', 'opencode.cmd'),
|
path.join(programData, 'chocolatey', 'bin', 'opencode.cmd'),
|
||||||
@@ -328,12 +336,10 @@ function resolveOpencodeCliPath(): string | null {
|
|||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if (process.platform !== 'win32') {
|
const fromPath = findExecutableInPath('opencode');
|
||||||
const fromPath = findExecutableInPath('opencode');
|
if (fromPath) {
|
||||||
if (fromPath) {
|
cachedDetectedOpencodeCliPath = fromPath;
|
||||||
cachedDetectedOpencodeCliPath = fromPath;
|
return fromPath;
|
||||||
return fromPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallbacks = process.platform === 'win32' ? winFallbacks : unixFallbacks;
|
const fallbacks = process.platform === 'win32' ? winFallbacks : unixFallbacks;
|
||||||
|
|||||||
Reference in New Issue
Block a user