local servers = { pylsp = {}, omnisharp = {}, html = {}, lua_ls = { settings = { Lua = { format = { defaultConfig = { indent_style = "space", indent_size = "2", -- Brace/table formatting max_line_length = "120", trailing_table_separator = "always", table_separator_style = "comma", align_array_table = "false", align_continuous_rect_table_field = "false", align_call_args = "false", align_function_params = "false", space_around_table_field_list = "false", }, }, diagnostics = { globals = {'vim',}, disable = {'missing-fields',}, }, runtime = { version = "LuaJIT", }, workspace = { library = vim.api.nvim_get_runtime_file("", true), }, }, }, }, rust_analyzer = { settings = { ['rust-analyzer'] = { check = { command = "clippy", }, completion = { autoimport = { enable = false, }, snippets = { custom = nil, }, }, }, }, }, tailwindcss = {}, -- nil_ls = {}, bashls = { filetypes = {'bash', 'sh', 'zsh',}, }, ts_ls = { init_options = { preferences = { includeInlayParameterNameHints = 'all', includeInlayParameterNameHintsWhenArgumentMatchesName = false, includeInlayFunctionParameterTypeHints = true, includeInlayVariableTypeHints = true, includeInlayPropertyDeclarationTypeHints = true, includeInlayFunctionLikeReturnTypeHints = true, includeInlayEnumMemberValueHints = true, importModuleSpecifierPreference = 'non-relative', }, }, }, } -- Code to run whenever a language server attaches to a buffer local on_attach = function(lsp_client, buffer_number) -- Setup Signs vim.diagnostic.config({ signs = { text = { [vim.diagnostic.severity.ERROR] = "🛑", [vim.diagnostic.severity.WARN] = "âš ī¸", [vim.diagnostic.severity.HINT] = "💡", [vim.diagnostic.severity.INFO] = "â„šī¸", }, }, }) -- Enable inlay hints if lsp_client.server_capabilities.inlayHintProvider then vim.lsp.inlay_hint.enable(true) end -- Setup Keybinds local keymap_opts = {buffer = buffer_number,} vim.keymap.set('n', 'g[', vim.diagnostic.goto_prev, keymap_opts) vim.keymap.set('n', 'g]', vim.diagnostic.goto_next, keymap_opts) vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, keymap_opts) vim.keymap.set('n', 'gh', vim.lsp.buf.hover, keymap_opts) vim.keymap.set('i', '', vim.lsp.buf.hover, keymap_opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, keymap_opts) vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, keymap_opts) vim.keymap.set('n', 'gD', vim.lsp.buf.type_definition, keymap_opts) vim.keymap.set('n', 'gR', vim.lsp.buf.references, keymap_opts) vim.keymap.set('n', 'gr', vim.lsp.buf.rename, keymap_opts) vim.keymap.set('n', 'g0', vim.lsp.buf.document_symbol, keymap_opts) vim.keymap.set('n', 'gW', vim.lsp.buf.workspace_symbol, keymap_opts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, keymap_opts) --vim.keymap.set('n', 'a', rt.code_action_group.code_action_group, { buffer = bufnr }) -- vim.keymap.set('n', 'g-', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) end, keymap_opts) -- Format on save if lsp_client:supports_method('textDocument/formatting') then local fmt_group = vim.api.nvim_create_augroup('LspFormatOnSave_' .. buffer_number, {clear = true,}) vim.api.nvim_create_autocmd('BufWritePre', { group = fmt_group, buffer = buffer_number, callback = function() local ft_format_opts = { lua = {tabSize = 2, insertSpaces = true,}, } vim.lsp.buf.format({ async = false, formatting_options = ft_format_opts[vim.bo.filetype], }) end, }) end vim.keymap.set('n', 'gf', function() vim.lsp.buf.format {async = true,} end, keymap_opts) end return { "neovim/nvim-lspconfig", dependencies = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", "j-hui/fidget.nvim", "hrsh7th/cmp-nvim-lsp", }, opts = { inlay_hints = { enabled = true, }, }, config = function() require("mason").setup({ -- Prefer system binaries PATH = "append", ui = { icons = { package_installed = "", package_pending = "ī‚Š", package_uninstalled = "ī„Œ", }, }, }) -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() -- capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = false local mason_servers = vim.tbl_filter( function(name) return name ~= "rust_analyzer" end, vim.tbl_keys(servers) ) require("mason-lspconfig").setup { ensure_installed = mason_servers, automatic_enable = false, } for name, conf in pairs(servers) do local cfg = vim.tbl_deep_extend("force", { capabilities = capabilities, on_attach = on_attach, }, conf) vim.lsp.config(name, cfg) vim.lsp.enable(name) end -- LSP Status Information require('fidget').setup({ notification = { window = { avoid = { "NvimTree" }, }, }, }) end, }