alaviss / nim.nvim

Nim plugin for NeoVim
ISC License
202 stars 24 forks source link

Support for null-ls #49

Open xigoi opened 2 years ago

xigoi commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

ariel-frischer commented 1 year ago

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.