coq_nvim icon indicating copy to clipboard operation
coq_nvim copied to clipboard

How do I turn a text file in a custom source?

Open nijek opened this issue 1 year ago • 1 comments

Hello, I read the documentation, I read the part about sources and custom sources, but I couldn't make it work. I have a file with words (like the english dictionary) and I want it to be a source to coq autocomplete. How do I do it? Do I put this on a separete file or inside my init.lua?


COQsources = COQsources or {}

COQsources["<random uid>"] = {
  name = "<name>", -- this is displayed to the client
  fn = function (args, callback)
    -- 0 based
    local row, col = unpack(args.pos)

    -- ...
    -- callback(<LSP completion items>) at some point


    local cancel = function ()
      -- ...
    end
    return cancel -- optionally support cancellation
  end
}

Thanks for the help

nijek avatar Sep 08 '24 23:09 nijek

COQsources = COQsources or {}

local uid = 1234
COQsources[uid] = {
  name = "dict",
  fn = function(args, callback)
    local file = io.open "test"
    if not file then
      callback()
      return
    end

    local items = {}
    for line in file:lines() do
      table.insert(items, { label = line, insertText = line })
    end
    file:close()

    callback { isIncomplete = false, items = items }
  end,
}

This is a rough example of how to get completion from a file

Do I put this on a separete file or inside my init.lua?

Put it anywhere where that could would get executed on startup, init.lua is indeed one of the places you could put it in

TheLeoP avatar Oct 19 '24 16:10 TheLeoP