我正在将 Neovim 与 LSP 结合使用,但在保存任何 tsx 文件时遇到问题。我不断收到选择语言服务器的提示:
这是我配置语言服务器的方法
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
Run Code Online (Sandbox Code Playgroud)
如果我这样做,: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}}
}
}
Run Code Online (Sandbox Code Playgroud)
打字稿配置
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'}}}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
小智 2
最近进行了一项更改,以更好地支持多个 LSP,您可以在此处查看详细信息:https: //github.com/neovim/neovim/pull/14462,其要点是:使用formatting_seq_sync()而不是formatting_sync():https://neovim。 io/doc/user/lsp.html#vim.lsp.buf.formatting_seq_sync()
| 归档时间: |
|
| 查看次数: |
2929 次 |
| 最近记录: |