ms-jpq / coq_nvim

Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.
GNU General Public License v3.0
3.57k stars 99 forks source link

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

Open nijek opened 2 months ago

nijek commented 2 months ago

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

TheLeoP commented 1 month ago
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