Skip to content

Commit 9c52bc6

Browse files
committed
Rename the clipboard application command to and extend its functionality to accept direct refactoring instructions alongside clipboard content
1 parent b7a5b1f commit 9c52bc6

5 files changed

Lines changed: 32 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Generate meaningful summaries of changes adhering to your style.
9898
### Handling chat responses
9999

100100
- `Code Web Chat: Apply Chat Response` - Integrate with the codebase a copied to clipboard overall chat response or a single code block.
101-
- `Code Web Chat: Apply Clipboard Content to Active Editor` - Serves as a flexible fallback for applying AI-generated edits, e.g. broken diffs.
101+
- `Code Web Chat: Refactor Current File` - Refactor the active editor based on clipboard content or instructions, without context.
102102
- `Code Web Chat: Undo Last Changes` - Revert applied AI-suggested edits.
103103

104104
### Code completions

‎packages/vscode/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@
200200
"category": "Code Web Chat"
201201
},
202202
{
203-
"command": "codeWebChat.applyClipboardContentToActiveEditor",
204-
"title": "Apply Clipboard Content to Active Editor",
203+
"command": "codeWebChat.refactorCurrentFile",
204+
"title": "Refactor Current File",
205205
"category": "Code Web Chat"
206206
},
207207
{

‎packages/vscode/src/commands/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export * from './new-folder-command'
1010
export * from './open-file-from-workspace-command'
1111
export * from './open-url-command'
1212
export * from './reference-in-chat-command'
13-
export * from './apply-clipboard-content-to-active-editor-command'
13+
export * from './refactor-current-file-command'
1414
export * from './feedback-command'
1515
export * from './rename-command'
1616
export * from './undo-command'

packages/vscode/src/commands/apply-clipboard-content-to-active-editor-command.ts renamed to packages/vscode/src/commands/refactor-current-file-command.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
} from '../utils/intelligent-update-utils'
99
import { dictionary } from '@shared/constants/dictionary'
1010

11-
export const apply_clipboard_content_to_active_editor_command = (
11+
export const refactor_current_file_command = (
1212
context: vscode.ExtensionContext
1313
) => {
1414
return vscode.commands.registerCommand(
15-
'codeWebChat.applyClipboardContentToActiveEditor',
15+
'codeWebChat.refactorCurrentFile',
1616
async () => {
1717
const editor = vscode.window.activeTextEditor
1818
if (!editor) {
@@ -22,11 +22,31 @@ export const apply_clipboard_content_to_active_editor_command = (
2222
return
2323
}
2424

25+
let instruction: string | undefined
2526
const clipboard_content = await vscode.env.clipboard.readText()
2627
if (!clipboard_content) {
27-
vscode.window.showInformationMessage(
28-
dictionary.information_message.CLIPBOARD_IS_EMPTY
28+
instruction = await vscode.window.showInputBox({
29+
prompt: 'Enter your refactoring instructions'
30+
})
31+
} else {
32+
const choice = await vscode.window.showQuickPick(
33+
['Clipboard', 'Instructions'],
34+
{
35+
placeHolder:
36+
'Use clipboard content or enter new refactoring instructions?'
37+
}
2938
)
39+
40+
if (choice == 'Clipboard') {
41+
instruction = clipboard_content
42+
} else if (choice == 'Instructions') {
43+
instruction = await vscode.window.showInputBox({
44+
prompt: 'Enter your refactoring instructions'
45+
})
46+
}
47+
}
48+
49+
if (!instruction) {
3050
return
3151
}
3252

@@ -60,7 +80,7 @@ export const apply_clipboard_content_to_active_editor_command = (
6080
result = await vscode.window.withProgress(
6181
{
6282
location: vscode.ProgressLocation.Notification,
63-
title: `Applying clipboard content to active editor`,
83+
title: `Refactoring current file`,
6484
cancellable: true
6585
},
6686
async (progress, token) => {
@@ -82,7 +102,7 @@ export const apply_clipboard_content_to_active_editor_command = (
82102
reasoning_effort: intelligent_update_config.reasoning_effort,
83103
file_path: file_path,
84104
file_content: original_content,
85-
instruction: clipboard_content,
105+
instruction,
86106
cancel_token: cancel_token_source.token,
87107
on_chunk: (tokens_per_second, total_tokens) => {
88108
if (estimated_total_tokens > 0) {

‎packages/vscode/src/extension.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
generate_commit_message_command,
2424
commit_changes_command,
2525
reference_in_chat_command,
26-
apply_clipboard_content_to_active_editor_command,
26+
refactor_current_file_command,
2727
open_url_command,
2828
feedback_command,
2929
apply_context_from_clipboard_command
@@ -72,7 +72,7 @@ export async function activate(context: vscode.ExtensionContext) {
7272
),
7373
reference_in_chat_command(view_provider, workspace_provider),
7474
apply_chat_response_command(context, view_provider),
75-
apply_clipboard_content_to_active_editor_command(context),
75+
refactor_current_file_command(context),
7676
undo_command(
7777
context,
7878
view_provider.set_undo_button_state,

0 commit comments

Comments
 (0)