Skip to content

Commit c8bd2ea

Browse files
committed
Consolidate chat and api edit format configurations into a unified edit format setting
- unify chat/api edit format selection as we don't need to have different values for each mode
1 parent a27dcfd commit c8bd2ea

13 files changed

Lines changed: 56 additions & 160 deletions

‎apps/editor/src/commands/duplicate-workspace-command.ts‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as vscode from 'vscode'
22
import { WorkspaceProvider } from '../context/providers/workspace/workspace-provider'
33
import {
4-
API_EDIT_FORMAT_STATE_KEY,
5-
CHAT_EDIT_FORMAT_STATE_KEY,
4+
EDIT_FORMAT_STATE_KEY,
65
DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY,
76
RANGES_STATE_KEY,
87
type DuplicateWorkspaceContext
@@ -52,23 +51,13 @@ export const duplicate_workspace_command = (
5251
ranges
5352
}
5453

55-
const api_edit_format = extension_context.workspaceState.get(
56-
API_EDIT_FORMAT_STATE_KEY
54+
const edit_format = extension_context.workspaceState.get(
55+
EDIT_FORMAT_STATE_KEY
5756
)
58-
if (api_edit_format) {
57+
if (edit_format) {
5958
await extension_context.globalState.update(
60-
API_EDIT_FORMAT_STATE_KEY,
61-
api_edit_format
62-
)
63-
}
64-
65-
const chat_edit_format = extension_context.workspaceState.get(
66-
CHAT_EDIT_FORMAT_STATE_KEY
67-
)
68-
if (chat_edit_format) {
69-
await extension_context.globalState.update(
70-
CHAT_EDIT_FORMAT_STATE_KEY,
71-
chat_edit_format
59+
EDIT_FORMAT_STATE_KEY,
60+
edit_format
7261
)
7362
}
7463

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export const CHATS_VIEW_CHAT_HISTORY_STATE_KEY = 'chats-view-chat-history'
3333
export const DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY =
3434
'duplicate-workspace-context'
3535

36-
export const CHAT_EDIT_FORMAT_STATE_KEY = 'chat-edit-format'
37-
export const API_EDIT_FORMAT_STATE_KEY = 'api-edit-format'
36+
export const EDIT_FORMAT_STATE_KEY = 'edit-format'
3837
export const WEB_MODE_STATE_KEY = 'web-mode'
3938
export const API_MODE_STATE_KEY = 'api-mode'
4039
export const PANEL_MODE_STATE_KEY = 'panel-mode'

‎apps/editor/src/views/panel/backend/message-handlers/handle-autofill.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ export const handle_autofill = async (params: {
171171
truncated: 'editFormatInstructionsTruncated',
172172
'search-replace': 'editFormatInstructionsSearchReplace',
173173
diff: 'editFormatInstructionsDiff'
174-
}[params.panel_view_provider.chat_edit_format]
174+
}[params.panel_view_provider.edit_format]
175175
const default_instructions = {
176176
whole: EDIT_FORMAT_INSTRUCTIONS_WHOLE,
177177
truncated: EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
178178
'search-replace': EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE,
179179
diff: EDIT_FORMAT_INSTRUCTIONS_DIFF
180-
}[params.panel_view_provider.chat_edit_format]
180+
}[params.panel_view_provider.edit_format]
181181
const edit_format_instructions =
182182
config.get<string>(instructions_key) || default_instructions
183183
if (edit_format_instructions) {

‎apps/editor/src/views/panel/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ export const handle_copy_prompt = async (params: {
128128
let user_instructions = processed_instructions
129129

130130
if (params.panel_view_provider.web_prompt_type == 'edit-files') {
131-
const edit_format =
132-
params.panel_view_provider.mode == MODE.WEB
133-
? params.panel_view_provider.chat_edit_format
134-
: params.panel_view_provider.api_edit_format
131+
const edit_format = params.panel_view_provider.edit_format
135132
const config = vscode.workspace.getConfiguration('codeWebChat')
136133
const instructions_key = {
137134
whole: 'editFormatInstructionsWhole',

‎apps/editor/src/views/panel/backend/message-handlers/handle-get-edit-format.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const handle_get_edit_format = (
55
) => {
66
panel_view_provider.send_message({
77
command: 'EDIT_FORMAT',
8-
chat_edit_format: panel_view_provider.chat_edit_format,
9-
api_edit_format: panel_view_provider.api_edit_format
8+
edit_format: panel_view_provider.edit_format
109
})
1110
}

‎apps/editor/src/views/panel/backend/message-handlers/handle-make-api-call.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '@/services/model-providers-manager'
1010
import axios from 'axios'
1111
import {
12-
API_EDIT_FORMAT_STATE_KEY,
1312
LAST_USED_EDIT_FILES_CONFIG_ID_STATE_KEY,
1413
LAST_USED_CODE_AT_CURSOR_CONFIG_ID_STATE_KEY,
1514
LAST_USED_FIND_RELEVANT_FILES_CONFIG_ID_STATE_KEY,
@@ -305,14 +304,7 @@ export const handle_make_api_call = async (
305304
let user_content = ''
306305

307306
if (prompt_type == 'edit-files') {
308-
edit_format =
309-
panel_view_provider.extension_context.workspaceState.get<EditFormat>(
310-
API_EDIT_FORMAT_STATE_KEY
311-
) ??
312-
panel_view_provider.extension_context.globalState.get<EditFormat>(
313-
API_EDIT_FORMAT_STATE_KEY
314-
) ??
315-
'whole'
307+
edit_format = panel_view_provider.edit_format
316308
const config = vscode.workspace.getConfiguration('codeWebChat')
317309
const instructions_key = {
318310
whole: 'editFormatInstructionsWhole',

‎apps/editor/src/views/panel/backend/message-handlers/handle-preview-web-configuration.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ export const handle_preview_web_configuration = async (
120120
truncated: 'editFormatInstructionsTruncated',
121121
'search-replace': 'editFormatInstructionsSearchReplace',
122122
diff: 'editFormatInstructionsDiff'
123-
}[panel_view_provider.chat_edit_format]
123+
}[panel_view_provider.edit_format]
124124
const default_instructions = {
125125
whole: EDIT_FORMAT_INSTRUCTIONS_WHOLE,
126126
truncated: EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
127127
'search-replace': EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE,
128128
diff: EDIT_FORMAT_INSTRUCTIONS_DIFF
129-
}[panel_view_provider.chat_edit_format]
129+
}[panel_view_provider.edit_format]
130130
const edit_format_instructions =
131131
config.get<string>(instructions_key) || default_instructions
132132
if (edit_format_instructions) {
Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
1-
import {
2-
API_EDIT_FORMAT_STATE_KEY,
3-
CHAT_EDIT_FORMAT_STATE_KEY
4-
} from '@/constants/state-keys'
1+
import { EDIT_FORMAT_STATE_KEY } from '@/constants/state-keys'
52
import { PanelViewProvider } from '@/views/panel/backend/panel-view-provider'
63
import { SaveEditFormatMessage } from '@/views/panel/types/messages'
74

85
export const handle_save_edit_format = async (
96
panel_view_provider: PanelViewProvider,
107
message: SaveEditFormatMessage
118
): Promise<void> => {
12-
if (message.target == 'chat') {
13-
panel_view_provider.chat_edit_format = message.edit_format
14-
await panel_view_provider.extension_context.workspaceState.update(
15-
CHAT_EDIT_FORMAT_STATE_KEY,
16-
message.edit_format
17-
)
18-
await panel_view_provider.extension_context.globalState.update(
19-
CHAT_EDIT_FORMAT_STATE_KEY,
20-
message.edit_format
21-
)
22-
} else if (message.target == 'api') {
23-
panel_view_provider.api_edit_format = message.edit_format
24-
await panel_view_provider.extension_context.workspaceState.update(
25-
API_EDIT_FORMAT_STATE_KEY,
26-
message.edit_format
27-
)
28-
await panel_view_provider.extension_context.globalState.update(
29-
API_EDIT_FORMAT_STATE_KEY,
30-
message.edit_format
31-
)
32-
}
9+
panel_view_provider.edit_format = message.edit_format
10+
await panel_view_provider.extension_context.workspaceState.update(
11+
EDIT_FORMAT_STATE_KEY,
12+
message.edit_format
13+
)
14+
await panel_view_provider.extension_context.globalState.update(
15+
EDIT_FORMAT_STATE_KEY,
16+
message.edit_format
17+
)
3318

3419
panel_view_provider.send_message({
3520
command: 'EDIT_FORMAT',
36-
chat_edit_format: panel_view_provider.chat_edit_format,
37-
api_edit_format: panel_view_provider.api_edit_format
21+
edit_format: panel_view_provider.edit_format
3822
})
3923
}

‎apps/editor/src/views/panel/backend/message-handlers/handle-select-edit-format.ts‎

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import * as vscode from 'vscode'
2-
import {
3-
API_EDIT_FORMAT_STATE_KEY,
4-
CHAT_EDIT_FORMAT_STATE_KEY
5-
} from '@/constants/state-keys'
2+
import { EDIT_FORMAT_STATE_KEY } from '@/constants/state-keys'
63
import { PanelViewProvider } from '@/views/panel/backend/panel-view-provider'
74
import { SelectEditFormatMessage } from '@/views/panel/types/messages'
85
import { EditFormat } from '@shared/types/edit-format'
96
import { t } from '@/i18n'
107

118
export const handle_select_edit_format = async (
129
panel_view_provider: PanelViewProvider,
13-
message: SelectEditFormatMessage
10+
_: SelectEditFormatMessage
1411
): Promise<void> => {
15-
const current_format =
16-
message.target == 'chat'
17-
? panel_view_provider.chat_edit_format
18-
: panel_view_provider.api_edit_format
12+
const current_format = panel_view_provider.edit_format
1913

2014
const items: (vscode.QuickPickItem & { value: EditFormat })[] = [
2115
{
@@ -82,31 +76,18 @@ export const handle_select_edit_format = async (
8276
return
8377
}
8478

85-
if (message.target == 'chat') {
86-
panel_view_provider.chat_edit_format = selection.value
87-
await panel_view_provider.extension_context.workspaceState.update(
88-
CHAT_EDIT_FORMAT_STATE_KEY,
89-
selection.value
90-
)
91-
await panel_view_provider.extension_context.globalState.update(
92-
CHAT_EDIT_FORMAT_STATE_KEY,
93-
selection.value
94-
)
95-
} else if (message.target == 'api') {
96-
panel_view_provider.api_edit_format = selection.value
97-
await panel_view_provider.extension_context.workspaceState.update(
98-
API_EDIT_FORMAT_STATE_KEY,
99-
selection.value
100-
)
101-
await panel_view_provider.extension_context.globalState.update(
102-
API_EDIT_FORMAT_STATE_KEY,
103-
selection.value
104-
)
105-
}
79+
panel_view_provider.edit_format = selection.value
80+
await panel_view_provider.extension_context.workspaceState.update(
81+
EDIT_FORMAT_STATE_KEY,
82+
selection.value
83+
)
84+
await panel_view_provider.extension_context.globalState.update(
85+
EDIT_FORMAT_STATE_KEY,
86+
selection.value
87+
)
10688

10789
panel_view_provider.send_message({
10890
command: 'EDIT_FORMAT',
109-
chat_edit_format: panel_view_provider.chat_edit_format,
110-
api_edit_format: panel_view_provider.api_edit_format
91+
edit_format: panel_view_provider.edit_format
11192
})
11293
}

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ import { handle_pick_api_reasoning_effort } from './message-handlers/handle-pick
9292
import { handle_select_edit_format } from './message-handlers/handle-select-edit-format'
9393
import { SelectionState } from '../types/messages'
9494
import {
95-
API_EDIT_FORMAT_STATE_KEY,
95+
EDIT_FORMAT_STATE_KEY,
9696
API_MODE_STATE_KEY,
97-
CHAT_EDIT_FORMAT_STATE_KEY,
9897
INSTRUCTIONS_ASK_STATE_KEY,
9998
INSTRUCTIONS_CODE_AT_CURSOR_STATE_KEY,
10099
INSTRUCTIONS_FIND_RELEVANT_FILES_STATE_KEY,
@@ -157,8 +156,7 @@ export class PanelViewProvider implements vscode.WebviewViewProvider {
157156
active_index: 0
158157
}
159158
public web_prompt_type: WebPromptType
160-
public chat_edit_format: EditFormat
161-
public api_edit_format: EditFormat
159+
public edit_format: EditFormat
162160
public api_prompt_type: ApiPromptType
163161
public mode: Mode = MODE.WEB
164162
public intelligent_update_abort_controllers: {
@@ -390,20 +388,12 @@ export class PanelViewProvider implements vscode.WebviewViewProvider {
390388
INSTRUCTIONS_FIND_RELEVANT_FILES_STATE_KEY
391389
)
392390

393-
this.chat_edit_format =
391+
this.edit_format =
394392
this.extension_context.workspaceState.get<EditFormat>(
395-
CHAT_EDIT_FORMAT_STATE_KEY
393+
EDIT_FORMAT_STATE_KEY
396394
) ??
397395
this.extension_context.globalState.get<EditFormat>(
398-
CHAT_EDIT_FORMAT_STATE_KEY
399-
) ??
400-
'whole'
401-
this.api_edit_format =
402-
this.extension_context.workspaceState.get<EditFormat>(
403-
API_EDIT_FORMAT_STATE_KEY
404-
) ??
405-
this.extension_context.globalState.get<EditFormat>(
406-
API_EDIT_FORMAT_STATE_KEY
396+
EDIT_FORMAT_STATE_KEY
407397
) ??
408398
'whole'
409399
this.mode =

0 commit comments

Comments
 (0)