* Find an existing QodeX terminal or create a new one. We reuse terminals so * repeated commands don't pile up tabs.
(cwd: string)
| 41 | * repeated commands don't pile up tabs. |
| 42 | */ |
| 43 | function getOrCreateTerminal(cwd: string): vscode.Terminal { |
| 44 | const cfg = getConfig(); |
| 45 | const existing = vscode.window.terminals.find(t => t.name === cfg.terminalName); |
| 46 | if (existing) { |
| 47 | existing.show(); |
| 48 | return existing; |
| 49 | } |
| 50 | const terminal = vscode.window.createTerminal({ |
| 51 | name: cfg.terminalName, |
| 52 | cwd, |
| 53 | env: { |
| 54 | ...process.env, |
| 55 | // Force HOME to a sane value. Some macOS launch paths (Spotlight, |
| 56 | // Applications folder, Finder double-click) leave HOME unset or set |
| 57 | // to '/' in the extension host, which propagates into the spawned |
| 58 | // terminal and breaks ~/.qodex resolution. |
| 59 | HOME: process.env.HOME && process.env.HOME !== '/' ? process.env.HOME : os.homedir(), |
| 60 | QODEX_LAUNCHED_FROM: 'vscode', |
| 61 | }, |
| 62 | }); |
| 63 | terminal.show(); |
| 64 | return terminal; |
| 65 | } |
| 66 | |
| 67 | /** Determine the right working directory: workspace folder if available, else file's dir, else home. */ |
| 68 | function getCwd(): string { |
no test coverage detected