@@ -6,6 +6,11 @@ import { apply_preset_affixes_to_instruction } from '@/utils/apply-preset-affixe
66import { replace_saved_context_placeholder } from '@/utils/replace-saved-context-placeholder'
77import { replace_changes_placeholder } from '@/view/backend/utils/replace-changes-placeholder'
88import { chat_code_completion_instructions } from '@/constants/instructions'
9+ import {
10+ get_last_group_or_preset_choice_state_key ,
11+ get_last_selected_group_state_key ,
12+ get_last_selected_preset_key
13+ } from '@/constants/state-keys'
914import { ConfigPresetFormat } from '../utils/preset-format-converters'
1015import { extract_file_paths_from_instruction } from '@/utils/extract-file-paths-from-instruction'
1116import { CHATBOTS } from '@shared/constants/chatbots'
@@ -20,26 +25,22 @@ export const handle_send_prompt = async (params: {
2025 group_name ?: string
2126 show_quick_pick ?: boolean
2227} ) : Promise < void > => {
23- const LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY = `last-group-or-preset-choice-${ params . provider . web_mode } `
24- const LAST_SELECTED_PRESET_KEY = `last-selected-preset-${ params . provider . web_mode } `
25- const LAST_SELECTED_GROUP_STATE_KEY = `last-selected-group-${ params . provider . web_mode } `
26-
2728 if ( params . preset_name !== undefined ) {
2829 params . provider . context . workspaceState . update (
29- LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY ,
30+ get_last_group_or_preset_choice_state_key ( params . provider . web_mode ) ,
3031 'Preset'
3132 )
3233 params . provider . context . workspaceState . update (
33- LAST_SELECTED_PRESET_KEY ,
34+ get_last_selected_preset_key ( params . provider . web_mode ) ,
3435 params . preset_name
3536 )
3637 } else if ( params . group_name ) {
3738 params . provider . context . workspaceState . update (
38- LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY ,
39+ get_last_group_or_preset_choice_state_key ( params . provider . web_mode ) ,
3940 'Group'
4041 )
4142 params . provider . context . workspaceState . update (
42- LAST_SELECTED_GROUP_STATE_KEY ,
43+ get_last_selected_group_state_key ( params . provider . web_mode ) ,
4344 params . group_name
4445 )
4546 }
@@ -210,10 +211,8 @@ async function show_preset_quick_pick(
210211 context : vscode . ExtensionContext ,
211212 mode : string
212213) : Promise < string [ ] > {
213- const LAST_SELECTED_PRESET_KEY = `last-selected-preset-${ mode } `
214-
215214 const last_selected_item = context . workspaceState . get < string | undefined > (
216- LAST_SELECTED_PRESET_KEY ,
215+ get_last_selected_preset_key ( mode ) ,
217216 undefined
218217 )
219218
@@ -277,7 +276,7 @@ async function show_preset_quick_pick(
277276
278277 if ( selected && selected . name !== undefined ) {
279278 const selected_name = selected . name
280- context . workspaceState . update ( LAST_SELECTED_PRESET_KEY , selected_name )
279+ context . workspaceState . update ( get_last_selected_preset_key ( mode ) , selected_name )
281280 resolve ( [ selected_name ] )
282281 } else {
283282 resolve ( [ ] )
@@ -302,9 +301,14 @@ async function resolve_presets(params: {
302301 show_quick_pick ?: boolean
303302 context : vscode . ExtensionContext
304303} ) : Promise < string [ ] > {
305- const LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY = `last-group-or-preset-choice-${ params . provider . web_mode } `
306- const LAST_SELECTED_PRESET_KEY = `last-selected-preset-${ params . provider . web_mode } `
307- const LAST_SELECTED_GROUP_STATE_KEY = `last-selected-group-${ params . provider . web_mode } `
304+ const last_group_or_preset_choice_state_key =
305+ get_last_group_or_preset_choice_state_key ( params . provider . web_mode )
306+ const last_selected_preset_key = get_last_selected_preset_key (
307+ params . provider . web_mode
308+ )
309+ const last_selected_group_state_key = get_last_selected_group_state_key (
310+ params . provider . web_mode
311+ )
308312
309313 const PRESET = 'Preset'
310314 const GROUP = 'Group'
@@ -381,12 +385,12 @@ async function resolve_presets(params: {
381385 if ( params . preset_name === undefined && params . group_name === undefined ) {
382386 // Try to use last selection if "Send" button is clicked without specific preset/group
383387 const last_choice = params . context . workspaceState . get < string > (
384- LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY
388+ last_group_or_preset_choice_state_key
385389 )
386390
387391 if ( last_choice == PRESET ) {
388392 const last_preset = params . context . workspaceState . get < string > (
389- LAST_SELECTED_PRESET_KEY
393+ last_selected_preset_key
390394 )
391395 if (
392396 last_preset !== undefined &&
@@ -396,7 +400,7 @@ async function resolve_presets(params: {
396400 }
397401 } else if ( last_choice == GROUP ) {
398402 const last_group = params . context . workspaceState . get < string > (
399- LAST_SELECTED_GROUP_STATE_KEY
403+ last_selected_group_state_key
400404 )
401405 if ( last_group ) {
402406 if ( last_group == 'Ungrouped' ) {
@@ -431,12 +435,12 @@ async function resolve_presets(params: {
431435 }
432436 } else {
433437 const last_choice = params . context . workspaceState . get < string > (
434- LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY
438+ last_group_or_preset_choice_state_key
435439 )
436440
437441 if ( last_choice == PRESET ) {
438442 const last_preset = params . context . workspaceState . get < string > (
439- LAST_SELECTED_PRESET_KEY
443+ last_selected_preset_key
440444 )
441445 if (
442446 last_preset !== undefined &&
@@ -446,7 +450,7 @@ async function resolve_presets(params: {
446450 }
447451 } else if ( last_choice == GROUP ) {
448452 const last_group = params . context . workspaceState . get < string > (
449- LAST_SELECTED_GROUP_STATE_KEY
453+ last_selected_group_state_key
450454 )
451455 if ( last_group ) {
452456 if ( last_group == 'Ungrouped' ) {
@@ -497,7 +501,7 @@ async function resolve_presets(params: {
497501 quick_pick . items = items
498502 quick_pick . placeholder = 'Select what to initialize'
499503 const last_choice = params . context . workspaceState . get < string > (
500- LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY
504+ last_group_or_preset_choice_state_key
501505 )
502506 if ( last_choice ) {
503507 const last_item = items . find ( ( item ) => item . label == last_choice )
@@ -522,7 +526,7 @@ async function resolve_presets(params: {
522526 }
523527
524528 params . context . workspaceState . update (
525- LAST_GROUP_OR_PRESET_CHOICE_STATE_KEY ,
529+ last_group_or_preset_choice_state_key ,
526530 choice
527531 )
528532
@@ -583,7 +587,7 @@ async function resolve_presets(params: {
583587 quick_pick . placeholder = 'Select a group'
584588
585589 const last_selected_group = params . context . workspaceState . get < string > (
586- LAST_SELECTED_GROUP_STATE_KEY ,
590+ last_selected_group_state_key ,
587591 ''
588592 )
589593 if ( last_selected_group ) {
@@ -609,7 +613,7 @@ async function resolve_presets(params: {
609613
610614 const group_name = selected . name
611615 params . context . workspaceState . update (
612- LAST_SELECTED_GROUP_STATE_KEY ,
616+ last_selected_group_state_key ,
613617 group_name
614618 )
615619
0 commit comments