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

Support for null-ls #49

Open
xigoi opened this issue Jan 19, 2022 · 5 comments
Open

Support for null-ls #49

xigoi opened this issue Jan 19, 2022 · 5 comments

Comments

@xigoi
Copy link

xigoi commented Jan 19, 2022

I managed to set up nim.nvim as a source for null-ls, which allows it to be used with any completion engine that supports LSP. Here's the code:

local null_ls = require "null-ls"

local CompletionItemKind = vim.lsp.protocol.CompletionItemKind
local kinds = {
  d = CompletionItemKind.Keyword,
  f = CompletionItemKind.Function,
  t = CompletionItemKind.Struct,
  v = CompletionItemKind.Variable,
}

return {
  method = null_ls.methods.COMPLETION,
  filetypes = { "nim" },
  generator = {
    async = true,
    fn = function(params, done)
      vim.fn["nim#suggest#sug#GetAllCandidates"](function(start, candidates)
        local items = vim.tbl_map(function(candidate)
          return {
            kind = kinds[candidate.kind] or CompletionItemKind.Text,
            label = candidate.word,
            documentation = candidate.info,
          }
        end, candidates)
        done { { items = items } }
      end)
    end,
  },
}

Simply put this in a Lua file and then require the file in the list of sources.

@n0bra1n3r
Copy link
Contributor

Thanks for this. I've been having issues with autocompletion recently. Do you happen to have this working with neovim 0.7.2 and nim 1.7.1? The candidates parameter is always empty in that callback. If not, do you remember which version of neovim/nim you had this working with?

@xigoi
Copy link
Author

xigoi commented Jul 30, 2022

Thanks for this. I've been having issues with autocompletion recently. Do you happen to have this working with neovim 0.7.2 and nim 1.7.1? The candidates parameter is always empty in that callback. If not, do you remember which version of neovim/nim you had this working with?

I'm using Neovim 0.7.2 and Nim 1.6.6 and the completion works, it's just very slow (just as the rest of nim.nvim). I haven't tried Nim 1.7, but I don't see why that would break it.

@n0bra1n3r
Copy link
Contributor

I see, thanks! It must be something in my config then, or the fact that I'm on windows. Are you running it on Linux? Thanks again!

@xigoi
Copy link
Author

xigoi commented Aug 6, 2022

Yes, I'm on GNU+Linux. Also tried it in Termux on Android.

@ariel-frischer
Copy link

ariel-frischer commented Nov 5, 2022

I'm getting Unknown function: nim#suggest#sug#GetAllCandidates (fixed) also null-ls info lists unknown source unless you add name = "nim" to the config.

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

3 participants