Skip to content

Commit 033bac5

Browse files
committed
Remove context dependency enforcement from the chat input and enhance prompt context collection
1 parent 645b2b2 commit 033bac5

15 files changed

Lines changed: 75 additions & 61 deletions

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ const translations = {
1515
'Code completions mode unavailable with text selection',
1616
code_completions_mode_unavailable_without_active_editor:
1717
'Code completions mode unavailable without active editor',
18-
mode_unavailable_without_context: 'This mode requires context',
1918
search: 'Search',
2019
websocket_not_connected: 'Websocket not connected',
2120
for_history_hint: 'for history hint',
2221
copy_to_clipboard: 'Copy to clipboard',
2322
insert_symbol: 'Insert symbol',
2423
prompt_templates: 'Prompt templates',
25-
approximate_token_count: 'Approximate token count'
24+
approximate_token_count: 'Approximate token count',
25+
last_selection: 'Last selection',
26+
use_default: 'Use default',
27+
select: 'Select'
2628
}
2729

2830
export const Empty = () => (
@@ -44,7 +46,6 @@ export const Empty = () => (
4446
on_submit_with_control={() => {}}
4547
on_curly_braces_click={() => {}}
4648
has_context={true}
47-
is_in_context_dependent_mode={true}
4849
/>
4950
)
5051

@@ -67,7 +68,6 @@ export const WithText = () => (
6768
on_submit_with_control={() => {}}
6869
on_curly_braces_click={() => {}}
6970
has_context={true}
70-
is_in_context_dependent_mode={true}
7171
/>
7272
)
7373

@@ -90,7 +90,6 @@ export const DisabledSubmit = () => (
9090
on_submit_with_control={() => {}}
9191
on_curly_braces_click={() => {}}
9292
has_context={true}
93-
is_in_context_dependent_mode={true}
9493
/>
9594
)
9695

@@ -113,7 +112,6 @@ export const MultilineText = () => (
113112
on_submit_with_control={() => {}}
114113
on_curly_braces_click={() => {}}
115114
has_context={true}
116-
is_in_context_dependent_mode={true}
117115
/>
118116
)
119117

@@ -136,7 +134,6 @@ export const LongText = () => (
136134
on_submit_with_control={() => {}}
137135
on_curly_braces_click={() => {}}
138136
has_context={true}
139-
is_in_context_dependent_mode={true}
140137
/>
141138
)
142139

@@ -160,7 +157,6 @@ export const WithTokenCount = () => (
160157
on_submit_with_control={() => {}}
161158
on_curly_braces_click={() => {}}
162159
has_context={true}
163-
is_in_context_dependent_mode={true}
164160
/>
165161
)
166162

@@ -184,7 +180,6 @@ export const WithLargeTokenCount = () => (
184180
on_submit_with_control={() => {}}
185181
on_curly_braces_click={() => {}}
186182
has_context={true}
187-
is_in_context_dependent_mode={true}
188183
/>
189184
)
190185

@@ -207,7 +202,6 @@ export const CodeCompletionsMode = () => (
207202
on_submit_with_control={() => {}}
208203
on_curly_braces_click={() => {}}
209204
has_context={true}
210-
is_in_context_dependent_mode={true}
211205
/>
212206
)
213207

@@ -230,7 +224,6 @@ export const WithActiveSelection = () => (
230224
translations={translations}
231225
on_curly_braces_click={() => {}}
232226
has_context={true}
233-
is_in_context_dependent_mode={true}
234227
/>
235228
)
236229

@@ -253,7 +246,6 @@ export const WithSavedContextPlaceholder = () => (
253246
translations={translations}
254247
on_curly_braces_click={() => {}}
255248
has_context={true}
256-
is_in_context_dependent_mode={true}
257249
/>
258250
)
259251

@@ -276,7 +268,6 @@ export const WithActiveSelectionAndPlaceholder = () => (
276268
translations={translations}
277269
on_curly_braces_click={() => {}}
278270
has_context={true}
279-
is_in_context_dependent_mode={true}
280271
/>
281272
)
282273

@@ -299,6 +290,5 @@ export const WithPlaceholderNoSelection = () => (
299290
translations={translations}
300291
on_curly_braces_click={() => {}}
301292
has_context={true}
302-
is_in_context_dependent_mode={true}
303293
/>
304294
)

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type Props = {
1414
token_count?: number
1515
is_connected: boolean
1616
is_in_code_completions_mode: boolean
17-
is_in_context_dependent_mode: boolean
1817
has_active_selection: boolean
1918
has_active_editor: boolean
2019
on_caret_position_change: (caret_position: number) => void
@@ -32,7 +31,6 @@ type Props = {
3231
select_config: string
3332
code_completions_mode_unavailable_with_text_selection: string
3433
code_completions_mode_unavailable_without_active_editor: string
35-
mode_unavailable_without_context: string
3634
search: string
3735
websocket_not_connected: string
3836
for_history_hint: string
@@ -295,20 +293,11 @@ export const ChatInput: React.FC<Props> = (props) => {
295293
</div>
296294
)}
297295

298-
{!props.has_context && props.is_in_context_dependent_mode && (
299-
<div className={styles.error}>
300-
<div className={styles.error__inner}>
301-
{props.translations.mode_unavailable_without_context}
302-
</div>
303-
</div>
304-
)}
305-
306296
<div
307297
className={cn(styles.container__inner, {
308298
[styles['container__inner--disabled']]:
309-
(props.is_in_code_completions_mode &&
310-
(props.has_active_selection || !props.has_active_editor)) ||
311-
(!props.has_context && props.is_in_context_dependent_mode)
299+
props.is_in_code_completions_mode &&
300+
(props.has_active_selection || !props.has_active_editor)
312301
})}
313302
onKeyDown={(e) => {
314303
if (e.key == 'f' && (e.ctrlKey || e.metaKey)) {

packages/vscode/src/commands/code-completion-in-chat-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode'
22
import { FilesCollector } from '../utils/files-collector'
33
import { WebSocketManager } from '../services/websocket-manager'
4-
import { ConfigPresetFormat } from '@/view/backend/helpers/preset-format-converters'
4+
import { ConfigPresetFormat } from '@/view/backend/utils/preset-format-converters'
55
import { chat_code_completion_instructions } from '../constants/instructions'
66
import { CHATBOTS } from '@shared/constants/chatbots'
77

packages/vscode/src/utils/apply-preset-affixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigPresetFormat } from '@/view/backend/helpers/preset-format-converters'
1+
import { ConfigPresetFormat } from '@/view/backend/utils/preset-format-converters'
22
import * as vscode from 'vscode'
33

44
export function apply_preset_affixes_to_instruction(

packages/vscode/src/utils/files-collector.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,35 @@ export class FilesCollector {
2323
this.workspace_roots = workspace_provider.getWorkspaceRoots()
2424
}
2525

26-
async collect_files(params?: { exclude_path?: string }): Promise<string> {
27-
const workspace_files = this.workspace_provider.get_checked_files()
28-
const open_editor_files =
29-
this.open_editors_provider?.get_checked_files() || []
26+
async collect_files(params?: {
27+
exclude_path?: string
28+
additional_paths?: string[]
29+
no_context?: boolean
30+
}): Promise<string> {
31+
let context_files: string[] = []
32+
33+
if (params?.no_context) {
34+
context_files = params?.additional_paths ?? []
35+
} else {
36+
const workspace_files = this.workspace_provider.get_checked_files()
37+
const open_editor_files =
38+
this.open_editors_provider?.get_checked_files() || []
39+
40+
context_files = Array.from(
41+
new Set([
42+
...workspace_files,
43+
...open_editor_files,
44+
...(params?.additional_paths ?? [])
45+
])
46+
)
47+
}
3048

31-
const context_files = Array.from(
32-
new Set([...workspace_files, ...open_editor_files])
33-
).sort((a, b) => natural_sort(a, b))
49+
context_files.sort((a, b) => natural_sort(a, b))
3450

3551
let collected_text = ''
3652

37-
if (this.websites_provider) {
53+
// Only include websites when not in no_context mode
54+
if (!params?.no_context && this.websites_provider) {
3855
const checked_websites = this.websites_provider.get_checked_websites()
3956

4057
for (const website of checked_websites) {

packages/vscode/src/view/backend/message-handlers/handle-copy-prompt.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ export const handle_copy_prompt = async (
6565

6666
vscode.env.clipboard.writeText(text.trim())
6767
} else if (!is_in_code_completions_mode) {
68-
const mode =
69-
provider.home_view_type == HOME_VIEW_TYPES.WEB
70-
? provider.web_mode
71-
: provider.api_mode
72-
const context_text =
73-
mode != 'no-context' ? await files_collector.collect_files() : ''
68+
const additional_paths = await extract_file_paths_from_instruction(
69+
final_instruction
70+
)
71+
72+
const context_text = await files_collector.collect_files({
73+
additional_paths,
74+
no_context: provider.web_mode == 'no-context'
75+
})
7476

7577
const instructions = replace_selection_placeholder(final_instruction)
7678

@@ -95,7 +97,7 @@ export const handle_copy_prompt = async (
9597
)
9698
}
9799

98-
if (mode == 'edit-context') {
100+
if (provider.web_mode == 'edit-context') {
99101
const edit_format =
100102
provider.home_view_type == HOME_VIEW_TYPES.WEB
101103
? provider.chat_edit_format
@@ -128,3 +130,12 @@ export const handle_copy_prompt = async (
128130
} copied to clipboard!`
129131
)
130132
}
133+
134+
async function extract_file_paths_from_instruction(
135+
instruction: string
136+
): Promise<string[]> {
137+
const matches = instruction.match(/`([^`]+)`/g)
138+
if (!matches) return []
139+
140+
return matches.map((match) => match.slice(1, -1)) // Remove backticks
141+
}

packages/vscode/src/view/backend/message-handlers/handle-create-preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CHATBOTS } from '@shared/constants/chatbots'
44
import {
55
config_preset_to_ui_format,
66
ConfigPresetFormat
7-
} from '@/view/backend/helpers/preset-format-converters'
7+
} from '@/view/backend/utils/preset-format-converters'
88

99
export const handle_create_preset = async (
1010
provider: ViewProvider

packages/vscode/src/view/backend/message-handlers/handle-delete-preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode'
22
import { ViewProvider } from '@/view/backend/view-provider'
33
import { DeletePresetMessage } from '@/view/types/messages'
4-
import { ConfigPresetFormat } from '@/view/backend/helpers/preset-format-converters'
4+
import { ConfigPresetFormat } from '@/view/backend/utils/preset-format-converters'
55

66
export const handle_delete_preset = async (
77
provider: ViewProvider,

packages/vscode/src/view/backend/message-handlers/handle-duplicate-preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode'
22
import { ViewProvider } from '@/view/backend/view-provider'
33
import { DuplicatePresetMessage } from '@/view/types/messages'
4-
import { ConfigPresetFormat } from '@/view/backend/helpers/preset-format-converters'
4+
import { ConfigPresetFormat } from '@/view/backend/utils/preset-format-converters'
55

66
export const handle_duplicate_preset = async (
77
provider: ViewProvider,

packages/vscode/src/view/backend/message-handlers/handle-replace-presets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { ReplacePresetsMessage } from '@/view/types/messages'
3-
import { ui_preset_to_config_format } from '@/view/backend/helpers/preset-format-converters'
3+
import { ui_preset_to_config_format } from '@/view/backend/utils/preset-format-converters'
44
import { ViewProvider } from '../view-provider'
55

66
export const handle_replace_presets = async (

0 commit comments

Comments
 (0)