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