Skip to content

Commit 26adab5

Browse files
committed
Replace is_in_code_completions_mode with prompt_type and add prune_context_instructions prop across components
1 parent b634e84 commit 26adab5

4 files changed

Lines changed: 44 additions & 26 deletions

File tree

‎packages/ui/src/components/editor/panel/PromptField/PromptField.stories.tsx‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Empty = () => (
1313
on_submit={() => console.log('Submitted')}
1414
on_copy={() => console.log('Copied')}
1515
is_connected={true}
16-
is_in_code_completions_mode={false}
16+
prompt_type="edit-context"
1717
current_selection=""
1818
currently_open_file_path="/path/to/file"
1919
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -28,6 +28,7 @@ export const Empty = () => (
2828
on_invocation_count_change={(count) =>
2929
console.log('Invocation count changed:', count)
3030
}
31+
prune_context_instructions=""
3132
/>
3233
)
3334

@@ -39,7 +40,7 @@ export const WithText = () => (
3940
on_submit={() => console.log('Submitted')}
4041
on_copy={() => console.log('Copied')}
4142
is_connected={true}
42-
is_in_code_completions_mode={false}
43+
prompt_type="edit-context"
4344
current_selection=""
4445
currently_open_file_path="/path/to/file"
4546
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -54,6 +55,7 @@ export const WithText = () => (
5455
on_invocation_count_change={(count) =>
5556
console.log('Invocation count changed:', count)
5657
}
58+
prune_context_instructions=""
5759
/>
5860
)
5961

@@ -65,7 +67,7 @@ export const LongText = () => (
6567
on_submit={() => console.log('Submitted')}
6668
on_copy={() => console.log('Copied')}
6769
is_connected={true}
68-
is_in_code_completions_mode={false}
70+
prompt_type="edit-context"
6971
current_selection=""
7072
currently_open_file_path="/path/to/file"
7173
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -80,6 +82,7 @@ export const LongText = () => (
8082
on_invocation_count_change={(count) =>
8183
console.log('Invocation count changed:', count)
8284
}
85+
prune_context_instructions=""
8386
/>
8487
)
8588

@@ -91,7 +94,7 @@ export const WithPlaceholderSavedContext = () => (
9194
on_submit={() => console.log('Submitted')}
9295
on_copy={() => console.log('Copied')}
9396
is_connected={true}
94-
is_in_code_completions_mode={false}
97+
prompt_type="edit-context"
9598
current_selection=""
9699
currently_open_file_path="/path/to/file"
97100
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -106,6 +109,7 @@ export const WithPlaceholderSavedContext = () => (
106109
console.log('Invocation count changed:', count)
107110
}
108111
on_curly_braces_click={() => {}}
112+
prune_context_instructions=""
109113
/>
110114
)
111115

@@ -117,7 +121,7 @@ export const WithPlaceholderSelection = () => (
117121
on_submit={() => console.log('Submitted')}
118122
on_copy={() => console.log('Copied')}
119123
is_connected={true}
120-
is_in_code_completions_mode={false}
124+
prompt_type="edit-context"
121125
current_selection="Selected text content"
122126
currently_open_file_path="/path/to/file"
123127
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -132,6 +136,7 @@ export const WithPlaceholderSelection = () => (
132136
console.log('Invocation count changed:', count)
133137
}
134138
on_curly_braces_click={() => {}}
139+
prune_context_instructions=""
135140
/>
136141
)
137142

@@ -143,7 +148,7 @@ export const WithCommit = () => (
143148
on_submit={() => console.log('Submitted')}
144149
on_copy={() => console.log('Copied')}
145150
is_connected={true}
146-
is_in_code_completions_mode={false}
151+
prompt_type="edit-context"
147152
current_selection=""
148153
currently_open_file_path="/path/to/file"
149154
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -158,6 +163,7 @@ export const WithCommit = () => (
158163
console.log('Invocation count changed:', count)
159164
}
160165
on_curly_braces_click={() => {}}
166+
prune_context_instructions=""
161167
/>
162168
)
163169

@@ -169,7 +175,7 @@ export const WithCommitWithQuotes = () => (
169175
on_submit={() => console.log('Submitted')}
170176
on_copy={() => console.log('Copied')}
171177
is_connected={true}
172-
is_in_code_completions_mode={false}
178+
prompt_type="edit-context"
173179
current_selection=""
174180
currently_open_file_path="/path/to/file"
175181
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -184,6 +190,7 @@ export const WithCommitWithQuotes = () => (
184190
console.log('Invocation count changed:', count)
185191
}
186192
on_curly_braces_click={() => {}}
193+
prune_context_instructions=""
187194
/>
188195
)
189196
export const WithContextAtCommit = () => (
@@ -194,7 +201,7 @@ export const WithContextAtCommit = () => (
194201
on_submit={() => console.log('Submitted')}
195202
on_copy={() => console.log('Copied')}
196203
is_connected={true}
197-
is_in_code_completions_mode={false}
204+
prompt_type="edit-context"
198205
current_selection=""
199206
currently_open_file_path="/path/to/file"
200207
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -209,6 +216,7 @@ export const WithContextAtCommit = () => (
209216
console.log('Invocation count changed:', count)
210217
}
211218
on_curly_braces_click={() => {}}
219+
prune_context_instructions=""
212220
/>
213221
)
214222

@@ -222,7 +230,7 @@ export const WithEditFormatSelector = () => {
222230
on_submit={() => console.log('Submitted')}
223231
on_copy={() => console.log('Copied')}
224232
is_connected={true}
225-
is_in_code_completions_mode={false}
233+
prompt_type="edit-context"
226234
current_selection=""
227235
currently_open_file_path="/path/to/file"
228236
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -238,6 +246,7 @@ export const WithEditFormatSelector = () => {
238246
context_file_paths={[]}
239247
invocation_count={1}
240248
on_invocation_count_change={set_edit_format as any} // Mocking for demo
249+
prune_context_instructions=""
241250
/>
242251
)
243252
}
@@ -250,7 +259,7 @@ export const WithFilePaths = () => (
250259
on_submit={() => console.log('Submitted')}
251260
on_copy={() => console.log('Copied')}
252261
is_connected={true}
253-
is_in_code_completions_mode={false}
262+
prompt_type="edit-context"
254263
current_selection=""
255264
currently_open_file_path="/path/to/file"
256265
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
@@ -266,5 +275,6 @@ export const WithFilePaths = () => (
266275
on_invocation_count_change={(count) =>
267276
console.log('Invocation count changed:', count)
268277
}
278+
prune_context_instructions=""
269279
/>
270280
)

‎packages/ui/src/components/editor/panel/PromptField/PromptField.tsx‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
map_raw_pos_to_display_pos
2121
} from './utils/position-mapping'
2222
import { Tooltip } from './components'
23+
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
2324

2425
export type EditFormat = 'whole' | 'truncated' | 'diff' | 'before-after'
2526

@@ -31,7 +32,7 @@ export type PromptFieldProps = {
3132
on_submit_with_control: () => void
3233
on_copy: () => void
3334
is_connected: boolean
34-
is_in_code_completions_mode: boolean
35+
prompt_type: WebPromptType | ApiPromptType
3536
current_selection: string
3637
on_caret_position_change: (caret_position: number) => void
3738
is_web_mode: boolean
@@ -54,6 +55,7 @@ export type PromptFieldProps = {
5455
invocation_count: number
5556
on_invocation_count_change: (count: number) => void
5657
on_go_to_file?: (file_path: string) => void
58+
prune_context_instructions: string
5759
}
5860

5961
export const PromptField: React.FC<PromptFieldProps> = (props) => {
@@ -155,7 +157,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
155157
})
156158
}, [
157159
props.value,
158-
props.is_in_code_completions_mode,
160+
props.prompt_type,
159161
props.current_selection,
160162
props.context_file_paths
161163
])
@@ -251,7 +253,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
251253
}, [props.on_caret_position_change, props.value, props.context_file_paths])
252254

253255
const placeholder = useMemo(() => {
254-
if (props.is_in_code_completions_mode) {
256+
if (props.prompt_type == 'code-at-cursor') {
255257
if (props.chat_history.length > 0 && is_history_enabled) {
256258
return 'Completion instructions (⇅ for history)'
257259
} else {
@@ -262,11 +264,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
262264
return props.chat_history.length > 0 && is_history_enabled
263265
? 'Type something (⇅ for history)'
264266
: 'Type something'
265-
}, [
266-
props.is_in_code_completions_mode,
267-
props.chat_history,
268-
is_history_enabled
269-
])
267+
}, [props.prompt_type, props.chat_history, is_history_enabled])
270268

271269
const edit_format_shortcuts: Record<EditFormat, string> = useMemo(() => {
272270
const modifier = is_mac ? '⌥' : 'Alt+'
@@ -289,22 +287,25 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
289287

290288
return (
291289
<div className={styles.container}>
292-
{!!props.current_selection && props.is_in_code_completions_mode && (
290+
{!!props.current_selection && props.prompt_type == 'code-at-cursor' && (
293291
<div className={styles.error}>
294292
<div className={styles.error__inner}>Remove text selection</div>
295293
</div>
296294
)}
297295

298-
{props.is_in_code_completions_mode && !props.currently_open_file_path && (
299-
<div className={styles.error}>
300-
<div className={styles.error__inner}>Place cursor for completion</div>
301-
</div>
302-
)}
296+
{props.prompt_type == 'code-at-cursor' &&
297+
!props.currently_open_file_path && (
298+
<div className={styles.error}>
299+
<div className={styles.error__inner}>
300+
Place cursor for completion
301+
</div>
302+
</div>
303+
)}
303304

304305
<div
305306
className={cn(styles.container__inner, {
306307
[styles['container__inner--disabled']]:
307-
props.is_in_code_completions_mode &&
308+
props.prompt_type == 'code-at-cursor' &&
308309
(!!props.current_selection || !props.currently_open_file_path),
309310
[styles['container__inner--selecting']]: is_text_selecting
310311
})}

‎packages/vscode/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ export const Main: React.FC<Props> = (props) => {
807807
on_go_to_file={handle_go_to_file}
808808
currently_open_file_text={props.currently_open_file_text}
809809
are_keyboard_shortcuts_disabled={props.are_keyboard_shortcuts_disabled}
810+
prune_context_instructions={props.prune_context_instructions}
810811
/>
811812
)
812813
}

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ type Props = {
9595
currently_open_file_text?: string
9696
on_go_to_file: (file_path: string) => void
9797
are_keyboard_shortcuts_disabled: boolean
98+
prune_context_instructions: string
9899
}
99100

100101
export const MainView: React.FC<Props> = (props) => {
@@ -219,7 +220,11 @@ export const MainView: React.FC<Props> = (props) => {
219220
on_curly_braces_click={props.on_curly_braces_click}
220221
is_web_mode={props.mode == MODE.WEB}
221222
is_connected={props.is_connected}
222-
is_in_code_completions_mode={is_in_code_completions_prompt_type}
223+
prompt_type={
224+
props.mode == MODE.WEB
225+
? props.web_prompt_type
226+
: props.api_prompt_type
227+
}
223228
current_selection={props.current_selection}
224229
send_with_shift_enter={props.send_with_shift_enter}
225230
currently_open_file_path={props.currently_open_file_path}
@@ -245,6 +250,7 @@ export const MainView: React.FC<Props> = (props) => {
245250
currently_open_file_text={props.currently_open_file_text}
246251
invocation_count={current_invocation_count}
247252
on_invocation_count_change={handle_invocation_count_change}
253+
prune_context_instructions={props.prune_context_instructions}
248254
/>
249255
<UiContextUtilisation
250256
current_context_size={props.token_count}

0 commit comments

Comments
 (0)