Skip to content

Commit 18452e6

Browse files
committed
Refine Tools tab button states and text, and update the quick pick message handler to execute commands directly
1 parent 296b366 commit 18452e6

3 files changed

Lines changed: 19 additions & 30 deletions

File tree

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
import { ViewProvider } from '@/view/backend/view-provider'
21
import * as vscode from 'vscode'
3-
import { ExtensionMessage } from '@/view/types/messages'
2+
import { ShowQuickPickMessage } from '@/view/types/messages'
43

54
export const handle_show_quick_pick = async (
6-
provider: ViewProvider,
7-
items: Array<{ label: string; description: string; command: string }>,
8-
title: string
5+
message: ShowQuickPickMessage
96
): Promise<void> => {
10-
const quick_pick_items = items.map((item) => ({
7+
const quick_pick_items = message.items.map((item) => ({
118
label: item.label,
129
description: item.description
1310
}))
1411

1512
const selected_item = await vscode.window.showQuickPick(quick_pick_items, {
16-
placeHolder: title
13+
placeHolder: message.title
1714
})
1815

1916
if (selected_item) {
20-
const selectedCommand = items.find(
17+
const selected_command = message.items.find(
2118
(item) => item.label == selected_item.label
2219
)?.command
2320

24-
if (selectedCommand) {
25-
provider.send_message<ExtensionMessage>({
26-
command: 'EXECUTE_COMMAND',
27-
command_id: selectedCommand
28-
})
21+
if (selected_command) {
22+
vscode.commands.executeCommand(selected_command)
2923
}
3024
}
3125
}

packages/vscode/src/view/backend/view-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export class ViewProvider implements vscode.WebviewViewProvider {
453453
} else if (message.command == 'EXECUTE_COMMAND') {
454454
vscode.commands.executeCommand(message.command_id)
455455
} else if (message.command == 'SHOW_QUICK_PICK') {
456-
await handle_show_quick_pick(this, message.items, message.title)
456+
await handle_show_quick_pick(message)
457457
} else if (message.command == 'GET_EDIT_FORMAT') {
458458
this.send_message<ExtensionMessage>({
459459
command: 'EDIT_FORMAT',

packages/vscode/src/view/frontend/tabs/tools/ToolsTab.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,15 @@ export const ToolsTab: React.FC<Props> = (props) => {
6868
})
6969
}
7070

71-
const code_completion_title = has_active_editor
72-
? 'Insert code completion at the caret position'
73-
: 'Requires an active editor'
71+
const code_completion_title =
72+
has_active_editor && !has_active_selection
73+
? undefined
74+
: has_active_selection
75+
? 'Unavailable with text selection'
76+
: 'Requires an active editor'
7477

7578
const refactor_title = has_active_editor
76-
? 'Refactor the content of the active file'
77-
: 'Requires an active editor'
78-
79-
const apply_chat_response_title = has_active_editor
80-
? has_active_selection
81-
? 'Replace selection or insert at caret with chat response from clipboard'
82-
: 'Insert at caret with chat response from clipboard'
79+
? undefined
8380
: 'Requires an active editor'
8481

8582
const configuration_title = 'Configure API tool settings'
@@ -95,27 +92,25 @@ export const ToolsTab: React.FC<Props> = (props) => {
9592
handle_execute_command('codeWebChat.codeCompletionAutoAccept')
9693
}}
9794
on_quick_pick_trigger_click={handle_code_completions_more_actions}
98-
disabled={!has_active_editor}
95+
disabled={!has_active_editor || has_active_selection}
9996
title={code_completion_title}
10097
>
101-
Insert Code Completion
98+
Code Completion at Cursor
10299
</Button>
103100
<Button
104101
on_click={() => handle_execute_command('codeWebChat.refactor')}
105102
on_quick_pick_trigger_click={handle_file_refactoring_more_actions}
106103
disabled={!has_active_editor}
107104
title={refactor_title}
108105
>
109-
Refactor Active File
106+
Refactor File with Instructions
110107
</Button>
111108
<Button
112109
on_click={() =>
113110
handle_execute_command('codeWebChat.applyChatResponse')
114111
}
115-
disabled={!has_active_editor}
116-
title={apply_chat_response_title}
117112
>
118-
Apply Chat Response
113+
Apply Copied Chat Response
119114
</Button>
120115
</div>
121116

0 commit comments

Comments
 (0)