146 lines
4.5 KiB
Lua
146 lines
4.5 KiB
Lua
require("mason").setup({
|
|
ui = {
|
|
icons = {
|
|
package_installed = "✓",
|
|
package_pending = "➜",
|
|
package_uninstalled = "✗"
|
|
}
|
|
}
|
|
})
|
|
|
|
-- https://github.com/williamboman/mason-lspconfig.nvim
|
|
require("mason-lspconfig").setup {
|
|
ensure_installed = { "rust_analyzer", "gopls", "volar", "cssls", "yamlls", "zk", "tsserver", "pyright",
|
|
"tailwindcss", "sqls", "efm", "html", "prettierd" },
|
|
}
|
|
|
|
local lspconfig = require('lspconfig')
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
|
|
|
-- 需特别配置的lsp插件
|
|
-- { key: 语言 value: 配置文件 }
|
|
-- pyright 不支持autoformat
|
|
local servers = {
|
|
sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua
|
|
tailwindcss = require "lsp.tailwind",
|
|
sqls = require "lsp.sql",
|
|
efm = require "lsp.efm",
|
|
}
|
|
|
|
require("mason-lspconfig").setup_handlers({
|
|
-- The first entry (without a key) will be the default handler
|
|
-- and will be called for each installed server that doesn't have
|
|
-- a dedicated handler.
|
|
function(server_name) -- default handler (optional)
|
|
local opts = servers[server_name]
|
|
if not opts then
|
|
opts = {}
|
|
end
|
|
opts.capabilities = capabilities
|
|
opts.flags = {
|
|
debounce_text_changes = 150,
|
|
}
|
|
require("lspconfig")[server_name].setup(opts)
|
|
end,
|
|
})
|
|
|
|
-- local lsp_installer = require "nvim-lsp-installer"
|
|
|
|
|
|
-- Mappings.
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
local keyOpts = { noremap = true, silent = true }
|
|
-- vim.api.nvim_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
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_next()<CR>', keyOpts)
|
|
|
|
-- vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
|
|
|
|
|
|
-- luasnip setup
|
|
local luasnip = require 'luasnip'
|
|
|
|
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
|
require('nvim-ts-autotag').setup()
|
|
|
|
-- nvim-cmp setup
|
|
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' },
|
|
{ name = 'omni', }
|
|
},
|
|
}
|
|
|
|
-- Utilities for creating configurations
|
|
local util = require "formatter.util"
|
|
|
|
-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
|
|
require("formatter").setup {
|
|
-- Enable or disable logging
|
|
logging = true,
|
|
-- Set the log level
|
|
log_level = vim.log.levels.WARN,
|
|
-- All formatter configurations are opt-in
|
|
filetype = {
|
|
-- vue = {
|
|
-- function()
|
|
-- return {
|
|
-- exe = "prettierd",
|
|
-- args = {vim.api.nvim_buf_get_name(0)},
|
|
-- stdin = true
|
|
-- }
|
|
-- end
|
|
-- },
|
|
|
|
-- Use the special "*" filetype for defining formatter configurations on
|
|
-- any filetype
|
|
-- ["*"] = {
|
|
-- -- "formatter.filetypes.any" defines default configurations for any
|
|
-- -- filetype
|
|
-- require("formatter.filetypes.any").remove_trailing_whitespace
|
|
-- }
|
|
}
|
|
}
|