1return { 2 'neovim/nvim-lspconfig', 3 dependencies = { 4 'williamboman/mason-lspconfig.nvim', 5 "williamboman/mason.nvim", 6 'neovim/nvim-lspconfig', 7 'hrsh7th/cmp-nvim-lsp', 8 'hrsh7th/cmp-buffer', 9 'hrsh7th/cmp-path', 10 'hrsh7th/cmp-cmdline', 11 'micangl/cmp-vimtex', 12 'hrsh7th/nvim-cmp', 13 'windwp/nvim-autopairs', 14 { 15 'L3MON4D3/LuaSnip', 16 build = "make install_jsregexp", 17 dependencies = { 18 'rafamadriz/friendly-snippets' 19 }, 20 }, 21 'j-hui/fidget.nvim', 22 }, 23 config = function() 24 require('fidget').setup({}) 25 require("nvim-autopairs").setup({}) 26 require("mason").setup({ 27 PATH="append", 28 }) 29 require("mason-lspconfig").setup({ 30 ensure_installed = { 31 'lua_ls', 32 'rust_analyzer', 33 'jedi_language_server', 34 'fortls', 35 }, 36 handlers = { 37 function(server_name) 38 local cmp_nvim_lsp = require("cmp_nvim_lsp") 39 local capabilities = vim.tbl_deep_extend( 40 "force", 41 {}, 42 vim.lsp.protocol.make_client_capabilities(), 43 cmp_nvim_lsp.default_capabilities()) 44 45 require("lspconfig")[server_name].setup { 46 capabilities = capabilities 47 } 48 require'lspconfig'.fortls.setup{ 49 cmd = { 50 'fortls', 51 '--hover_signature', 52 '--hover_language=fortran', 53 '--use_signature_help', 54 '--lowercase_intrinsics' 55 }, 56 } 57 require("lspconfig").lua_ls.setup({ 58 settings = { 59 Lua = { 60 diagnostics = { 61 -- Get the language server to recognize the `vim` global 62 globals = { 'vim' }, 63 }, 64 workspace = { 65 checkThirdParty = false, 66 library = { 67 vim.env.VIMRUNTIME 68 } 69 } 70 } 71 } 72 }) 73 end, 74 } 75 }) 76 77 78 local has_words_before = function() 79 unpack = unpack or table.unpack 80 local line, col = unpack(vim.api.nvim_win_get_cursor(0)) 81 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil 82 end 83 84 85 local cmp = require('cmp') 86 local cmp_autopairs = require('nvim-autopairs.completion.cmp') 87 88 89 local luasnip = require('luasnip') 90 -- require("luasnip.loaders.from_vscode").lazy_load() 91 92 cmp.event:on( 93 'confirm_done', 94 cmp_autopairs.on_confirm_done() 95 ) 96 local cmp_select = { behaviour = cmp.SelectBehavior.Insert } 97 cmp.setup({ 98 snippet = { 99 expand = function(args) 100 require('luasnip').lsp_expand(args.body) -- For `luasnip` users. 101 end, 102 }, 103 mapping = cmp.mapping.preset.insert({ 104 ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select), 105 ['<C-n>'] = cmp.mapping.select_next_item(cmp_select), 106 ['<CR>'] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace, }), 107 ['<C-Space>'] = cmp.mapping.complete(), 108 ['<C-u>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), 109 ['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), 110 ["<Tab>"] = cmp.mapping(function(fallback) 111 if cmp.visible() then 112 cmp.select_next_item() 113 -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() 114 -- they way you will only jump inside the snippet region 115 elseif luasnip.expand_or_jumpable() then 116 luasnip.expand_or_jump() 117 elseif has_words_before() then 118 cmp.complete() 119 else 120 fallback() 121 end 122 end, { "i", "s" }), 123 124 ["<S-Tab>"] = cmp.mapping(function(fallback) 125 if cmp.visible() then 126 cmp.select_prev_item() 127 elseif luasnip.jumpable(-1) then 128 luasnip.jump(-1) 129 else 130 fallback() 131 end 132 end, { "i", "s" }), 133 }), 134 sources = cmp.config.sources({ 135 { name = 'nvim_lsp' }, 136 { name = 'vimtex' }, 137 { name = 'luasnip' }, -- For luasnip users. 138 }, { 139 { name = 'buffer' }, 140 }) 141 }) 142 cmp.setup.cmdline({ '/', '?' }, { 143 mapping = cmp.mapping.preset.cmdline(), 144 sources = { 145 { name = 'buffer' } 146 } 147 }) 148 149 -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). 150 cmp.setup.cmdline(':', { 151 mapping = cmp.mapping.preset.cmdline(), 152 sources = cmp.config.sources({ 153 { name = 'path' } 154 }, { 155 { name = 'cmdline' } 156 }) 157 }) 158 159 vim.diagnostic.config({ 160 update_in_insert = true, 161 float = { 162 focusable = false, 163 style = "minimal", 164 border = "rounded", 165 source = "always", 166 header = "", 167 prefix = "", 168 } 169 }) 170 end 171}