require("neodev").setup({ library = { plugins = { "nvim-dap-ui" }, types = true } }) local lsp = require("lsp-zero") -- lsp.preset("recommended") -- use csharp_ls language server("https://github.com/razzmatazz/csharp-language-server") -- i'm using this instead of Mason because the version of it is old in Mason, -- the version here is maintained by dotnet tool and it's the latest -- lsp.configure('csharp_ls', { -- force_setup = true -- }) lsp.configure('clangd', { cmd = { 'clangd', '--offset-encoding=utf-16' }, }) -- -- -- Fix Undefined global 'vim' -- lsp.configure('lua-language-server', { -- settings = { -- Lua = { -- diagnostics = { -- globals = { 'vim' } -- } -- } -- } -- }) -- this code makes it so that the css language server doesn't complain about tailwindcss classes lsp.configure("cssls", { settings = { css = { lint = { unknownAtRules = "ignore" } }, scss = { lint = { unknownAtRules = "ignore" } }, less = { lint = { unknownAtRules = "ignore" } } } }) lsp.set_server_config({ capabilities = { textDocument = { foldingRange = { dynamicRegistration = false, lineFoldingOnly = true } } } }) local cmp = require('cmp') local cmp_action = lsp.cmp_action() local cmp_format = lsp.cmp_format() require('luasnip.loaders.from_vscode').lazy_load() vim.opt.completeopt = {'menu', 'menuone', 'noselect'} cmp.setup({ formatting = cmp_format, preselect = 'item', completion = { completeopt = 'menu,menuone,noinsert' }, window = { documentation = cmp.config.window.bordered(), }, sources = { {name = 'path'}, {name = 'nvim_lsp'}, {name = 'nvim_lua'}, {name = 'buffer', keyword_length = 3}, {name = 'luasnip', keyword_length = 2}, }, mapping = cmp.mapping.preset.insert({ -- confirm completion item [''] = cmp.mapping.confirm({select = false, behavior = cmp.ConfirmBehavior.Insert}), [''] = cmp.mapping.confirm({select = false, behavior = cmp.ConfirmBehavior.Replace}), -- toggle completion menu [''] = cmp_action.toggle_completion(), -- tab complete -- [''] = cmp_action.tab_complete(), [''] = cmp.mapping.select_prev_item(), -- navigate between snippet placeholder [''] = cmp_action.luasnip_jump_forward(), [''] = cmp_action.luasnip_jump_backward(), -- scroll documentation window [''] = cmp.mapping.scroll_docs(5), [''] = cmp.mapping.scroll_docs(-5), }), }) local navic = require("nvim-navic") lsp.on_attach(function(client, bufnr) local opts = { buffer = bufnr, remap = false } lsp.default_keymaps({buffer = bufnr}) if client.server_capabilities.documentSymbolProvider then navic.attach(client, bufnr) end vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) vim.keymap.set("n", "dc", function() vim.lsp.buf.hover() end, opts) vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) vim.keymap.set("n", "ed", function() vim.diagnostic.open_float() end, opts) vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) -- for the code action key map to work you need to change key binding('.' symbol) of your terminal, otherwise it won't work vim.keymap.set("n", "", function() vim.lsp.buf.code_action() end, opts) vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) -- sometimes lsp fails, we can restart it with this keymap vim.keymap.set('n', "lr", vim.cmd.LspRestart, opts) end) require("mason").setup({}); require("mason-lspconfig").setup({ ensure_installed = {'tsserver', 'tailwindcss', 'svelte', 'lua_ls'}, handlers = { lsp.default_setup, lua_ls = function() local lua_opts = lsp.nvim_lua_ls() require('lspconfig').lua_ls.setup(lua_opts) end, } }) lsp.set_sign_icons({ error = '✘', warn = '▲', hint = '⚑', info = '' }) vim.diagnostic.config({ virtual_text = false, severity_sort = true, float = { style = 'minimal', border = 'rounded', source = 'always', header = '', prefix = '', }, }) -- because we want to add another source, the ones that are set by lsp-zero will be lost, -- we need to add them again together with the new one