Hey!
I wanted to setup NeoVim 0.5 with elixir-ls + autocompletion following this article, and the autocompletion is working, I can see NeoVim communicates with the language server, but syntax highlighting for Elixir is not working for some reason. Everything has the same text color. When I tried some random Ruby project, code was syntax highlighted.
Any help would be really appreciated.
Here’s my init.vim
file:
call plug#begin('~/.config/nvim/autoload/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-compe'
Plug 'joshdick/onedark.vim'
call plug#end()
lua <<EOF
local lspconfig = require("lspconfig")
-- Neovim doesn't support snippets out of the box, so we need to mutate the
-- capabilities we send to the language server to let them know we want snippets.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
-- Setup our autocompletion. These configuration options are the default ones
-- copied out of the documentation.
require "compe".setup {
enabled = true,
autocomplete = true,
debug = false,
min_length = 1,
preselect = "disabled",
throttle_time = 80,
source_timeout = 200,
incomplete_delay = 400,
max_abbr_width = 100,
max_kind_width = 100,
max_menu_width = 100,
documentation = true,
source = {
path = true,
buffer = true,
calc = true,
vsnip = true,
nvim_lsp = true,
nvim_lua = true,
spell = true,
tags = true,
treesitter = true
}
}
-------------------------------------
-- A callback that will get called when a buffer connects to the language server.
-- Here we create any key maps that we want to have on that buffer.
local on_attach = function(_, bufnr)
local function map(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local map_opts = {noremap = true, silent = true}
map("n", "df", "<cmd>lua vim.lsp.buf.formatting()<cr>", map_opts)
map("n", "gd", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>", map_opts)
map("n", "dt", "<cmd>lua vim.lsp.buf.definition()<cr>", map_opts)
map("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", map_opts)
map("n", "gD", "<cmd>lua vim.lsp.buf.implementation()<cr>", map_opts)
map("n", "<c-k>", "<cmd>lua vim.lsp.buf.signature_help()<cr>", map_opts)
map("n", "1gD", "<cmd>lua vim.lsp.buf.type_definition()<cr>", map_opts)
-- These have a different style than above because I was fiddling
-- around and never converted them. Instead of converting them
-- now, I'm leaving them as they are for this article because this is
-- what I actually use, and hey, it works ¯\_(ツ)_/¯.
vim.cmd [[imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>']]
vim.cmd [[smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>']]
vim.cmd [[imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>']]
vim.cmd [[smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>']]
vim.cmd [[imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>']]
vim.cmd [[smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>']]
vim.cmd [[inoremap <silent><expr> <C-Space> compe#complete()]]
vim.cmd [[inoremap <silent><expr> <CR> compe#confirm('<CR>')]]
vim.cmd [[inoremap <silent><expr> <C-e> compe#close('<C-e>')]]
vim.cmd [[inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })]]
vim.cmd [[inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })]]
end
-- Finally, let's initialize the Elixir language server
-- Replace the following with the path to your installation
local path_to_elixirls = vim.fn.expand("~/dev/elixir-ls/rel/language_server.sh")
lspconfig.elixirls.setup({
cmd = {path_to_elixirls},
capabilities = capabilities,
on_attach = on_attach,
settings = {
elixirLS = {
-- I choose to disable dialyzer for personal reasons, but
-- I would suggest you also disable it unless you are well
-- aquainted with dialzyer and know how to use it.
dialyzerEnabled = false,
-- I also choose to turn off the auto dep fetching feature.
-- It often get's into a weird state that requires deleting
-- the .elixir_ls directory and restarting your editor.
fetchDeps = false
}
}
})
EOF