| 70 | * quickly edit a file. |
| 71 | */ |
| 72 | export class QuickEdit { |
| 73 | /** |
| 74 | * Matches the search char followed by non-space chars, excluding matches ending with a space. |
| 75 | * This is used to detect file search queries while allowing subsequent prompt text |
| 76 | */ |
| 77 | private static hasFileSearchQueryRegex = new RegExp( |
| 78 | `${FILE_SEARCH_CHAR}[^${FILE_SEARCH_CHAR}\\s]+(?!\\s)$`, |
| 79 | ); |
| 80 | |
| 81 | private static maxFileSearchResults = 20; |
| 82 | |
| 83 | private range?: vscode.Range; |
| 84 | private initialPrompt?: string; |
| 85 | |
| 86 | private previousInput?: string; |
| 87 | |
| 88 | /** |
| 89 | * Handles situations where the user navigates to a different editor |
| 90 | * while interacting with the Quick Pick |
| 91 | */ |
| 92 | private editorWhenOpened!: vscode.TextEditor; |
| 93 | |
| 94 | /** |
| 95 | * Required to store the string content of a context provider |
| 96 | * while naviagting beween Quick Picks. |
| 97 | */ |
| 98 | private contextProviderStr?: string; |
| 99 | |
| 100 | constructor( |
| 101 | private readonly verticalDiffManager: VerticalDiffManager, |
| 102 | private readonly configHandler: ConfigHandler, |
| 103 | private readonly webviewProtocol: VsCodeWebviewProtocol, |
| 104 | private readonly ide: IDE, |
| 105 | private readonly context: vscode.ExtensionContext, |
| 106 | private readonly fileSearch: FileSearch, |
| 107 | ) {} |
| 108 | |
| 109 | /** |
| 110 | * Shows the Quick Edit Quick Pick, allowing the user to select an initial item or enter a prompt. |
| 111 | * Displays a quick pick for "History" or "ContextProviders" to set the prompt or context provider string. |
| 112 | * Displays a quick pick for "Model" to set the current model title. |
| 113 | * Appends the entered prompt to the history and streams the edit with input and context. |
| 114 | */ |
| 115 | async show(params?: QuickEditShowParams) { |
| 116 | // Clean up state from previous quick picks, e.g. if a user pressed `esc` |
| 117 | |
| 118 | const editor = vscode.window.activeTextEditor; |
| 119 | |
| 120 | // We only allow users to interact with a quick edit if there is an open editor |
| 121 | if (!editor) { |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | const hasChanges = !!this.verticalDiffManager.getHandlerForFile( |
| 126 | editor.document.uri.toString(), |
| 127 | ); |
| 128 | |
| 129 | if (hasChanges) { |
nothing calls this directly
no test coverage detected