nvim dot files

format

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