Command 2: ask QodeX about the current selection (or whole file).
()
| 93 | |
| 94 | /** Command 2: ask QodeX about the current selection (or whole file). */ |
| 95 | async function askAboutSelection(): Promise<void> { |
| 96 | const editor = vscode.window.activeTextEditor; |
| 97 | if (!editor) { |
| 98 | vscode.window.showWarningMessage('QodeX: no active editor.'); |
| 99 | return; |
| 100 | } |
| 101 | const selection = editor.selection; |
| 102 | const document = editor.document; |
| 103 | const selectedText = selection.isEmpty ? document.getText() : document.getText(selection); |
| 104 | const filePath = document.uri.fsPath; |
| 105 | const lineRange = selection.isEmpty |
| 106 | ? `whole file` |
| 107 | : `lines ${selection.start.line + 1}-${selection.end.line + 1}`; |
| 108 | |
| 109 | // Prompt the user for their question |
| 110 | const question = await vscode.window.showInputBox({ |
| 111 | prompt: `Ask QodeX about ${path.basename(filePath)} (${lineRange})`, |
| 112 | placeHolder: 'e.g. explain this function, find bugs, suggest improvements', |
| 113 | }); |
| 114 | if (!question) return; |
| 115 | |
| 116 | const cfg = getConfig(); |
| 117 | const cwd = getCwd(); |
| 118 | const term = getOrCreateTerminal(cwd); |
| 119 | // Build a self-contained prompt: file context + user question |
| 120 | // We pass via the CLI's headless mode if configured, else interactive |
| 121 | await writeEditorContext(document, selection); |
| 122 | const { text: diags, count: diagCount } = collectDiagnostics(document.uri, selection.isEmpty ? undefined : selection); |
| 123 | const promptText = |
| 124 | `Look at ${filePath} (${lineRange}). Editor snapshot is in .qodex/editor-context.md — read that first.\n` + |
| 125 | (diagCount ? `The editor currently reports:\n${diags}\n` : '') + |
| 126 | `Question: ${question}`; |
| 127 | if (cfg.openHeadless) { |
| 128 | term.sendText(`${cfg.executablePath} --headless ${shellQuote(promptText)}`); |
| 129 | } else { |
| 130 | term.sendText(`${cfg.executablePath} ${shellQuote(promptText)}`); |
| 131 | } |
| 132 | } |
| 133 |
nothing calls this directly
no test coverage detected