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