4444--- @return OrgCompletionItem
4545function OrgCompletion :complete (context )
4646 local results = {}
47+ context .base = context .base or ' '
48+ if not context .matcher then
49+ context .matcher = function (value , pattern )
50+ pattern = pattern or ' '
51+ if pattern == ' ' then
52+ return true
53+ end
54+ if context .fuzzy then
55+ return # vim .fn .matchfuzzy ({ value }, pattern ) > 0
56+ end
57+ return value :find (' ^' .. vim .pesc (pattern )) ~= nil
58+ end
59+ end
4760 for _ , source in ipairs (self .sources ) do
4861 if source :get_start (context ) then
4962 vim .list_extend (results , self :_get_valid_results (source :get_results (context ), context ))
@@ -53,12 +66,13 @@ function OrgCompletion:complete(context)
5366 return results
5467end
5568
69+ --- @param results string[]
70+ --- @param context OrgCompletionContext
71+ --- @return OrgCompletionItem[]
5672function OrgCompletion :_get_valid_results (results , context )
57- local base = context .base or ' '
58-
5973 local valid_results = {}
6074 for _ , item in ipairs (results ) do
61- if base == ' ' or item : find ( ' ^ ' .. vim . pesc ( base ) ) then
75+ if context . matcher ( item , context . base ) then
6276 table.insert (valid_results , {
6377 word = item ,
6478 menu = self .menu ,
@@ -89,6 +103,9 @@ function OrgCompletion:omnifunc(findstart, base)
89103
90104 self ._context = self ._context or { line = self :get_line () }
91105 self ._context .base = base
106+ if vim .tbl_contains (vim .opt_local .completeopt :get (), ' fuzzy' ) then
107+ self ._context .fuzzy = true
108+ end
92109 return self :complete (self ._context )
93110end
94111
0 commit comments