Skip to content

Commit 2f95cdc

Browse files
committed
Pass context file paths to ghost text generation for identifier suggestions
1 parent 988710a commit 2f95cdc

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
127127
input_ref,
128128
is_focused: is_focused && should_show_ghost_text,
129129
currently_open_file_text: props.currently_open_file_text,
130+
context_file_paths: props.context_file_paths,
130131
caret_position
131132
})
132133

‎packages/ui/src/components/editor/panel/prompts/PromptField/hooks/use-ghost-text.ts‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const use_ghost_text = (params: {
1212
input_ref: RefObject<HTMLDivElement>
1313
is_focused: boolean
1414
currently_open_file_text?: string
15+
context_file_paths?: string[]
1516
caret_position: number
1617
}) => {
1718
const [ghost_text, set_ghost_text] = useState('')
@@ -37,13 +38,32 @@ export const use_ghost_text = (params: {
3738
}, [params.is_focused, params.value, can_show_ghost_text])
3839

3940
const identifiers = useMemo(() => {
40-
if (!params.currently_open_file_text) return new Set<string>()
41-
const matches = params.currently_open_file_text.match(
42-
/[a-zA-Z_][a-zA-Z0-9_]*/g
43-
)
44-
if (!matches) return new Set<string>()
45-
return new Set(matches.filter((id) => id.length >= 3))
46-
}, [params.currently_open_file_text])
41+
const match_set = new Set<string>()
42+
43+
if (params.currently_open_file_text) {
44+
const matches = params.currently_open_file_text.match(
45+
/[a-zA-Z_][a-zA-Z0-9_]*/g
46+
)
47+
if (matches) {
48+
for (const m of matches) {
49+
if (m.length >= 3) match_set.add(m)
50+
}
51+
}
52+
}
53+
54+
if (params.context_file_paths) {
55+
for (const path of params.context_file_paths) {
56+
const matches = path.match(/[a-zA-Z_][a-zA-Z0-9_]*/g)
57+
if (matches) {
58+
for (const m of matches) {
59+
if (m.length >= 3) match_set.add(m)
60+
}
61+
}
62+
}
63+
}
64+
65+
return match_set
66+
}, [params.currently_open_file_text, params.context_file_paths])
4767

4868
useEffect(() => {
4969
if (ghost_text_debounce_timer_ref.current) {

0 commit comments

Comments
 (0)