Skip to content

Commit 3ca969b

Browse files
committed
Refactor context size warning threshold to use a default constant and support undefined values
1 parent 1701765 commit 3ca969b

9 files changed

Lines changed: 61 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<a href="https://marketplace.visualstudio.com/items?itemName=robertpiosik.gemini-coder"><img src="https://img.shields.io/badge/Install-VS_Code_Marketplace-blue" alt="Get from Visual Studio Code Marketplace" /></a> <a href="https://open-vsx.org/extension/robertpiosik/gemini-coder"><img src="https://img.shields.io/badge/Install-Open_VSX_Registry-a60ee5" alt="Get from Open VSX Registry" /></a> <a href="https://github.com/robertpiosik/CodeWebChat/blob/dev/LICENSE"><img src="https://img.shields.io/badge/License-GPL--3.0-green.svg" alt="GPL-3.0 license" /></a>
1313
</p>
1414

15-
Code Web Chat is a free and open-source AI coding toolkit. You can use CWC in **VS Code** family of editors (Cursor, Antigravity, VSCodium etc.) for a **fast and cost efficient\*** development experience.
15+
Code Web Chat is a free and open-source AI coding toolkit. You can use CWC in **VS Code** family of editors (Cursor, Antigravity, VSCodium etc.) for a **fast and cost efficient** AI-assisted development experience.
1616

1717
✍️ **Construct coding prompts for...**
1818

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const CHECKPOINT_DEFAULT_LIFESPAN = 24
2+
export const DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD = 60000

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import {
6565
handle_commit_changes,
6666
handle_accept_commit_message,
6767
handle_cancel_commit_message,
68-
handle_hash_sign_quick_pick,
6968
handle_proceed_with_commit,
7069
handle_get_collapsed_states,
7170
handle_manage_configurations,
@@ -83,7 +82,8 @@ import {
8382
handle_get_prune_context_instructions_prefix,
8483
handle_save_prune_context_instructions_prefix,
8584
handle_open_file_and_select,
86-
handle_open_external_url
85+
handle_open_external_url,
86+
handle_hash_sign_quick_pick
8787
} from './message-handlers'
8888
import { SelectionState } from '../types/messages'
8989
import {
@@ -113,6 +113,7 @@ import { ResponseHistoryItem } from '@shared/types/response-history-item'
113113
import { CancelTokenSource } from 'axios'
114114
import { update_last_used_preset_or_group } from './message-handlers/update-last-used-preset-or-group'
115115
import { dictionary } from '@shared/constants/dictionary'
116+
import { DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD } from '@/constants/values'
116117

117118
export class PanelProvider implements vscode.WebviewViewProvider {
118119
private _webview_view: vscode.WebviewView | undefined
@@ -859,7 +860,10 @@ export class PanelProvider implements vscode.WebviewViewProvider {
859860
private _send_context_size_warning_threshold() {
860861
if (!this._webview_view) return
861862
const config = vscode.workspace.getConfiguration('codeWebChat')
862-
const threshold = config.get<number>('contextSizeWarningThreshold', 60000)
863+
const threshold = config.get<number>(
864+
'contextSizeWarningThreshold',
865+
DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD
866+
)
863867
this.send_message({
864868
command: 'CONTEXT_SIZE_WARNING_THRESHOLD',
865869
threshold

‎apps/editor/src/views/settings/backend/message-handlers/handle-get-context-size-warning-threshold.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as vscode from 'vscode'
22
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
import { DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD } from '@/constants/values'
34

45
export const handle_get_context_size_warning_threshold = async (
56
provider: SettingsProvider
67
): Promise<void> => {
78
const config = vscode.workspace.getConfiguration('codeWebChat')
8-
const threshold = config.get<number>('contextSizeWarningThreshold', 60000)
9+
const threshold = config.get<number>(
10+
'contextSizeWarningThreshold',
11+
DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD
12+
)
913
provider.postMessage({
1014
command: 'CONTEXT_SIZE_WARNING_THRESHOLD',
1115
threshold

‎apps/editor/src/views/settings/backend/message-handlers/handle-update-context-size-warning-threshold.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const handle_update_context_size_warning_threshold = async (
1010
.getConfiguration('codeWebChat')
1111
.update(
1212
'contextSizeWarningThreshold',
13-
message.threshold,
13+
message.threshold ?? undefined,
1414
vscode.ConfigurationTarget.Global
1515
)
1616
}

‎apps/editor/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ type Props = {
9393
set_intelligent_update_configs: (configs: ConfigurationForClient[]) => void
9494
set_prune_context_configs: (configs: ConfigurationForClient[]) => void
9595
set_commit_messages_configs: (configs: ConfigurationForClient[]) => void
96-
on_context_size_warning_threshold_change: (threshold: number) => void
96+
on_context_size_warning_threshold_change: (
97+
threshold: number | undefined
98+
) => void
9799
on_commit_instructions_change: (instructions: string) => void
98100
on_commit_message_auto_accept_after_change: (seconds: number | null) => void
99101
on_edit_format_instructions_change: (

‎apps/editor/src/views/settings/frontend/Home/sections/GeneralSection.tsx‎

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { Section } from '@ui/components/editor/settings/Section'
88
import { TextButton } from '@ui/components/editor/settings/TextButton'
99
import { Textarea } from '@ui/components/editor/common/Textarea'
1010
import { EditFormatInstructions } from '@/views/settings/types/messages'
11+
import {
12+
CHECKPOINT_DEFAULT_LIFESPAN,
13+
DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD
14+
} from '@/constants/values'
1115

1216
type ClearChecksBehavior = 'ignore-open-editors' | 'uncheck-all'
1317

@@ -32,7 +36,9 @@ type Props = {
3236
on_checkpoint_lifespan_change: (hours: number | undefined) => void
3337
clear_checks_in_workspace_behavior: ClearChecksBehavior
3438
edit_format_instructions: EditFormatInstructions
35-
on_context_size_warning_threshold_change: (threshold: number) => void
39+
on_context_size_warning_threshold_change: (
40+
threshold: number | undefined
41+
) => void
3642
on_clear_checks_in_workspace_behavior_change: (
3743
value: ClearChecksBehavior
3844
) => void
@@ -48,8 +54,8 @@ type Props = {
4854
export const GeneralSection = forwardRef<HTMLDivElement, Props>(
4955
(props, ref) => {
5056
const [context_size_warning_threshold, set_context_size_warning_threshold] =
51-
useState('')
52-
const [checkpoint_lifespan_str, set_checkpoint_lifespan_str] = useState('')
57+
useState<number>()
58+
const [checkpoint_lifespan, set_checkpoint_lifespan] = useState<number>()
5359
const [gemini_user_id_str, set_gemini_user_id_str] = useState('')
5460
const [ai_studio_user_id_str, set_ai_studio_user_id_str] = useState('')
5561
const [instructions, set_instructions] = useState<EditFormatInstructions>({
@@ -66,13 +72,11 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
6672
})
6773

6874
useEffect(() => {
69-
set_context_size_warning_threshold(
70-
String(props.context_size_warning_threshold)
71-
)
75+
set_context_size_warning_threshold(props.context_size_warning_threshold)
7276
}, [props.context_size_warning_threshold])
7377

7478
useEffect(() => {
75-
set_checkpoint_lifespan_str(String(props.checkpoint_lifespan))
79+
set_checkpoint_lifespan(props.checkpoint_lifespan)
7680
}, [props.checkpoint_lifespan])
7781

7882
useEffect(() => {
@@ -99,18 +103,27 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
99103
}, [props.edit_format_instructions])
100104

101105
const handle_context_size_warning_threshold_blur = () => {
102-
const num_threshold = parseInt(context_size_warning_threshold, 10)
103-
if (!isNaN(num_threshold) && num_threshold >= 0) {
104-
props.on_context_size_warning_threshold_change(num_threshold)
106+
if (
107+
context_size_warning_threshold &&
108+
context_size_warning_threshold > 0
109+
) {
110+
props.on_context_size_warning_threshold_change(
111+
context_size_warning_threshold
112+
)
113+
} else {
114+
props.on_context_size_warning_threshold_change(undefined)
115+
set_context_size_warning_threshold(
116+
DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD
117+
)
105118
}
106119
}
107120

108121
const handle_checkpoint_lifespan_blur = () => {
109-
const num_hours = parseInt(checkpoint_lifespan_str, 10)
110-
if (!isNaN(num_hours) && num_hours > 0) {
111-
props.on_checkpoint_lifespan_change(num_hours)
122+
if (checkpoint_lifespan && checkpoint_lifespan > 0) {
123+
props.on_checkpoint_lifespan_change(checkpoint_lifespan)
112124
} else {
113125
props.on_checkpoint_lifespan_change(undefined)
126+
set_checkpoint_lifespan(CHECKPOINT_DEFAULT_LIFESPAN)
114127
}
115128
}
116129

@@ -181,8 +194,12 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
181194
slot_right={
182195
<Input
183196
type="number"
184-
value={context_size_warning_threshold}
185-
on_change={set_context_size_warning_threshold}
197+
value={context_size_warning_threshold?.toString() ?? ''}
198+
on_change={(val) =>
199+
set_context_size_warning_threshold(
200+
val == '' ? undefined : parseInt(val, 10)
201+
)
202+
}
186203
on_blur={handle_context_size_warning_threshold_blur}
187204
max_width={100}
188205
/>
@@ -239,8 +256,12 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
239256
slot_right={
240257
<Input
241258
type="number"
242-
value={checkpoint_lifespan_str}
243-
on_change={set_checkpoint_lifespan_str}
259+
value={checkpoint_lifespan?.toString() || ''}
260+
on_change={(val) =>
261+
set_checkpoint_lifespan(
262+
val == '' ? undefined : parseInt(val, 10)
263+
)
264+
}
244265
on_blur={handle_checkpoint_lifespan_blur}
245266
max_width={100}
246267
/>

‎apps/editor/src/views/settings/frontend/hooks/use-settings.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,12 @@ export const use_settings = (vscode: any) => {
276276
const handle_open_allow_patterns_settings = () =>
277277
post_message(vscode, { command: 'OPEN_ALLOW_PATTERNS_SETTINGS' })
278278

279-
const handle_context_size_warning_threshold_change = (threshold: number) =>
279+
const handle_context_size_warning_threshold_change = (
280+
threshold: number | undefined
281+
) =>
280282
post_message(vscode, {
281283
command: 'UPDATE_CONTEXT_SIZE_WARNING_THRESHOLD',
282-
threshold
284+
threshold: threshold ?? null
283285
})
284286

285287
const handle_edit_format_instructions_change = (

‎apps/editor/src/views/settings/types/messages.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export interface GetContextSizeWarningThresholdMessage {
200200

201201
export interface UpdateContextSizeWarningThresholdMessage {
202202
command: 'UPDATE_CONTEXT_SIZE_WARNING_THRESHOLD'
203-
threshold: number
203+
threshold: number | null
204204
}
205205

206206
export interface GetAreAutomaticCheckpointsDisabledMessage {

0 commit comments

Comments
 (0)