Skip to content

Commit

Permalink
Check for complete pattern matches later in the target text
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iteratee committed Apr 24, 2024
1 parent 8f3c541 commit 6123f41
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lua/cmp/matcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ matcher.match = function(input, word, option)
local no_symbol_match = false
while input_end_index <= #input and word_index <= #word do
local m = matcher.find_match_region(input, input_start_index, input_end_index, word, word_index)
if input_start_index ~= 1 then
local m2 = nil
-- If we can find a bigger match later, add it to the list. Prefer
-- a larger, later match over a match spread over more small pieces.
m2 = matcher.find_match_region(input, 1, 1, word, word_index)
if m and m2 then
if m2.input_match_end >= m.input_match_end then
m = m2
end
elseif m2 and not m then
m = m2
end
end
if m and input_end_index <= m.input_match_end then
m.index = word_bound_index
input_start_index = m.input_match_start + 1
Expand Down

0 comments on commit 6123f41

Please sign in to comment.