local map = vim.keymap.set ---------------------- -- Language servers -- ---------------------- -- NOTE: put settings into `settings` -- use another `on_attach` field if needed local servers = { clangd = {}, -- C/CPP cssls = {}, -- CSS html = {}, -- HTML jsonls = {}, -- JSON lemminx = {}, -- XML phpactor = {}, -- PHP pylsp = {}, -- Python pyright = {}, taplo = {}, -- TOML texlab = {}, -- texlab ts_ls = {}, -- TypeScript vimls = {}, -- Vim Script ocamllsp = {}, -- OCaml gleam = {}, -- Gleam yamlls = {}, -- yaml gopls = {}, -- Golang elmls = {}, -- elm -- -- fix this, it shows spamming message on top -- golangci_lint_ls = {}, fish_lsp = {}, bashls = { -- Bash on_attach = function(_, bufno) map("n", "f", function() local saved = vim.fn.winsaveview() vim.cmd([[silent exec "%!shfmt"]]) vim.fn.winrestview(saved) end, { buffer = bufno }) end, }, tinymist = { on_attach = function(_, bufno) map("n", "f", function() local saved = vim.fn.winsaveview() vim.cmd([[silent exec "%!typstyle -c 100"]]) vim.fn.winrestview(saved) end, { buffer = bufno }) end, }, lua_ls = { -- Lua on_attach = function(_, bufno) map("n", "f", function() local saved = vim.fn.winsaveview() vim.cmd([[silent exec "!stylua %"]]) vim.fn.winrestview(saved) end, { buffer = bufno }) end, settings = { Lua = { workspace = { checkThirdParty = "Disable", library = { vim.env.VIMRUNTIME }, }, }, }, }, nil_ls = { -- Nix settings = { ["nil"] = { formatting = { command = { "alejandra" } } } }, }, } ------------- -- Helpers -- ------------- vim.diagnostic.config { signs = { text = { [vim.diagnostic.severity.ERROR] = "E", [vim.diagnostic.severity.WARN] = "W", [vim.diagnostic.severity.INFO] = "H", [vim.diagnostic.severity.HINT] = "ยท", }, }, severity_sort = true, underline = { severity = { vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN, }, }, } local mylsp = require("lsp") -- Helix style border local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) opts = opts or {} opts.border = mylsp.border return orig_util_open_floating_preview(contents, syntax, opts, ...) end -- Set log level vim.lsp.set_log_level("off") ---------- -- Init -- ---------- -- It is not recommended to break lspconfig into different settings -- related: https://github.com/neovim/nvim-lspconfig/issues/970#issuecomment-860080502 for name, config in pairs(servers) do require("lspconfig")[name].setup { capabilities = mylsp.capabilities, settings = config.settings, on_attach = function(client, bufno) mylsp.on_attach(client, bufno); (config.on_attach or function(...) end)(client, bufno) end, } end