Skip to content

Commit dae7013

Browse files
committed
Refactor the extension's rating mechanism from a webview message to a direct VS Code command
1 parent a7869fe commit dae7013

10 files changed

Lines changed: 33 additions & 24 deletions

File tree

packages/vscode/package.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@
116116
"title": "Apply Context from Clipboard",
117117
"category": "Code Web Chat"
118118
},
119+
{
120+
"command": "codeWebChat.openRepository",
121+
"title": "Repository",
122+
"category": "Code Web Chat",
123+
"icon": "$(github-alt)"
124+
},
125+
{
126+
"command": "codeWebChat.rate",
127+
"title": "Rate",
128+
"category": "Code Web Chat",
129+
"icon": "$(star)"
130+
},
119131
{
120132
"command": "codeWebChat.applyContext",
121133
"title": "Apply Context",
@@ -328,6 +340,10 @@
328340
"command": "codeWebChat.clearChecks",
329341
"when": "false"
330342
},
343+
{
344+
"command": "codeWebChat.rate",
345+
"when": "false"
346+
},
331347
{
332348
"command": "codeWebChat.clearChecksOpenEditors",
333349
"when": "false"
@@ -480,9 +496,14 @@
480496
"group": "navigation@1"
481497
},
482498
{
483-
"command": "codeWebChat.settings",
499+
"command": "codeWebChat.rate",
484500
"when": "view == codeWebChatView",
485501
"group": "navigation@2"
502+
},
503+
{
504+
"command": "codeWebChat.settings",
505+
"when": "view == codeWebChatView",
506+
"group": "navigation@3"
486507
}
487508
],
488509
"view/item/context": [

packages/vscode/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './open-file-from-workspace-command'
1414
export * from './open-url-command'
1515
export * from './open-settings-command'
1616
export * from './reference-in-chat-command'
17+
export * from './rate-command'
1718
export * from './rename-command'
1819
export * from './revert-command'
1920
export * from './save-all-command'

packages/vscode/src/view/backend/message-handlers/handle-review.ts renamed to packages/vscode/src/commands/rate-command.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22

3-
export const handle_review = async (): Promise<void> => {
3+
const rate = async (): Promise<void> => {
44
const options = [
55
{
66
label: 'Visual Studio Marketplace',
@@ -24,3 +24,6 @@ export const handle_review = async (): Promise<void> => {
2424
vscode.env.openExternal(vscode.Uri.parse(selected_option.url))
2525
}
2626
}
27+
28+
export const rate_command = () =>
29+
vscode.commands.registerCommand('codeWebChat.rate', rate)

packages/vscode/src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
reference_in_chat_command,
3636
open_settings_command,
3737
open_url_command,
38+
rate_command,
3839
edit_context_commands,
3940
apply_context_from_clipboard_command
4041
} from './commands'
@@ -158,6 +159,7 @@ export async function activate(context: vscode.ExtensionContext) {
158159
command: 'codeWebChat.openRepository',
159160
url: 'https://github.com/robertpiosik/CodeWebChat'
160161
}),
162+
rate_command(),
161163
open_settings_command(context),
162164
apply_context_from_clipboard_command(workspace_provider)
163165
)

packages/vscode/src/utils/at-sign-quick-pick.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ export async function at_sign_quick_pick(
1111
const items = [
1212
{
1313
label: '@Selection',
14-
description: 'Inject text selection of the active editor'
14+
description: 'Text selection of the active editor'
1515
},
1616
{
1717
label: '@Changes',
18-
description:
19-
'Inject changes between the current branch and the selected branch'
18+
description: 'Changes between the current branch and the selected branch'
2019
},
2120
{
2221
label: '@SavedContext',
23-
description: 'Inject files from a saved context'
22+
description: 'Files from a saved context'
2423
}
2524
]
2625

packages/vscode/src/view/backend/message-handlers/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ export * from './handle-get-mode-web'
3232
export * from './handle-get-mode-api'
3333
export * from './handle-save-mode-web'
3434
export * from './handle-save-mode-api'
35-
export * from './handle-review'

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ import {
4646
handle_get_mode_api,
4747
handle_save_mode_api,
4848
handle_save_home_view_type,
49-
handle_get_home_view_type,
50-
handle_review
49+
handle_get_home_view_type
5150
} from './message-handlers'
5251
import {
5352
config_preset_to_ui_format,
@@ -398,8 +397,6 @@ export class ViewProvider implements vscode.WebviewViewProvider {
398397
handle_get_home_view_type(this)
399398
} else if (message.command == 'SHOW_AT_SIGN_QUICK_PICK') {
400399
await handle_at_sign_quick_pick(this, this.context)
401-
} else if (message.command == 'REVIEW') {
402-
await handle_review()
403400
}
404401
} catch (error: any) {
405402
console.error('Error handling message:', message, error)

packages/vscode/src/view/frontend/home/Home.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,6 @@ export const Home: React.FC<Props> = (props) => {
390390
} as WebviewMessage)
391391
}
392392

393-
const handle_review_click = () => {
394-
props.vscode.postMessage({
395-
command: 'REVIEW'
396-
} as WebviewMessage)
397-
}
398-
399393
const handle_quick_action_click = (command: string) => {
400394
props.vscode.postMessage({
401395
command: 'EXECUTE_COMMAND',
@@ -499,7 +493,6 @@ export const Home: React.FC<Props> = (props) => {
499493
on_code_completion_with_quick_pick_click={
500494
handle_code_completion_with_quick_pick_click
501495
}
502-
on_review_click={handle_review_click}
503496
/>
504497
)
505498
}

packages/vscode/src/view/frontend/home/HomeView/HomeView.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type Props = {
5353
on_edit_context_with_quick_pick_click: () => void
5454
on_code_completion_click: () => void
5555
on_code_completion_with_quick_pick_click: () => void
56-
on_review_click: () => void
5756
}
5857

5958
const web_mode_labels: Record<WebMode, string> = {

packages/vscode/src/view/types/messages.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ export interface SaveApiModeMessage extends BaseMessage {
193193
mode: ApiMode
194194
}
195195

196-
export interface ReviewMessage extends BaseMessage {
197-
command: 'REVIEW'
198-
}
199-
200196
// Messages from extension to webview:
201197
export interface InstructionsMessage extends BaseMessage {
202198
command: 'INSTRUCTIONS'
@@ -375,7 +371,6 @@ export type WebviewMessage =
375371
| GetWebModeMessage
376372
| GetApiModeMessage
377373
| SaveApiModeMessage
378-
| ReviewMessage
379374

380375
export type ExtensionMessage =
381376
| InstructionsMessage

0 commit comments

Comments
 (0)