Skip to content

Commit 22082ed

Browse files
committed
Check for complete pattern matches later in the target text
This allows us to find the best match when trying to match "so" against "schemas/source_files.ex". Without this, bescause the 's' in "so" matches against "schemas", we never find the complete match against "source_files" later in the target. Look for a later total match and add it to the list if it is at least as good as the computed partial match so far. If we also have a partial-match continuation, prefer the longer of the 2 choices.
1 parent 8f3c541 commit 22082ed

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lua/cmp/matcher.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ matcher.match = function(input, word, option)
112112
local no_symbol_match = false
113113
while input_end_index <= #input and word_index <= #word do
114114
local m = matcher.find_match_region(input, input_start_index, input_end_index, word, word_index)
115+
if input_start_index ~= 1 then
116+
-- If we can find a bigger match later, add it to the list. Prefer
117+
-- a larger, later match over a match spread over more small pieces.
118+
local m2 = matcher.find_match_region(input, 1, 1, word, word_index)
119+
if m and m2 then
120+
if m2.input_match_end >= m.input_match_end then
121+
m = m2
122+
end
123+
elseif m2 and not m then
124+
m = m2
125+
end
126+
end
115127
if m and input_end_index <= m.input_match_end then
116128
m.index = word_bound_index
117129
input_start_index = m.input_match_start + 1

0 commit comments

Comments
 (0)