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