Hey all,
I’m trying to integration the Motoko language server in neovim. It’s a pretty nice language and there’s understandably no official support yet. There’s a vscode plugin out there which basically invokes dfx _language-service
and passes the dfx.json
path as a parameter.
Pretty simple stuff. However, I’m having trouble using it in neovim. I’ve hacked this little piece together
nvim_lsp.motoko.setup{
cmd = {"dfx", "_language-service"},
filetypes = { "motoko", "mo"},
root_dir = root_pattern("dfx.json", ".git"),
settings = {},
capabilities = capabilities,
}
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = {"gopls", "tsserver", "motoko"}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
However when I do :LspInfo
it’s not detecting the language or starting the server.
Any pointers would be appreciated.
UPDATE
I had a look at the advanced custom configs and ended up with this config
The dao
parameter is the canister I’m working on. I’ll have to ask the user for their input after I get the basic working.
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
configs.motoko = {
default_config = {
cmd = {"dfx", "_language-service", "dao"},
filetypes = { "motoko", "mo", "gdmo"},
root_dir = function(fname)
return util.root_pattern '*.mo'(fname) or util.find_git_ancestor(fname) or util.path.dirname(fname)
end,
},
docs = {
description = [[]],
default_config = {
root_dir = [[root_pattern("dfx.json", ".git")]],
},
},
}
require('lspconfig').motoko.setup {}
:LspConfig
does now list the motoko server and detect the language as gdmo
,
Language client log: /Users/nmartin/.cache/nvim/lsp.log
Detected filetype: gdmo
1 client(s) attached to this buffer:
Client: motoko (id: 1, pid: 17216, bufnr: [1, 1])
filetypes: motoko, mo, gdmo
autostart: true
root directory: /Users/nmartin/crypto/sk/src/dao
cmd: dfx _language-service dao
Configured servers list: gopls, diagnosticls, motoko, tsserver
However the completion or the basic lsp functionality aren’t working.