mason
This commit is contained in:
+77
-48
@@ -1,6 +1,51 @@
|
||||
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)
|
||||
local lsp_installer = require "nvim-lsp-installer"
|
||||
|
||||
-- 需特别配置的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.
|
||||
@@ -16,53 +61,6 @@ vim.api.nvim_set_keymap('n', 'e]', '<cmd>lua vim.diagnostic.goto_next()<CR>', ke
|
||||
-- vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
|
||||
|
||||
|
||||
|
||||
|
||||
-- 安装列表
|
||||
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
|
||||
-- { 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",
|
||||
yamlls = require "lsp.base",
|
||||
zk = require "lsp.base",
|
||||
tsserver = require "lsp.base",
|
||||
pyright = require "lsp.base",
|
||||
rust_analyzer = require "lsp.base",
|
||||
tailwindcss = require "lsp.tailwind",
|
||||
sqls = require "lsp.sql",
|
||||
efm = require "lsp.efm",
|
||||
html = require "lsp.base"
|
||||
}
|
||||
|
||||
-- 自动安装 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
|
||||
end
|
||||
|
||||
lsp_installer.on_server_ready(function(server)
|
||||
local opts = servers[server.name]
|
||||
if not opts then
|
||||
return
|
||||
end
|
||||
opts.capabilities = capabilities
|
||||
opts.flags = {
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
server:setup(opts)
|
||||
end)
|
||||
|
||||
-- luasnip setup
|
||||
local luasnip = require 'luasnip'
|
||||
|
||||
@@ -114,3 +112,34 @@ cmp.setup {
|
||||
{ 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
|
||||
-- }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user