Skip to content

Commit

Permalink
fix: coq_nvim completion integration (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoP authored and devansh08 committed Nov 1, 2024
1 parent fd1fa34 commit 4e20d16
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lua/neorg/modules/core/integrations/coq_nvim/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,39 @@ module.public = {
return callback()
end

local completion_cache = module.public.invoke_completion_engine(args)
local row, col = unpack(args.pos)
local line = args.line
local before_char = line:sub(#line, #line)
-- Neorg requires a nvim-compe like context nvim-compe defines
-- the following fields. Not all of them are used by Neorg, but
-- they are left here for future reference
local context = {
start_offset = nil,
char = col + 1,
before_char = before_char,
line = line,
column = nil,
buffer = nil,
line_number = row + 1,
previous_context = nil,
full_line = line,
}
local completion_cache = module.public.invoke_completion_engine(context)
local prev = line:match("({.*)$")

if completion_cache.options.pre then
completion_cache.options.pre(args)
completion_cache.options.pre(context)
end

local completions = vim.deepcopy(completion_cache.items)

for index, element in ipairs(completions) do
local word = element
local label = element
-- coq_nvim requries at least 2 exact prefix characters by
-- default. Users could chagnge this setting, but instead
-- we are providing the start of the match (for links) so
-- coq_nvim doesnt' filter our results
local word = (prev or "") .. element
local label = (prev or "") .. element
if type(element) == "table" then
word = element[1]
label = element.label
Expand Down

0 comments on commit 4e20d16

Please sign in to comment.