summaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/confs/nvimlsp.vim
blob: d91d17a9352710e7df89e58e56b99791f6920417 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
lua << EOF
-- Set up nvim-cmp.
local cmp = require('cmp')
local lspkind = require('lspkind')

cmp.setup({
	formatting = {
		format = lspkind.cmp_format({
			mode = 'symbol_text',
			preset = 'codicons',
			maxwidth = 50,
			ellipsis_char = '...',
			before = function (_, vim_item)
					return vim_item
				end
		})
	},
	snippet = {
		expand = function(args)
			require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
		end,
	},

	window = {
		completion = cmp.config.window.bordered(),
		documentation = cmp.config.window.bordered(),
	},

	mapping = cmp.mapping.preset.insert({
	['<C-b>'] = cmp.mapping.scroll_docs(-4),
	['<C-f>'] = cmp.mapping.scroll_docs(4),
	['<C-Space>'] = cmp.mapping.complete(),
	['<C-e>'] = cmp.mapping.abort(),
	['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
	["<Tab>"] = cmp.mapping(function(fallback)
	if cmp.visible() then
		cmp.select_next_item()
	else
		fallback()
		end
		end, { "i", "s" }),
	["<S-Tab>"] = cmp.mapping(function(fallback)
	if cmp.visible() then
		cmp.select_prev_item()
	else
		fallback()
		end
		end, { "i", "s" }),
	}),
	sources = cmp.config.sources({
	{ name = 'luasnip' },
	{ name = 'nvim_lsp' }
	})
})

-- Set up lspconfig.
require("mason").setup()

local capabilities = require('cmp_nvim_lsp').default_capabilities()
local masonlsp = require("mason-lspconfig")

masonlsp.setup {
	ensure_installed = { 'clangd', 'tsserver'},
	automatic_installation = true,
	handlers =  {
		function (server_name)
			require("lspconfig")[server_name].setup {
				capabilities = capabilities
			}
			end

			-- Next, you can provide a dedicated handler for specific servers.
			-- For example, a handler override for the `rust_analyzer`:
			-- ["rust_analyzer"] = function ()
			--     require("rust-tools").setup {}
			-- end
	}
	}
EOF