Skip to content

Commit 488507b

Browse files
authored
fix: coq_nvim completion integration (#1597)
1 parent b34337f commit 488507b

File tree

1 file changed

+26
-4
lines changed
  • lua/neorg/modules/core/integrations/coq_nvim

1 file changed

+26
-4
lines changed

lua/neorg/modules/core/integrations/coq_nvim/module.lua

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,39 @@ module.public = {
6767
return callback()
6868
end
6969

70-
local completion_cache = module.public.invoke_completion_engine(args)
70+
local row, col = unpack(args.pos)
71+
local line = args.line
72+
local before_char = line:sub(#line, #line)
73+
-- Neorg requires a nvim-compe like context nvim-compe defines
74+
-- the following fields. Not all of them are used by Neorg, but
75+
-- they are left here for future reference
76+
local context = {
77+
start_offset = nil,
78+
char = col + 1,
79+
before_char = before_char,
80+
line = line,
81+
column = nil,
82+
buffer = nil,
83+
line_number = row + 1,
84+
previous_context = nil,
85+
full_line = line,
86+
}
87+
local completion_cache = module.public.invoke_completion_engine(context)
88+
local prev = line:match("({.*)$")
7189

7290
if completion_cache.options.pre then
73-
completion_cache.options.pre(args)
91+
completion_cache.options.pre(context)
7492
end
7593

7694
local completions = vim.deepcopy(completion_cache.items)
7795

7896
for index, element in ipairs(completions) do
79-
local word = element
80-
local label = element
97+
-- coq_nvim requries at least 2 exact prefix characters by
98+
-- default. Users could chagnge this setting, but instead
99+
-- we are providing the start of the match (for links) so
100+
-- coq_nvim doesnt' filter our results
101+
local word = (prev or "") .. element
102+
local label = (prev or "") .. element
81103
if type(element) == "table" then
82104
word = element[1]
83105
label = element.label

0 commit comments

Comments
 (0)