Skip to content

Commit 62b7de5

Browse files
committed
Refactor symbol insertion logic to separate file path references (@) from context symbols (#) in the chat input
1 parent 0bafd9d commit 62b7de5

16 files changed

Lines changed: 355 additions & 389 deletions

File tree

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.module.scss‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@
175175

176176
&__left {
177177
display: flex;
178-
gap: var(--padding-2px);
179-
overflow: hidden;
180178

181179
&__button {
182180
--size: 20px;
@@ -250,7 +248,7 @@
250248
}
251249

252250
&--secondary {
253-
@media (max-width: 330px) {
251+
@media (max-width: 360px) {
254252
> span {
255253
display: none;
256254
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export const Empty = () => (
1818
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
1919
is_web_mode={false}
2020
on_at_sign_click={() => console.log('@ clicked')}
21+
on_hash_sign_click={() => console.log('# clicked')}
2122
on_search_click={() => console.log('Search clicked')}
2223
on_submit_with_control={() => {}}
2324
on_curly_braces_click={() => {}}
24-
has_context={true}
2525
/>
2626
)
2727

@@ -40,10 +40,10 @@ export const WithText = () => (
4040
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
4141
is_web_mode={false}
4242
on_at_sign_click={() => console.log('@ clicked')}
43+
on_hash_sign_click={() => console.log('# clicked')}
4344
on_search_click={() => console.log('Search clicked')}
4445
on_submit_with_control={() => {}}
4546
on_curly_braces_click={() => {}}
46-
has_context={true}
4747
/>
4848
)
4949

@@ -62,10 +62,10 @@ export const LongText = () => (
6262
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
6363
is_web_mode={false}
6464
on_at_sign_click={() => console.log('@ clicked')}
65+
on_hash_sign_click={() => console.log('# clicked')}
6566
on_search_click={() => console.log('Search clicked')}
6667
on_submit_with_control={() => {}}
6768
on_curly_braces_click={() => {}}
68-
has_context={true}
6969
/>
7070
)
7171

@@ -83,10 +83,10 @@ export const WithPlaceholderSavedContext = () => (
8383
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
8484
on_search_click={() => console.log('Search clicked')}
8585
on_at_sign_click={() => console.log('@ clicked')}
86+
on_hash_sign_click={() => console.log('# clicked')}
8687
is_web_mode={false}
8788
on_submit_with_control={() => {}}
8889
on_curly_braces_click={() => {}}
89-
has_context={true}
9090
/>
9191
)
9292

@@ -104,9 +104,9 @@ export const WithPlaceholderSelection = () => (
104104
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
105105
on_search_click={() => console.log('Search clicked')}
106106
on_at_sign_click={() => console.log('@ clicked')}
107+
on_hash_sign_click={() => console.log('# clicked')}
107108
is_web_mode={false}
108109
on_submit_with_control={() => {}}
109110
on_curly_braces_click={() => {}}
110-
has_context={true}
111111
/>
112112
)

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export type ChatInputProps = {
2323
is_web_mode: boolean
2424
on_search_click: () => void
2525
on_at_sign_click: () => void
26+
on_hash_sign_click: () => void
2627
on_curly_braces_click: () => void
27-
has_context: boolean
2828
caret_position_to_set?: number
2929
on_caret_position_set?: () => void
3030
focus_key?: number
@@ -130,14 +130,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
130130
}}
131131
ref={container_ref}
132132
>
133-
<div
134-
className={styles['highlight-container']}
135-
ref={highlight_ref}
136-
onClick={() => {
137-
if (props.value.includes('#Selection') && props.on_at_sign_click)
138-
props.on_at_sign_click()
139-
}}
140-
>
133+
<div className={styles['highlight-container']} ref={highlight_ref}>
141134
{get_highlighted_text({
142135
text: props.value,
143136
is_in_code_completions_mode: props.is_in_code_completions_mode,
@@ -204,14 +197,20 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
204197
e.stopPropagation()
205198
}}
206199
>
207-
{/* TODO: Should be always visible but we need to handle including saved contexts first */}
200+
<button
201+
onClick={props.on_at_sign_click}
202+
className={cn(styles['footer__left__button'])}
203+
title="Reference file"
204+
>
205+
<span>@</span>
206+
</button>
208207
{!props.is_in_code_completions_mode && (
209208
<button
210-
onClick={props.on_at_sign_click}
209+
onClick={props.on_hash_sign_click}
211210
className={cn(styles['footer__left__button'])}
212211
title="Insert symbol"
213212
>
214-
<span>@</span>
213+
<span>#</span>
215214
</button>
216215
)}
217216
<button

‎packages/ui/src/components/editor/panel/ChatInput/hooks/use-handlers.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const use_handlers = (props: ChatInputProps) => {
2222
setTimeout(() => {
2323
props.on_at_sign_click()
2424
}, 150)
25+
} else if (new_value.charAt(caret_position - 1) == '#') {
26+
setTimeout(() => {
27+
props.on_hash_sign_click()
28+
}, 150)
2529
}
2630

2731
if (!new_value) {

‎packages/vscode/src/views/panel/backend/message-handlers/handle-at-sign-quick-pick-for-preset-affix.ts‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎packages/vscode/src/views/panel/backend/message-handlers/handle-at-sign-quick-pick.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { ViewProvider } from '@/views/panel/backend/panel-provider'
22
import { at_sign_quick_pick } from '@/views/panel/backend/utils/at-sign-quick-pick'
33
import { HOME_VIEW_TYPES } from '@/views/panel/types/home-view-type'
4-
import * as vscode from 'vscode'
54

65
export const handle_at_sign_quick_pick = async (
7-
provider: ViewProvider,
8-
context: vscode.ExtensionContext,
9-
is_for_code_completions: boolean
6+
provider: ViewProvider
107
): Promise<void> => {
118
const replacement = await at_sign_quick_pick({
12-
context,
13-
is_for_code_completions,
14-
workspace_provider: provider.workspace_provider,
15-
allow_reference_context_item: true
9+
workspace_provider: provider.workspace_provider
1610
})
1711

1812
if (!replacement) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { ViewProvider } from '@/views/panel/backend/panel-provider'
2+
import { HOME_VIEW_TYPES } from '@/views/panel/types/home-view-type'
3+
import * as vscode from 'vscode'
4+
import { hash_sign_quick_pick } from '../utils/hash-sign-quick-pick'
5+
6+
export const handle_hash_sign_quick_pick = async (
7+
provider: ViewProvider,
8+
context: vscode.ExtensionContext,
9+
is_for_code_completions: boolean
10+
): Promise<void> => {
11+
const replacement = await hash_sign_quick_pick({
12+
context,
13+
is_for_code_completions
14+
})
15+
16+
if (!replacement) {
17+
provider.send_message({
18+
command: 'FOCUS_CHAT_INPUT'
19+
})
20+
return
21+
}
22+
23+
let current_text = ''
24+
25+
const mode =
26+
provider.home_view_type == HOME_VIEW_TYPES.WEB
27+
? provider.web_mode
28+
: provider.api_mode
29+
if (mode == 'ask') {
30+
current_text = provider.ask_instructions
31+
} else if (mode == 'edit-context') {
32+
current_text = provider.edit_instructions
33+
} else if (mode == 'no-context') {
34+
current_text = provider.no_context_instructions
35+
} else if (mode == 'code-completions') {
36+
current_text = provider.code_completion_instructions
37+
}
38+
39+
const is_after_hash_sign = current_text
40+
.slice(0, provider.caret_position)
41+
.endsWith('#')
42+
if (is_after_hash_sign) {
43+
provider.add_text_at_cursor_position(replacement, 1)
44+
} else {
45+
provider.add_text_at_cursor_position(replacement)
46+
}
47+
}

‎packages/vscode/src/views/panel/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export * from './handle-edit-context'
2424
export * from './handle-code-completion'
2525
export * from './handle-get-edit-format'
2626
export * from './handle-at-sign-quick-pick'
27+
export * from './handle-hash-sign-quick-pick'
2728
export * from './handle-get-edit-format-instructions'
2829
export * from './handle-get-mode-web'
2930
export * from './handle-get-mode-api'
3031
export * from './handle-save-mode-web'
3132
export * from './handle-save-mode-api'
3233
export * from './handle-get-version'
33-
export * from './handle-at-sign-quick-pick-for-preset-affix'
3434
export * from './handle-get-api-tool-configurations'
3535
export * from './handle-reorder-api-tool-configurations'
3636
export * from './handle-get-donations-visibility'

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
handle_get_home_view_type,
3939
handle_get_version,
4040
handle_show_prompt_template_quick_pick,
41-
handle_at_sign_quick_pick_for_preset_affix,
4241
handle_get_api_tool_configurations,
4342
handle_reorder_api_tool_configurations,
4443
handle_pick_open_router_model,
@@ -51,7 +50,8 @@ import {
5150
handle_intelligent_update_file_in_review,
5251
handle_commit_changes,
5352
handle_accept_commit_message,
54-
handle_cancel_commit_message
53+
handle_cancel_commit_message,
54+
handle_hash_sign_quick_pick
5555
} from './message-handlers'
5656
import {
5757
API_EDIT_FORMAT_STATE_KEY,
@@ -406,19 +406,13 @@ export class ViewProvider implements vscode.WebviewViewProvider {
406406
} else if (message.command == 'GET_VERSION') {
407407
handle_get_version(this)
408408
} else if (message.command == 'SHOW_AT_SIGN_QUICK_PICK') {
409-
await handle_at_sign_quick_pick(
409+
await handle_at_sign_quick_pick(this)
410+
} else if (message.command == 'SHOW_HASH_SIGN_QUICK_PICK') {
411+
await handle_hash_sign_quick_pick(
410412
this,
411413
this.context,
412414
message.is_for_code_completions
413415
)
414-
} else if (
415-
message.command == 'SHOW_AT_SIGN_QUICK_PICK_FOR_PRESET_AFFIX'
416-
) {
417-
await handle_at_sign_quick_pick_for_preset_affix(
418-
this,
419-
this.context,
420-
message
421-
)
422416
} else if (message.command == 'GET_DONATIONS_VISIBILITY') {
423417
handle_get_donations_visibility(this)
424418
} else if (message.command == 'SAVE_DONATIONS_VISIBILITY') {

0 commit comments

Comments
 (0)