Skip to content

Commit 306c33c

Browse files
committed
fix(ui/reference_picker): allow later top-level refs with same basename
1 parent 2b8b2fa commit 306c33c

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

lua/opencode/ui/reference_picker.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ function M.parse_references(text, message_id)
8181
refs = {},
8282
ranges = {},
8383
seen_paths = {},
84-
seen_basenames = {},
8584
}
8685
cache[message_id] = c
8786
end
@@ -107,18 +106,14 @@ function M.parse_references(text, message_id)
107106
local abs_ms = ms + abs_offset
108107
local abs_me = me + abs_offset
109108
local path_key = path .. ':' .. (l or '') .. ':' .. (col or '')
110-
local basename = path:match('[^/]+$') or path
111-
local shadowed = entry.check_exists and c.seen_basenames[basename]
112109

113110
if
114-
not shadowed
115-
and not is_url_path(path, chunk, ms)
111+
not is_url_path(path, chunk, ms)
116112
and not c.seen_paths[path_key]
117113
and not overlaps(c.ranges, abs_ms, abs_me)
118114
and (not entry.check_exists or file_exists(path))
119115
then
120116
c.seen_paths[path_key] = true
121-
c.seen_basenames[basename] = true
122117
table.insert(c.ranges, { abs_ms, abs_me })
123118
table.insert(c.refs, make_ref(path, l or '', col or '', abs_ms, abs_me))
124119
end

tests/unit/reference_picker_spec.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ describe('opencode.ui.reference_picker', function()
244244
assert.equal('src/main.lua', refs[1].file_path)
245245
end)
246246

247+
it('keeps later top-level references with the same basename', function()
248+
local text = 'See `src/main.lua:10` first, then check main.lua:42 too.'
249+
local refs = reference_picker.parse_references(text, 'msg1')
250+
251+
assert.equal(2, #refs)
252+
assert.equal('src/main.lua', refs[1].file_path)
253+
assert.equal(10, refs[1].line)
254+
assert.equal('main.lua', refs[2].file_path)
255+
assert.equal(42, refs[2].line)
256+
end)
257+
247258
it('ref struct contains file_path, line, col, match_start, match_end', function()
248259
local text = 'See `src/test.lua:5:3` for details.'
249260
local refs = reference_picker.parse_references(text, 'msg1')

0 commit comments

Comments
 (0)