| 25 | } |
| 26 | |
| 27 | async function findVsCodeCommand(): Promise<string | null> { |
| 28 | // 1. Check PATH first. |
| 29 | try { |
| 30 | child_process.execSync( |
| 31 | process.platform === 'win32' |
| 32 | ? `where.exe ${VSCODE_COMMAND}` |
| 33 | : `command -v ${VSCODE_COMMAND}`, |
| 34 | { stdio: 'ignore' }, |
| 35 | ); |
| 36 | return VSCODE_COMMAND; |
| 37 | } catch { |
| 38 | // Not in PATH, continue to check common locations. |
| 39 | } |
| 40 | |
| 41 | // 2. Check common installation locations. |
| 42 | const locations: string[] = []; |
| 43 | const platform = process.platform; |
| 44 | const homeDir = os.homedir(); |
| 45 | |
| 46 | if (platform === 'darwin') { |
| 47 | // macOS |
| 48 | locations.push( |
| 49 | '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code', |
| 50 | path.join(homeDir, 'Library/Application Support/Code/bin/code'), |
| 51 | ); |
| 52 | } else if (platform === 'linux') { |
| 53 | // Linux |
| 54 | locations.push( |
| 55 | '/usr/share/code/bin/code', |
| 56 | '/snap/bin/code', |
| 57 | path.join(homeDir, '.local/share/code/bin/code'), |
| 58 | ); |
| 59 | } else if (platform === 'win32') { |
| 60 | // Windows |
| 61 | locations.push( |
| 62 | path.join( |
| 63 | process.env['ProgramFiles'] || 'C:\\Program Files', |
| 64 | 'Microsoft VS Code', |
| 65 | 'bin', |
| 66 | 'code.cmd', |
| 67 | ), |
| 68 | path.join( |
| 69 | homeDir, |
| 70 | 'AppData', |
| 71 | 'Local', |
| 72 | 'Programs', |
| 73 | 'Microsoft VS Code', |
| 74 | 'bin', |
| 75 | 'code.cmd', |
| 76 | ), |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | for (const location of locations) { |
| 81 | if (fs.existsSync(location)) { |
| 82 | return location; |
| 83 | } |
| 84 | } |