This commit is contained in:
veypi
2022-05-15 15:15:27 +08:00
parent 4a1ad02483
commit f40ae333fe
12 changed files with 555 additions and 254 deletions
+21 -15
View File
@@ -1,20 +1,26 @@
-- 部分补全代码不支持autoformat 需使用efm自动补全
-- https://github.com/mattn/efm-langserver
return {
init_options = { documentFormatting = true },
filetypes = { 'python', 'json' },
settings = {
rootMarkers = { ".git/" },
languages = {
python = {
-- pip install yapf
{ formatCommand = "yapf --quiet", formatStdin = true }
},
json = {
-- yarn global add fixjson
{ formatCommand = "fixjson", formatStdin = true }
init_options = { documentFormatting = true },
filetypes = { 'python', 'json', 'css' },
settings = {
rootMarkers = { ".git/" },
languages = {
python = {
-- pip install yapf
{ formatCommand = "yapf --quiet", formatStdin = true }
},
json = {
-- yarn global add fixjson
{ formatCommand = "fixjson", formatStdin = true }
}
}
}
},
css = {
-- yarn global add prettier
{ formatCommand = "prettier --tab-width=4 ${--single-quote:singleQuote} --parser css", formatStdin = true }
-- { formatCommand = "prettier ${--tab-width:tabWidth} ${--single-quote:singleQuote} --parser css", formatStdin = true }
}
}
}
}
+10 -9
View File
@@ -1,13 +1,14 @@
local eslint_config = require("lspconfig.server_configurations.eslint")
return {
on_attach = function(client, bufnr)
-- neovim's LSP client does not currently support dynamic capabilities registration, so we need to set
-- the resolved capabilities of the eslint server ourselves!
client.resolved_capabilities.document_formatting = true
end,
settings = {
format = { enable = true },
},
cmd = { "yarn", "exec", unpack(eslint_config.default_config.cmd) }
on_attach = function(client, bufnr)
-- neovim's LSP client does not currently support dynamic capabilities registration, so we need to set
-- the resolved capabilities of the eslint server ourselves!
client.resolved_capabilities.document_formatting = true
end,
settings = {
format = { enable = true },
},
print(unpack(eslint_config.default_config.cmd)),
cmd = { "yarn", "exec", unpack(eslint_config.default_config.cmd) }
}
+67 -64
View File
@@ -10,9 +10,12 @@ local keyOpts = { noremap = true, silent = true }
vim.api.nvim_set_keymap('n', '<C-]>', '<cmd>lua vim.lsp.buf.definition()<CR>', keyOpts)
vim.api.nvim_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', keyOpts)
vim.api.nvim_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', keyOpts)
vim.api.nvim_set_keymap('n', 'e[', '<cmd>lua vim.diagnostic.goto_prev()<CR>',keyOpts)
vim.api.nvim_set_keymap('n', 'e[', '<cmd>lua vim.diagnostic.goto_prev()<CR>', keyOpts)
vim.api.nvim_set_keymap('n', 'e]', '<cmd>lua vim.diagnostic.goto_next()<CR>', keyOpts)
-- vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
-- 安装列表
@@ -20,38 +23,38 @@ vim.api.nvim_set_keymap('n', 'e]', '<cmd>lua vim.diagnostic.goto_next()<CR>', ke
-- { key: 语言 value: 配置文件 }
-- pyright 不支持autoformat
local servers = {
sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua
gopls = require "lsp.base",
volar = require "lsp.base",
basels = require "lsp.base",
cssls = require "lsp.base",
eslint = require "lsp.eslint",
tsserver = require "lsp.base",
prosemd_lsp = require "lsp.base",
pyright = require "lsp.base",
rust_analyzer = require "lsp.base",
tailwindcss = require "lsp.base",
efm = require "lsp.efm"
sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua
gopls = require "lsp.base",
volar = require "lsp.base",
basels = require "lsp.base",
cssls = require "lsp.base",
-- eslint = require "lsp.eslint",
tsserver = require "lsp.base",
prosemd_lsp = require "lsp.base",
pyright = require "lsp.base",
rust_analyzer = require "lsp.base",
tailwindcss = require "lsp.base",
efm = require "lsp.efm"
}
-- 自动安装 LanguageServers
for name, _ in pairs(servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
print("Installing " .. name)
server:install()
end
end
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
print("Installing " .. name)
server:install()
end
end
end
lsp_installer.on_server_ready(function(server)
local opts = servers[server.name]
opts.capabilities = capabilities
opts.flags = {
debounce_text_changes = 150,
}
server:setup(opts)
local opts = servers[server.name]
opts.capabilities = capabilities
opts.flags = {
debounce_text_changes = 150,
}
server:setup(opts)
end)
-- luasnip setup
@@ -65,42 +68,42 @@ local cmp = require 'cmp'
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } }))
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' }
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' }
},
}