Skip to content

Commit 5473c18

Browse files
committed
Refactor edit format persistence to utilize global state storage and standardized keys, ensuring proper fallback during retrieval
1 parent f27fb0a commit 5473c18

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎packages/vscode/src/views/panel/backend/message-handlers/handle-save-edit-format.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
API_EDIT_FORMAT_STATE_KEY,
3+
CHAT_EDIT_FORMAT_STATE_KEY
4+
} from '@/constants/state-keys'
15
import { ViewProvider } from '@/views/panel/backend/panel-provider'
26
import { SaveEditFormatMessage } from '@/views/panel/types/messages'
37

@@ -8,13 +12,21 @@ export const handle_save_edit_format = async (
812
if (message.target == 'chat') {
913
provider.chat_edit_format = message.edit_format
1014
await provider.context.workspaceState.update(
11-
'chat-edit-format',
15+
CHAT_EDIT_FORMAT_STATE_KEY,
16+
message.edit_format
17+
)
18+
await provider.context.globalState.update(
19+
CHAT_EDIT_FORMAT_STATE_KEY,
1220
message.edit_format
1321
)
1422
} else if (message.target == 'api') {
1523
provider.api_edit_format = message.edit_format
1624
await provider.context.workspaceState.update(
17-
'api-edit-format',
25+
API_EDIT_FORMAT_STATE_KEY,
26+
message.edit_format
27+
)
28+
await provider.context.globalState.update(
29+
API_EDIT_FORMAT_STATE_KEY,
1830
message.edit_format
1931
)
2032
}

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ export class ViewProvider implements vscode.WebviewViewProvider {
142142
''
143143
)
144144

145-
this.chat_edit_format = this.context.workspaceState.get<EditFormat>(
146-
CHAT_EDIT_FORMAT_STATE_KEY,
145+
this.chat_edit_format =
146+
this.context.workspaceState.get<EditFormat>(CHAT_EDIT_FORMAT_STATE_KEY) ??
147+
this.context.globalState.get<EditFormat>(CHAT_EDIT_FORMAT_STATE_KEY) ??
148+
'whole'
149+
this.api_edit_format =
150+
this.context.workspaceState.get<EditFormat>(API_EDIT_FORMAT_STATE_KEY) ??
151+
this.context.globalState.get<EditFormat>(API_EDIT_FORMAT_STATE_KEY) ??
147152
'whole'
148-
)
149-
this.api_edit_format = this.context.workspaceState.get<EditFormat>(
150-
API_EDIT_FORMAT_STATE_KEY,
151-
'diff'
152-
)
153153

154154
this.web_mode = this.context.workspaceState.get<WebMode>(
155155
WEB_MODE_STATE_KEY,

0 commit comments

Comments
 (0)