Skip to content

Commit 3a281fe

Browse files
committed
Optimistically update edit format state on frontend and simplify backend save handler
- currently changing 'edit format instructions' go through backed so using shortcuts feel sluggish ├── apps │ └── editor │ └── src │ ├── constants │ │ ├── edit-format-instructions.ts │ │ └── state-keys.ts │ ├── i18n │ │ └── translations │ │ └── views │ │ └── prompt │ │ └── handlers │ │ ├── handle-select-edit-format-instructions.ts │ │ └── index.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-autofill.ts │ │ │ ├── handle-copy-prompt.ts │ │ │ ├── handle-get-edit-format-instructions.ts │ │ │ ├── handle-make-api-call.ts │ │ │ ├── handle-preview-prompt.ts │ │ │ ├── handle-preview-web-configuration.ts │ │ │ ├── handle-save-edit-format.ts │ │ │ ├── handle-select-edit-format-instructions.ts │ │ │ └── index.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ └── i18n │ │ └── translations │ │ ├── index.ts │ │ └── prompt-field.ts │ └── types │ └── messages.ts ├── docs │ └── chatbot-initialization.mdx └── packages ├── shared │ └── src │ └── types │ └── edit-format.ts └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.tsx └── components └── Footer └── Footer.tsx
1 parent 11d79d2 commit 3a281fe

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-save-edit-format.ts‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@ import { EDIT_FORMAT_STATE_KEY } from '@/constants/state-keys'
22
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
33
import { SaveEditFormatMessage } from '@/views/prompt/types/messages'
44

5-
export const handle_save_edit_format = async (
5+
export const handle_save_edit_format = (
66
prompt_view_provider: PromptViewProvider,
77
message: SaveEditFormatMessage
8-
): Promise<void> => {
8+
): void => {
99
prompt_view_provider.edit_format = message.edit_format
1010

11-
await Promise.all([
12-
prompt_view_provider.extension_context.workspaceState.update(
13-
EDIT_FORMAT_STATE_KEY,
14-
message.edit_format
15-
),
16-
prompt_view_provider.extension_context.globalState.update(
17-
EDIT_FORMAT_STATE_KEY,
18-
message.edit_format
19-
)
20-
])
21-
22-
prompt_view_provider.send_message({
23-
command: 'EDIT_FORMAT',
24-
edit_format: prompt_view_provider.edit_format
25-
})
11+
prompt_view_provider.extension_context.workspaceState.update(
12+
EDIT_FORMAT_STATE_KEY,
13+
message.edit_format
14+
)
15+
prompt_view_provider.extension_context.globalState.update(
16+
EDIT_FORMAT_STATE_KEY,
17+
message.edit_format
18+
)
2619
}

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import { handle_agentic_search } from './message-handlers/handle-agentic-search'
1616
import { handle_preview_saved_context_symbol } from './message-handlers/handle-preview-saved-context-symbol'
1717
import { SelectionState, UpdateInfo } from '../types/messages'
1818
import * as state_keys from '@/constants/state-keys'
19-
import {
20-
ConfigWebConfigurationFormat
21-
} from '@/utils/web-configuration-format-converters'
19+
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
2220
import {
2321
config_cli_configuration_to_ui_format,
2422
ConfigAgentConfigurationFormat
@@ -213,12 +211,9 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
213211
this.agentic_search_state = params.agentic_search_state
214212

215213
this.check_for_updates()
216-
setInterval(
217-
() => {
218-
this.check_for_updates()
219-
},
220-
UPDATE_CHECK_INTERVAL
221-
)
214+
setInterval(() => {
215+
this.check_for_updates()
216+
}, UPDATE_CHECK_INTERVAL)
222217

223218
this.websocket_server_instance.on_connection_status_change((connected) => {
224219
if (this.webview_view) {
@@ -458,7 +453,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
458453
if (!current_version) return
459454

460455
this.update_info = await check_for_updates(current_version)
461-
456+
462457
this.send_message({
463458
command: 'UPDATE_INFO',
464459
update_info: this.update_info
@@ -648,23 +643,32 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
648643
} else if (message.command === 'TOGGLE_PINNED_API_CONFIGURATION') {
649644
await handlers.handle_toggle_pinned_api_configuration(this, message)
650645
} else if (message.command === 'SAVE_WEB_PROMPT_TYPE') {
651-
await handlers.handle_save_web_prompt_type(this, message.prompt_type)
646+
await handlers.handle_save_web_prompt_type(
647+
this,
648+
message.prompt_type
649+
)
652650
} else if (message.command === 'GET_API_PROMPT_TYPE') {
653651
handlers.handle_get_api_prompt_type(this)
654652
} else if (message.command === 'SAVE_API_PROMPT_TYPE') {
655-
await handlers.handle_save_api_prompt_type(this, message.prompt_type)
653+
await handlers.handle_save_api_prompt_type(
654+
this,
655+
message.prompt_type
656+
)
656657
} else if (message.command === 'GET_CLI_PROMPT_TYPE') {
657658
handlers.handle_get_cli_prompt_type(this)
658659
} else if (message.command === 'SAVE_CLI_PROMPT_TYPE') {
659-
await handlers.handle_save_cli_prompt_type(this, message.prompt_type)
660+
await handlers.handle_save_cli_prompt_type(
661+
this,
662+
message.prompt_type
663+
)
660664
} else if (message.command === 'INVOKE_AGENTIC_CLI') {
661665
await handlers.handle_invoke_agentic_cli(this, message as any)
662666
} else if (message.command === 'GET_EDIT_FORMAT_INSTRUCTIONS') {
663667
handlers.handle_get_edit_format_instructions(this)
664668
} else if (message.command === 'GET_EDIT_FORMAT') {
665669
handlers.handle_get_edit_format(this)
666670
} else if (message.command === 'SAVE_EDIT_FORMAT') {
667-
await handlers.handle_save_edit_format(this, message)
671+
handlers.handle_save_edit_format(this, message)
668672
} else if (message.command === 'SELECT_EDIT_FORMAT_INSTRUCTIONS') {
669673
await handlers.handle_select_edit_format_instructions(this, message)
670674
} else if (message.command === 'CARET_POSITION_CHANGED') {
@@ -678,7 +682,10 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
678682
} else if (message.command === 'SHOW_AT_SIGN_QUICK_PICK') {
679683
await handlers.handle_at_sign_quick_pick(this)
680684
} else if (message.command === 'SHOW_HASH_SIGN_QUICK_PICK') {
681-
await handlers.handle_hash_sign_quick_pick(this, this.extension_context)
685+
await handlers.handle_hash_sign_quick_pick(
686+
this,
687+
this.extension_context
688+
)
682689
} else if (message.command === 'GO_TO_FILE') {
683690
handlers.handle_go_to_file(message)
684691
} else if (message.command === 'OPEN_FILE_AND_SELECT') {
@@ -876,7 +883,8 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
876883
selected_cli_configuration_name_by_mode: Object.fromEntries(
877884
cli_prompt_types.map((prompt_type) => {
878885
let selected_name: string | undefined = undefined
879-
const key = state_keys.get_last_used_cli_configuration_key(prompt_type)
886+
const key =
887+
state_keys.get_last_used_cli_configuration_key(prompt_type)
880888
const last_selected =
881889
this.extension_context.workspaceState.get<string>(key) ??
882890
this.extension_context.globalState.get<string>(key)
@@ -908,7 +916,8 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
908916
selected_web_configuration_name_by_mode: Object.fromEntries(
909917
web_prompt_types.map((prompt_type) => {
910918
let selected_name: string | undefined = undefined
911-
const key = state_keys.get_last_used_web_configuration_key(prompt_type)
919+
const key =
920+
state_keys.get_last_used_web_configuration_key(prompt_type)
912921
const last_selected =
913922
this.extension_context.workspaceState.get<string>(key) ??
914923
this.extension_context.globalState.get<string>(key)

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ export const Main: React.FC<Props> = (props) => {
466466

467467
const handle_edit_format_change = (format?: EditFormat) => {
468468
if (format) {
469+
set_edit_format(format)
469470
post_message(props.vscode, {
470471
command: 'SAVE_EDIT_FORMAT',
471472
edit_format: format

0 commit comments

Comments
 (0)