11local char = require (' cmp.utils.char' )
2+ local pattern = require (' cmp.utils.pattern' )
23
34local matcher = {}
45
8182--- Match entry
8283--- @param input string
8384--- @param word string
84- --- @param option { synonyms : string[] , disallow_fullfuzzy_matching : boolean , disallow_fuzzy_matching : boolean , disallow_partial_fuzzy_matching : boolean , disallow_partial_matching : boolean , disallow_prefix_unmatching : boolean , disallow_symbol_nonprefix_matching : boolean }
85+ --- @param option { synonyms : string[] , disallow_fullfuzzy_matching : boolean , disallow_fuzzy_matching : boolean , disallow_partial_fuzzy_matching : boolean , disallow_partial_matching : boolean , disallow_prefix_unmatching : boolean , disallow_symbol_nonprefix_matching : boolean , keyword_pattern : string | nil }
8586--- @return integer , table
8687matcher .match = function (input , word , option )
8788 option = option or {}
@@ -103,6 +104,15 @@ matcher.match = function(input, word, option)
103104 end
104105 end
105106
107+ local is_symbol
108+ if option .keyword_pattern ~= nil then
109+ is_symbol = function (byte )
110+ return pattern .matchstr (option .keyword_pattern , string.char (byte )) == nil
111+ end
112+ else
113+ is_symbol = char .is_symbol
114+ end
115+
106116 -- Gather matched regions
107117 local matches = {}
108118 local input_start_index = 1
@@ -111,7 +121,7 @@ matcher.match = function(input, word, option)
111121 local word_bound_index = 1
112122 local no_symbol_match = false
113123 while input_end_index <= # input and word_index <= # word do
114- local m = matcher .find_match_region (input , input_start_index , input_end_index , word , word_index )
124+ local m = matcher .find_match_region (input , input_start_index , input_end_index , word , word_index , is_symbol )
115125 if m and input_end_index <= m .input_match_end then
116126 m .index = word_bound_index
117127 input_start_index = m .input_match_start + 1
@@ -277,7 +287,7 @@ matcher.fuzzy = function(input, word, matches, option)
277287end
278288
279289--- find_match_region
280- matcher .find_match_region = function (input , input_start_index , input_end_index , word , word_index )
290+ matcher .find_match_region = function (input , input_start_index , input_end_index , word , word_index , is_symbol )
281291 -- determine input position ( woroff -> word_offset )
282292 while input_start_index < input_end_index do
283293 if char .match (string.byte (input , input_end_index ), string.byte (word , word_index )) then
@@ -309,7 +319,7 @@ matcher.find_match_region = function(input, input_start_index, input_end_index,
309319 strict_count = strict_count + (c1 == c2 and 1 or 0 )
310320 match_count = match_count + 1
311321 word_offset = word_offset + 1
312- no_symbol_match = no_symbol_match or char . is_symbol (c1 )
322+ no_symbol_match = no_symbol_match or is_symbol (c1 )
313323 else
314324 -- Match end (partial region)
315325 if input_match_start ~= - 1 then
0 commit comments