local lspkind = require('lspkind') local lspconfig = require("lspconfig") local cmp = require('cmp') local capabilities = require("cmp_nvim_lsp").default_capabilities() require("mason").setup({ registries = { "github:mason-org/mason-registry", "github:Crashdummyy/mason-registry", }, }) require("mason-lspconfig").setup() cmp.setup({ snippet = { expand = function(args) require('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.abort(), [''] = cmp.mapping.confirm({ select = true }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, }), formatting = { format = lspkind.cmp_format({ mode = 'symbol_text', maxwidth = 50, ellipsis_char = '...', show_labelDetails = true, }) }, window = { completion = { winhighlight = "Normal:CmpNormal,FloatBorder:CmpBorder", border = { { "╭", "CmpBorder" }, { "─", "CmpBorder" }, { "╮", "CmpBorder" }, { "│", "CmpBorder" }, { "╯", "CmpBorder" }, { "─", "CmpBorder" }, { "╰", "CmpBorder" }, { "│", "CmpBorder" }, }, scrollbar = false, }, documentation = { winhighlight = "Normal:CmpDocNormal,FloatBorder:CmpDocBorder", border = { { "╭", "CmpDocBorder" }, { "─", "CmpDocBorder" }, { "╮", "CmpDocBorder" }, { "│", "CmpDocBorder" }, { "╯", "CmpDocBorder" }, { "─", "CmpDocBorder" }, { "╰", "CmpDocBorder" }, { "│", "CmpDocBorder" }, }, }, }, }) -- vim.api.nvim_set_hl(0, "CmpNormal", { bg = "#E0E2EB", blend = 0 }) -- vim.api.nvim_set_hl(0, "CmpBorder", { fg = "#E0E2EB", bg = "#E0E2EB", blend = 0 }) -- vim.api.nvim_set_hl(0, "CmpDocNormal", { bg = "#E0E2EB", blend = 0 }) -- vim.api.nvim_set_hl(0, "CmpDocBorder", { fg = "#E0E2EB", bg = "#E0E2EB", blend = 0 }) local options = { buffer = bufnr, remap = false } local on_attach = function(client, bufnr) -- if vim.bo.filetype == 'csharp' or vim.bo.filetype == 'cs' or vim.bo.filetype == "c" or vim.bo.filetype == "cpp" or vim.bo.filetype == "swift" or vim.bo.filetype == "swiftinterface" or vim.bo.filetype == 'zig' then client.server_capabilities.semanticTokensProvider = nil -- end vim.keymap.set('n', 'gd', 'lua require"telescope.builtin".lsp_definitions({jump_type="vsplit"})', options) -- vim.keymap.set('n', 'gd', function() vim.lsp.buf.definition() end, options) vim.keymap.set("n", "gr", function() vim.lsp.buf.references() end, options) vim.keymap.set("n", "bh", function() vim.lsp.buf.hover() end, options) vim.keymap.set("n", "ca", function() vim.lsp.buf.code_action() end, options) vim.keymap.set("n", "cr", function() vim.lsp.buf.rename() end, options) vim.keymap.set("n", "gv", function() vim.lsp.buf.signature_help() end, options) vim.keymap.set("n", "gl", function() vim.diagnostic.open_float() end, options) vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, options) vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, options) end vim.lsp.config("roslyn", { on_attach = on_attach, capabilities = capabilities, settings = { ["csharp|inlay_hints"] = { csharp_enable_inlay_hints_for_implicit_object_creation = true, csharp_enable_inlay_hints_for_implicit_variable_types = true, }, ["csharp|code_lens"] = { dotnet_enable_references_code_lens = true, }, }, }) vim.api.nvim_create_autocmd('BufWritePre', { callback = function() vim.lsp.buf.format { async = false, } end, }) vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) client.server_capabilities.semanticTokensProvider = nil end }) vim.lsp.config("eslint_lsp", { experimental = { useFlatConfig = true }, on_attach = function(_client, bufnr) vim.api.nvim_create_autocmd("BufWritePre", { buffer = bufnr, command = "EslintFixAll", }) on_attach(_client, bufnr) end, filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx", "vue", "html", "markdown", "json", "jsonc", "yaml", "toml", "xml", "gql", "graphql", "astro", "svelte", "css", "less", "scss", "pcss", "postcss" }, } ) vim.lsp.config('rust_analyzer', { on_attach = on_attach, capabilities = capabilities, settings = { ['rust-analyzer'] = { diagnostics = { enable = false; } } } }) vim.lsp.config('ocamllsp', { on_attach = on_attach, capabilities = capabilities, cmd = { 'ocamllsp' }, filetypes = { 'ocaml', 'reason' }, }) vim.lsp.enable('ocamllsp') vim.lsp.config('alive', { on_attach = on_attach, capabilities = capabilities, filetypes = { 'lisp' }, cmd = { 'alive-lsp' }, }) vim.lsp.enable('alive') vim.lsp.enable('rust_analyzer') vim.lsp.config("ols", { on_attach = on_attach, capabilities = capabilities, init_options = { checker_args = "-strict-style", collections = { { name = "shared", path = vim.fn.expand('$HOME/Odin/shared') } }, }, }) vim.lsp.enable("ols") vim.lsp.config('hls', { -- settings = { -- haskell = { -- cabalFormattingProvider = "cabal-fmt", -- formattingProvider = "ormolu", -- }, -- }, filetypes = { 'haskell', 'lhaskell', 'cabal' }, }) vim.lsp.enable('hls') local servers = { "elixir-ls", "ada_ls", "zls", "bashls", "gopls", "clangd", "lua_ls", "fortls", "prettier", "rubyfmt", "tailwindcss", "cmake", "dockerls", "ts_ls", "eslint", "ruby_lsp", "yamlls", "yamlfix", "yamlfmt", "yamllint", "erlangls", "jsonls", } for _, lsp in ipairs(servers) do vim.lsp.config(lsp, { on_attach = on_attach, capabilities = capabilities }) vim.lsp.enable(lsp) end vim.diagnostic.config({ virtual_text = true }) vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = true } ) vim.lsp.inlay_hint.enable(false) vim.lsp.commands["editor.action.showReferences"] = function(command, ctx) local locations = command.arguments[3] local client = vim.lsp.get_client_by_id(ctx.client_id) if locations and #locations > 0 then local items = vim.lsp.util.locations_to_items(locations, client.offset_encoding) vim.fn.setloclist(0, {}, " ", { title = "References", items = items, context = ctx }) vim.api.nvim_command("lopen") end end