我正在使用带有LSP的Neovim,但保存任何tsx文件时遇到问题,会不断提示我选择语言服务器:
如果我执行
EFM配置
这是我配置语言服务器的方式
lspinstall.setup()
local servers = lspinstall.installed_servers()
for _, lsp in ipairs(servers) do
if lsp == 'tsserver' then
require('lsp.tsserver')
elseif lsp == 'efm' then
require('lsp.efm')
elseif lsp == 'html' then
require('lsp.html')
else
nvim_lsp[lsp].setup {on_attach = on_attach, settings = {Lua = {diagnostics = {globals = {'vim'}}}}}
end
end
如果我执行
:LspInfo
,我会看到屏幕截图中看到的2个服务器。EFM配置
local lspconfig = require 'lspconfig'
local prettier = {formatCommand = './node_modules/.bin/prettier --config-precedence prefer-file --stdin-filepath ${INPUT}', formatStdin = true}
local luaFormat = {
formatCommand = 'lua-format -i --no-keep-simple-function-one-line --column-limit=120 --indent-width=2 --double-quote-to-single-quote',
formatStdin = true
}
lspconfig.efm.setup {
-- cmd = {'efm-langserver', '-logfile', '/tmp/efm.log', '-loglevel', '5'},
on_attach = on_attach,
init_options = {documentFormatting = true},
filetypes = {'javascriptreact', 'javascript', 'lua', 'typescriptreact', 'typescript'},
settings = {
rootMarkers = {'.git/'},
languages = {lua = {luaFormat}, typescript = {prettier}, typescriptreact = {prettier}}
}
}
typescript配置
local lspconfig = require 'lspconfig'
lspconfig.tsserver.setup {
on_attach = function(client, bufnr)
client.resolved_capabilities.document_formatting = false
on_attach(client, bufnr)
end,
settings = {diagnostics = {globals = {'on_attach'}}}
}
感谢任何帮助
formatting_seq_sync(nil, 1000, {"null-ls"})
将确保 null-ls 语言服务器进行格式化。但是其他语言服务器将在您选择的服务器之前被调用,因此性能较差。 - Emmanuel Touzery