efm-langserver
efm-langserver copied to clipboard
Formatting not working for Lua
Describe the bug I execute and the file doesn't change
:lua vim.lsp.buf.formatting()
To Reproduce My efm setup:
local lspconfig = require('lspconfig')
lspconfig.efm.setup({
cmd = {'efm-langserver', '-logfile', '/tmp/efm.log', '-loglevel', '5'},
init_options = {documentFormatting = true},
settings = {
rootMarkers = {'.git/'},
languages = {
lua = {
formatCommand = 'lua-format -i --double-quote-to-single-quote',
formatStdin = true
}
}
}
})
I just have a simple rule to convert double quotes to single quotes to test.
Expected behavior Double quotes turn to single quotes when this is executed
:lua vim.lsp.buf.formatting()
Additional context I created a git repo just to test as well (To comply with the rootMakers option)
I have the lua language server running too, tho I have disabled it just in case it was causing any conflict and still nothing.
Lua setup:
local sumneko_root_path = '/usr/share/lua-language-server'
local sumneko_binary = '/bin/lua-language-server'
local lspconfig = require('lspconfig')
lspconfig.sumneko_lua.setup({
cmd = {sumneko_binary, '-E', sumneko_root_path .. '/main.lua'},
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
-- Setup your lua path
path = vim.split(package.path, ';')
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'}
},
workspace = {
-- Make the server aware of Neovim runtime files
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true
}
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {enable = false}
}
}
})
Neovim Version: NVIM v0.5.0-dev+1330 Distro: Arch Linux Terminal: Windows Terminal (Using WSL2)
SOLVED!!
As mentioned in issue #103
languages.<languages>
has to be a list.
Changing the efm setup
From:
local lspconfig = require('lspconfig')
lspconfig.efm.setup({
cmd = {'efm-langserver', '-logfile', '/tmp/efm.log', '-loglevel', '5'},
init_options = {documentFormatting = true},
settings = {
rootMarkers = {'.git/'},
languages = {
lua = {
formatCommand = 'lua-format -i --double-quote-to-single-quote',
formatStdin = true
}
}
}
})
To:
lspconfig.efm.setup({
init_options = {documentFormatting = true},
settings = {
languages = {
lua = {
{
formatCommand = 'lua-format -i',
formatStdin = true
}
}
}
})
Did the trick. I'll leave the issue open for exposure but feel free to close it!
#158 #137 looks like all faces the same issue.
I've solved a similar issue by specifying version = 2
in the settings
. See https://github.com/mattn/efm-langserver/issues/264#issuecomment-1784069576