Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nijek opened this issue Sep 8, 2024 · 1 comment
Open

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

nijek opened this issue Sep 8, 2024 · 1 comment

Comments

@nijek
Copy link

nijek commented Sep 8, 2024

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
Copy link
Contributor

TheLeoP commented Oct 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants