diff --git a/README.md b/README.md index 48a1163..47afbaf 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,8 @@ lua < print, -- ~ -- * Typically, the middle match with symbol characters only is false positive. should be ignored. +-- This doesn't work for command line completions like ":b foo_" which we like to match +-- "lib/foo_bar.txt". The option disallow_symbol_nonprefix_matching controls this and defaults +-- to preventing matches like these. The documentation recommends it for command line completion. -- -- ---Match entry ---@param input string ---@param word string ----@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 } +---@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 } ---@return integer, table matcher.match = function(input, word, option) option = option or {} @@ -160,7 +163,9 @@ matcher.match = function(input, word, option) end if no_symbol_match and not prefix then - return 0, {} + if option.disallow_symbol_nonprefix_matching then + return 0, {} + end end -- Compute prefix match score diff --git a/lua/cmp/matcher_spec.lua b/lua/cmp/matcher_spec.lua index 607b2c8..25e5315 100644 --- a/lua/cmp/matcher_spec.lua +++ b/lua/cmp/matcher_spec.lua @@ -49,6 +49,7 @@ describe('matcher', function() disallow_partial_matching = false, disallow_prefix_unmatching = false, disallow_partial_fuzzy_matching = false, + disallow_symbol_nonprefix_matching = true, }) assert.is.truthy(score >= 1) assert.equals(matches[1].word_match_start, 5) @@ -58,6 +59,7 @@ describe('matcher', function() disallow_partial_matching = false, disallow_prefix_unmatching = false, disallow_partial_fuzzy_matching = true, + disallow_symbol_nonprefix_matching = true, }) assert.is.truthy(score == 0) end) @@ -84,6 +86,11 @@ describe('matcher', function() assert.is.truthy(matcher.match('bar', 'foo_bar', { disallow_prefix_unmatching = false }) >= 1) end) + it('disallow_symbol_nonprefix_matching', function() + assert.is.truthy(matcher.match('foo_', 'b foo_bar', { disallow_symbol_nonprefix_matching = true }) == 0) + assert.is.truthy(matcher.match('foo_', 'b foo_bar', { disallow_symbol_nonprefix_matching = false }) >= 1) + end) + it('debug', function() matcher.debug = function(...) print(vim.inspect({ ... })) diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index a6fae8f..98173c8 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -137,6 +137,7 @@ cmp.ItemField = { ---@field public disallow_partial_fuzzy_matching boolean ---@field public disallow_partial_matching boolean ---@field public disallow_prefix_unmatching boolean +---@field public disallow_symbol_nonprefix_matching boolean ---@class cmp.SortingConfig ---@field public priority_weight integer