(context: vscode.ExtensionContext, command: CodeActionId, promptType: CodeActionName)
| 14 | } |
| 15 | |
| 16 | const registerCodeAction = (context: vscode.ExtensionContext, command: CodeActionId, promptType: CodeActionName) => { |
| 17 | let userInput: string | undefined |
| 18 | |
| 19 | context.subscriptions.push( |
| 20 | vscode.commands.registerCommand(getCodeActionCommand(command), async (...args: any[]) => { |
| 21 | // Handle both code action and direct command cases. |
| 22 | let filePath: string |
| 23 | let selectedText: string |
| 24 | let startLine: number | undefined |
| 25 | let endLine: number | undefined |
| 26 | let diagnostics: any[] | undefined |
| 27 | |
| 28 | if (args.length > 1) { |
| 29 | // Called from code action. |
| 30 | ;[filePath, selectedText, startLine, endLine, diagnostics] = args |
| 31 | } else { |
| 32 | // Called directly from command palette. |
| 33 | const context = EditorUtils.getEditorContext() |
| 34 | |
| 35 | if (!context) { |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | ;({ filePath, selectedText, startLine, endLine, diagnostics } = context) |
| 40 | } |
| 41 | |
| 42 | const params = { |
| 43 | ...{ filePath, selectedText }, |
| 44 | ...(startLine !== undefined ? { startLine: startLine.toString() } : {}), |
| 45 | ...(endLine !== undefined ? { endLine: endLine.toString() } : {}), |
| 46 | ...(diagnostics ? { diagnostics } : {}), |
| 47 | ...(userInput ? { userInput } : {}), |
| 48 | } |
| 49 | |
| 50 | await ClineProvider.handleCodeAction(command, promptType, params) |
| 51 | }), |
| 52 | ) |
| 53 | } |
no test coverage detected