function setup_attach() vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function (ev) -- local lspconfig = require('lspconfig') -- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' local opts = { buffer = ev.buf } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "gf", function() vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf(), async = false }) end, { buffer = bufnr, desc = "[lsp] format" }) -- vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) -- vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) -- vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) end, }) end function setup_cmp() local cmp = require('cmp') local kind_icons = { Text = "", Method = "󰆧", Function = "󰊕", Constructor = "", Field = "󰇽", Variable = "󰂡", Class = "󰠱", Interface = "", Module = "", Property = "󰜢", Unit = "", Value = "󰎠", Enum = "", Keyword = "󰌋", Snippet = "", Color = "󰏘", File = "󰈙", Reference = "", Folder = "󰉋", EnumMember = "", Constant = "󰏿", Struct = "", Event = "", Operator = "󰆕", TypeParameter = "󰅲", } cmp.setup({ snippet = { expand = function(args) -- require('luasnip').lsp_expand(args.body) require('snippy').expand_snippet(args.body) end, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, 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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'snippy' }, { name = 'path' }, { name = 'emoji' }, }, { { name = 'buffer' }, }), formatting = { format = function(entry, vim_item) -- Kind icons vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatenates the icons with the name of the item kind -- vim_item.kind = kind_icons[vim_item.kind] -- Source vim_item.menu = ({ buffer = "📝", nvim_lsp = "🔎", luasnip = "[LuaSnip]", nvim_lua = "[Lua]", latex_symbols = "[LaTeX]", })[entry.source.name] return vim_item end }, }) cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) end return { { "j-hui/fidget.nvim", name = "fidget", opts = {} }, { 'kevinhwang91/nvim-ufo', dependencies = { 'kevinhwang91/promise-async', }, }, { "neovim/nvim-lspconfig", dependencies = { 'neovim/nvim-lspconfig', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', 'hrsh7th/nvim-cmp', 'saadparwaiz1/cmp_luasnip', "ray-x/lsp_signature.nvim", 'dcampos/nvim-snippy', 'dcampos/cmp-snippy', 'fidget', 'kevinhwang91/nvim-ufo', }, config = function() local lspconfig = require('lspconfig') vim.diagnostic.config({ virtual_text = { prefix = "👈", }, signs = { text = { [vim.diagnostic.severity.ERROR] = "🆒", [vim.diagnostic.severity.WARN] = "😞", [vim.diagnostic.severity.HINT] = "🆘", [vim.diagnostic.severity.INFO] = "🆓", CodeAction = "🈁", } }, }) -- Check out trouble vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) vim.keymap.set('n', ']d', vim.diagnostic.goto_next) setup_attach() setup_cmp() -- This is required by UFO local pre_capabilities = vim.lsp.protocol.make_client_capabilities() pre_capabilities.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true } local capabilities = vim.tbl_deep_extend( "force", {}, pre_capabilities, require('cmp_nvim_lsp').default_capabilities() ) local def_set_servers = { "ts_ls", "svelte", "zls", "gopls", "cssls", "pylsp", "rust_analyzer", "dartls", "ols", "jdtls", "biome", "ocamllsp" } for _, server_name in ipairs(def_set_servers) do lspconfig[server_name].setup({ capabilities = capabilities, }) end lspconfig.tailwindcss.setup({ capabilities = capabilities, init_options = { userLanguages = { elixir = "phoenix-heex", heex = "phoenix-heex", -- other languages }, }, filetypes = { "css", "scss", "sass", "html", "heex", "elixir", "javascript", "javascriptreact", "typescript", "typescriptreact", "svelte", "ocaml" }, }) lspconfig.elixirls.setup({ cmd = { "elixir-ls" }, capabilities = capabilities, }) local jdk_home = "/usr/lib/jvm/java-17-openjdk" -- Your actual jdk path local util = require('lspconfig/util') -- lspconfig.kotlin_language_server.setup { -- cmd_env = { -- PATH = jdk_home .. "/bin:" .. vim.env.PATH, -- JAVA_HOME = jdk_home, -- }, -- init_options = { -- storagePath = util.path.join(vim.env.XDG_DATA_HOME, "nvim-data"), -- }, -- capabilities = capabilities, -- } -- lspconfig.jdtls.setup { -- cmd_env = { -- PATH = jdk_home .. "/bin:" .. vim.env.PATH, -- JAVA_HOME = jdk_home, -- }, -- init_options = { -- storagePath = util.path.join(vim.env.XDG_DATA_HOME, "nvim-data"), -- }, -- capabilities = capabilities, -- } -- -- UFO stuff (folding) -- local handler = function(virtText, lnum, endLnum, width, truncate) local newVirtText = {} local suffix = (' 󰁂 %d '):format(endLnum - lnum) local sufWidth = vim.fn.strdisplaywidth(suffix) local targetWidth = width - sufWidth local curWidth = 0 for _, chunk in ipairs(virtText) do local chunkText = chunk[1] local chunkWidth = vim.fn.strdisplaywidth(chunkText) if targetWidth > curWidth + chunkWidth then table.insert(newVirtText, chunk) else chunkText = truncate(chunkText, targetWidth - curWidth) local hlGroup = chunk[2] table.insert(newVirtText, {chunkText, hlGroup}) chunkWidth = vim.fn.strdisplaywidth(chunkText) -- str width returned from truncate() may less than 2nd argument, need padding if curWidth + chunkWidth < targetWidth then suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth) end break end curWidth = curWidth + chunkWidth end table.insert(newVirtText, {suffix, 'MoreMsg'}) return newVirtText end require('ufo').setup({ fold_virt_text_handler = handler }) -- vim.keymap.set('n', 'zf', require('ufo').closeFoldsWith) vim.keymap.set('n', 'zR', require('ufo').openAllFolds) vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) -- -- END UFO stuff (folding) -- vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) if not client then return end if client.supports_method('textDocument/formatting') then -- Format the current buffer on save -- vim.api.nvim_create_autocmd('BufWritePre', { -- buffer = args.buf, -- callback = function() -- vim.lsp.buf.format({bufnr = args.buf, id = client.id}) -- end, -- }) end end, }) end, }, { "ray-x/lsp_signature.nvim", event = "InsertEnter", opts = { bind = true, handler_opts = { border = "rounded" } }, config = function(_, opts) require'lsp_signature'.setup(opts) end }, { "folke/trouble.nvim", opts = {}, -- for default options, refer to the configuration section for custom setup. cmd = "Trouble", keys = { { "xx", "Trouble diagnostics toggle", desc = "Diagnostics (Trouble)", }, { "xX", "Trouble diagnostics toggle filter.buf=0", desc = "Buffer Diagnostics (Trouble)", }, { "cs", "Trouble symbols toggle focus=false", desc = "Symbols (Trouble)", }, { "cl", "Trouble lsp toggle focus=false win.position=right", desc = "LSP Definitions / references / ... (Trouble)", }, { "xL", "Trouble loclist toggle", desc = "Location List (Trouble)", }, { "xQ", "Trouble qflist toggle", desc = "Quickfix List (Trouble)", }, }, } }