nvim dot files
at main 146 lines 5.4 kB view raw
1return { 2 { 3 "williamboman/mason.nvim", 4 config = function() 5 require('mason').setup() 6 end 7 }, 8 9 { 10 "williamboman/mason-lspconfig.nvim", 11 dependencies = { 12 "williamboman/mason.nvim" 13 }, 14 opts = { 15 ensure_installed = { "pyright", "rust_analyzer", "zls", "intelephense", "clangd", "lua_ls" }, 16 automatic_enable = false, 17 }, 18 }, 19 20 { 21 "neovim/nvim-lspconfig", 22 config = function() 23 local lspconfig = require('lspconfig') 24 local capabilities = require('cmp_nvim_lsp').default_capabilities() 25 26 local on_attach = function(client, bufnr) 27 local bufopts = { noremap = true, silent = true, buffer = bufnr } 28 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) 29 vim.keymap.set('n', '<C-[>', vim.lsp.buf.references, bufopts) 30 vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) 31 vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) 32 vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) 33 vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) 34 35 vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, bufopts) 36 37 vim.keymap.set({'n','v'}, '<space>ca', function() 38 vim.lsp.buf.code_action({}, bufnr) 39 end, bufopts) 40 41 vim.keymap.set({'n','v'}, '<space>f', function() 42 vim.lsp.buf.format({ async = true, bufnr = bufnr }) 43 end, bufopts) 44 end 45 46 lspconfig.pyright.setup({ on_attach = on_attach, capabilities = capabilities }) 47 lspconfig.intelephense.setup({ on_attach = on_attach, capabilities = capabilities }) 48 lspconfig.clangd.setup({ on_attach = on_attach, capabilities = capabilities }) 49 lspconfig.lua_ls.setup({ on_attach = on_attach, capabilities = capabilities }) 50 51 lspconfig.gopls.setup({ 52 on_attach = on_attach, 53 capabilities = capabilities, 54 settings = { 55 gopls = { 56 analyses = { 57 unusedparams = true, 58 }, 59 staticcheck = true, 60 gofumpt = true, 61 }, 62 }, 63 }) 64 65 lspconfig.rust_analyzer.setup({ 66 on_attach = on_attach, 67 capabilities = capabilities, 68 settings = { 69 ["rust-analyzer"] = { 70 imports = { 71 granularity = { 72 group = "module", 73 }, 74 prefix = "self", 75 }, 76 cargo = { 77 buildScripts = { 78 enable = true, 79 }, 80 }, 81 procMacro = { 82 enable = true 83 }, 84 } 85 } 86 }) 87 88 lspconfig.zls.setup({ 89 on_attach = on_attach, 90 capabilities = capabilities, 91 settings = { 92 zls = { 93 zig_exe_path = (function() 94 local handle = io.popen('which zig 2> /dev/null') 95 if handle then 96 local result = handle:read("*a") 97 handle:close() 98 -- Remove trailing newline 99 return result:gsub("[\n\r]", "") 100 end 101 -- Fallback to a default path or return nil if which command fails 102 return nil 103 end)(), 104 } 105 } 106 }) 107 end, 108 }, 109 110 { 111 'hrsh7th/nvim-cmp', 112 dependencies = { 113 'hrsh7th/cmp-nvim-lsp', 114 'hrsh7th/cmp-buffer', 115 'hrsh7th/cmp-path', 116 'L3MON4D3/LuaSnip', 117 }, 118 config = function() 119 local cmp = require('cmp') 120 local luasnip = require('luasnip') 121 122 cmp.setup({ 123 snippet = { 124 expand = function(args) 125 luasnip.lsp_expand(args.body) 126 end, 127 }, 128 mapping = cmp.mapping.preset.insert({ 129 ['<C-b>'] = cmp.mapping.scroll_docs(-4), 130 ['<C-f>'] = cmp.mapping.scroll_docs(4), 131 ['<C-Space>'] = cmp.mapping.complete(), 132 ['<C-e>'] = cmp.mapping.abort(), 133 ['<CR>'] = cmp.mapping.confirm({ select = true }), 134 ['<C-p>'] = cmp.mapping.select_prev_item(), 135 ['<C-n>'] = cmp.mapping.select_next_item(), 136 }), 137 sources = cmp.config.sources({ 138 {name = 'nvim_lsp' }, 139 {name = 'luasnip' }, 140 {name = 'buffer' }, 141 {name = 'path' }, 142 }) 143 }) 144 end, 145 }, 146}