M README.md => README.md +1 -1
@@ 12,7 12,7 @@ Features and design goals:
## Installation
```lua
-use {'https://git.sr.ht/~vigoux/complementree.nvim', requires = {'L3MON4D3/LuaSnip', 'nvim-treesitter/nvim-treesitter'} }
+use {'https://git.sr.ht/~vigoux/complementree.nvim', requires = {'L3MON4D3/LuaSnip', 'https://git.sr.ht/~vigoux/azy.nvim'} }
```
## Setting up
M lua/complementree/comparators.lua => lua/complementree/comparators.lua +18 -22
@@ 36,34 36,30 @@ Comparators.length = mk_comparator(function(a, b)
return #a < #b
end)
-local ok_fzy, fzy = pcall(require, 'fzy-lua-native')
+local ok_fzy, fzy = pcall(require, 'fzy')
if ok_fzy then
- local function mk_fzy(is_case_sensitive)
- return function(msource)
- return function(ltc, lnum)
- local orig, prefix = msource(ltc, lnum)
- local scores = {}
- local matching = {}
- if prefix ~= "" then
- for _, a in ipairs(orig) do
- local s = fzy.score(prefix, utils.cword(a), is_case_sensitive)
- if math.abs(s) ~= math.huge or prefix == utils.cword(a) then
- scores[a] = s
- table.insert(matching, a)
- end
+ function Comparators.fzy(msource)
+ return function(ltc, lnum)
+ local orig, prefix = msource(ltc, lnum)
+ local scores = {}
+ local matching = {}
+ if prefix ~= "" then
+ for _, a in ipairs(orig) do
+ local s, _ = fzy.match(prefix, utils.cword(a))
+ if math.abs(s or math.huge) ~= math.huge or prefix == utils.cword(a) then
+ scores[a] = s
+ table.insert(matching, a)
end
- table.sort(matching, function(a, b)
- return scores[a] > scores[b]
- end)
- return matching, prefix
- else
- return orig, prefix
end
+ table.sort(matching, function(a, b)
+ return scores[a] > scores[b]
+ end)
+ return matching, prefix
+ else
+ return orig, prefix
end
end
end
- Comparators.fzy = mk_fzy(false)
- Comparators.ifzy = mk_fzy(true)
end
return Comparators
M lua/complementree/defaults.lua => lua/complementree/defaults.lua +1 -1
@@ 21,7 21,7 @@ function Defaults.ins_completion(mode)
end
end
-function Defaults.dummy()
+function Defaults.dummy(_, _)
end
M lua/complementree/init.lua => lua/complementree/init.lua +1 -1
@@ 128,7 128,7 @@ function M.complete()
local func = get_completion(ft, line_to_cursor, lnum, pref_start)
- if not (type(func) == "nil") then
+ if not (func == nil) then
if func(line_to_cursor, lnum) then
return true
end
M teal/complementree/comparators.tl => teal/complementree/comparators.tl +18 -22
@@ 36,34 36,30 @@ Comparators.length = mk_comparator(function(a: string, b: string): boolean
return #a < #b
end)
-local ok_fzy, fzy = pcall(require, 'fzy-lua-native')
+local ok_fzy, fzy = pcall(require, 'fzy')
if ok_fzy then
- local function mk_fzy(is_case_sensitive: boolean): Pipe
- return function(msource: Source): Source
- return function(ltc: string, lnum: integer): {CompleteItem}, string
- local orig, prefix = msource(ltc, lnum)
- local scores: {CompleteItem:integer} = {}
- local matching: {CompleteItem} = {}
- if prefix ~= "" then
- for _, a in ipairs(orig) do
- local s = fzy.score(prefix, utils.cword(a), is_case_sensitive)
- if math.abs(s) ~= math.huge or prefix == utils.cword(a) then
- scores[a] = s
- table.insert(matching, a)
- end
+ function Comparators.fzy(msource: Source): Source
+ return function (ltc: string, lnum: integer): {CompleteItem}, string
+ local orig, prefix = msource(ltc, lnum)
+ local scores: {CompleteItem:number} = {}
+ local matching: {CompleteItem} = {}
+ if prefix ~= "" then
+ for _, a in ipairs(orig) do
+ local s, _ = fzy.match(prefix, utils.cword(a))
+ if math.abs(s or math.huge) ~= math.huge or prefix == utils.cword(a) then
+ scores[a] = s
+ table.insert(matching, a)
end
- table.sort(matching, function(a: CompleteItem, b: CompleteItem): boolean
- return scores[a] > scores[b]
- end)
- return matching, prefix
- else
- return orig, prefix
end
+ table.sort(matching, function(a: CompleteItem, b: CompleteItem): boolean
+ return scores[a] > scores[b]
+ end)
+ return matching, prefix
+ else
+ return orig, prefix
end
end
end
- Comparators.fzy = mk_fzy(false)
- Comparators.ifzy = mk_fzy(true)
end
return Comparators
M teal/complementree/defaults.tl => teal/complementree/defaults.tl +1 -1
@@ 21,7 21,7 @@ function Defaults.ins_completion(mode: string): Completor
end
end
-function Defaults.dummy(): boolean
+function Defaults.dummy(_: string, _: integer): boolean
-- Does nothing
end
M teal/complementree/filters.tl => teal/complementree/filters.tl +1 -1
@@ 1,7 1,7 @@
local utils = require 'complementree.utils'
local record Filters
- amount: Pipe
+ amount: function(integer): Pipe
prefix: Pipe
strict_prefix: Pipe
substr: Pipe
M teal/complementree/sources.tl => teal/complementree/sources.tl +2 -2
@@ 27,7 27,7 @@ end
local record Sources
lsp_matches: function(LspOptions): Source
luasnip_matches: function(LuasnipOptions): Source
- ctags_matches: function(LuasnipOptions): Source
+ ctags_matches: function(CtagsOptions): Source
filepath_matches: function(FilepathOptions): Source
treesitter_matches: function(TreesitterOptions): Source
@@ 303,7 303,7 @@ function Sources.filepath_matches(opts: FilepathOptions): Source
}, opts)
local function iter_files(): function(): string|nil
- local path_stack = vim.fn.reverse(config.root_dirs or { '.' })
+ local path_stack: {string} = vim.fn.reverse(config.root_dirs or { '.' })
local iter_stack = {}
for _, p in ipairs(path_stack) do
table.insert(iter_stack, vim.loop.fs_scandir(p))
A types/fzy.d.tl => types/fzy.d.tl +17 -0
@@ 0,0 1,17 @@
+local record Fzy
+ type Choices = record<M>
+ add_incremental: function(Choices<M>, {M})
+ available: function(Choices<M>): integer
+ elements: function(Choices<M>): {{M, integer}}
+ search: function(Choices<M>, string)
+ selected: function(Choices<M>): M, integer
+ next: function(Choices<M>): M, integer
+ prev: function(Choices<M>): M, integer
+ get: function(Choices<M>, integer): M
+ end
+
+ create: function<M>({M}): Choices<M>
+ match: function(string, string): number, {integer}
+end
+
+return Fzy
M types/types.d.tl => types/types.d.tl +1 -0
@@ 154,6 154,7 @@ global record vim
notify: function(string)
pretty_print: function(...: any)
inspect: function(...: any): string
+ print: function(...: any)
end
global record jit