feat(code-actions): add user input and customizable templates

Add ability to provide custom input when using code actions
Make code action templates customizable and resettable
Refactor code action handling for better maintainability
Add state management for utility prompts
This commit is contained in:
sam hoang
2025-01-13 02:48:52 +07:00
parent 1b26f91ea7
commit 7845791720
4 changed files with 81 additions and 30 deletions

View File

@@ -40,6 +40,12 @@ import { enhancePrompt } from "../../utils/enhance-prompt"
import { getCommitInfo, searchCommits, getWorkingState } from "../../utils/git"
import { ConfigManager } from "../config/ConfigManager"
import { CustomModesManager } from "../config/CustomModesManager"
import {
defaultTemplates,
createPrompt
} from "../prompts/code-actions"
import { ACTION_NAMES } from "../CodeActionProvider"
/*
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -182,7 +188,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
}
public static async handleCodeAction(
promptGenerator: (params: Record<string, string | any[]>) => string,
promptType: keyof typeof ACTION_NAMES,
params: Record<string, string | any[]>
): Promise<void> {
const visibleProvider = ClineProvider.getVisibleInstance()
@@ -190,8 +196,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
return
}
const prompt = promptGenerator(params)
const { utilPrompt } = await visibleProvider.getState()
const template = utilPrompt?.[promptType] ?? defaultTemplates[promptType]
const prompt = createPrompt(template, params)
await visibleProvider.initClineWithTask(prompt)
}