Skip to content

Commit 5dc0164

Browse files
committed
fix: handle file paths with line references in autocomplete
Fixes anomalyco#3910 When pasting file paths with line references like @file.tsx:39-42, the autocomplete system was treating the entire string (including :39-42) as a filename, causing no matches and blocking submission. Changes: - Strip line reference patterns (:N or :N-M) before file search - Auto-dismiss autocomplete when no results found after 300ms - Preserves normal autocomplete behavior for typing This enables tools like Neovim's SideKick.nvim that generate formatted paths with line references to work correctly. Co-authored-by: Claude (Anthropic AI Assistant)
1 parent 16c8c0f commit 5dc0164

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ export function Autocomplete(props: {
6060
return undefined
6161
}
6262

63-
return val
63+
// Strip line reference patterns (e.g., :39 or :39-42) from file paths
64+
// This allows pasted paths like @file.tsx:39-42 to match the file
65+
const lineRefPattern = /:\d+(-\d+)?$/
66+
const cleanedVal = val.replace(lineRefPattern, "")
67+
68+
return cleanedVal
6469
})
6570

6671
function insertPart(text: string, part: PromptInfo["parts"][number]) {
@@ -328,6 +333,29 @@ export function Autocomplete(props: {
328333
return result.map((arr) => arr.obj)
329334
})
330335

336+
// Auto-dismiss autocomplete when no results are found
337+
// This prevents the autocomplete from blocking submission when pasting file paths
338+
createEffect(() => {
339+
if (!store.visible || store.visible === "/") return
340+
const currentOptions = options()
341+
const currentFilter = filter()
342+
343+
// Only auto-dismiss if:
344+
// 1. There's an active filter (user has typed/pasted something)
345+
// 2. No options are available
346+
// 3. Files are not currently loading
347+
if (currentFilter && currentOptions.length === 0 && !files.loading) {
348+
// Use a small timeout to avoid dismissing too eagerly during typing
349+
const timer = setTimeout(() => {
350+
// Double-check conditions before hiding
351+
if (store.visible && filter() === currentFilter && options().length === 0) {
352+
hide()
353+
}
354+
}, 300)
355+
return () => clearTimeout(timer)
356+
}
357+
})
358+
331359
createEffect(() => {
332360
filter()
333361
setStore("selected", 0)

0 commit comments

Comments
 (0)