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", "sqlls", "efm", "html" }, } local lspconfig = require('lspconfig') local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -- 需特别配置的lsp插件 -- { key: 语言 value: 配置文件 } -- pyright 不支持autoformat local servers = { sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua tailwindcss = require "lsp.tailwind", sqlls = require "lsp.sqlls", efm = require "lsp.efm", volar = require "lsp.volar" } 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', '', 'lua vim.lsp.buf.definition()', keyOpts) vim.api.nvim_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', keyOpts) vim.api.nvim_set_keymap('n', 'e[', 'lua vim.diagnostic.goto_prev()', keyOpts) vim.api.nvim_set_keymap('n', 'e]', 'lua vim.diagnostic.goto_next()', keyOpts) -- vim.cmd [[autocmd BufWritePre 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({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, [''] = 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' }), [''] = 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 -- } } }