Summary Files Commits Branches @commit @diff @stats
path: root / lua / plugins / lsp.lua
blob: 1aa098d6cdfe5dcbcc0a4a4668fe703d833885ca (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
-- Thanks https://stackoverflow.com/a/70760302/12036073
vim.o.updatetime = 300
vim.diagnostic.config({
	virtual_text = false,
	float = { focus = false },
})
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { callback = function(ev)
	vim.diagnostic.open_float(nil)
end})

return {
	-- Syntax parsing (for highlighting)
	{
		"nvim-treesitter/nvim-treesitter",
		lazy = false,
		build = ":TSUpdate",
		opts = {
			ensure_installed = "all",
			ignore_install = { "liquidsoap", "tlaplus", "yaml" }, -- Can't compile
			highlight = { enable = true },
			incremental_selection = { enable = true },
			textobjects = { enable = true },
		},
		config = function(_, opts)
			require("nvim-treesitter.configs").setup(opts)
		end,
	},
	-- LSP server utilisation
	{
		"neovim/nvim-lspconfig",
		dependencies = { 'VonHeikemen/lsp-zero.nvim', 'williamboman/mason-lspconfig.nvim' },
		lazy = false,
		opts = { -- :h lspconfig-all
			awk_ls = { },
			bashls = { },
			lua_ls = { },
		},
		config = function(_, opts)
			for k,v in pairs(opts) do
				require("lspconfig")[k].setup(v)
			end
		end,
	},
	-- Auto-completion
	{
		'hrsh7th/cmp-nvim-lsp',
		config = true,
		lazy = true
	},
	{
		'hrsh7th/nvim-cmp',
		lazy = false,
		opts = {
			sources = { { name = 'nvim_lsp' } },
			snippet = {
				expand = function(args)
				  vim.snippet.expand(args.body)
				end,
			},
		},
		config = function(_, opts)
			local cmp = require('cmp')
			opts.mapping = cmp.mapping.preset.insert({
			-- 	-- `Enter` key to confirm completion
			-- 	['<CR>'] = cmp.mapping.confirm({select = false}),
			--
			-- 	-- Ctrl+Space to trigger completion menu
				['<C-Space>'] = cmp.mapping.complete(),
			--
			-- 	-- Navigate between snippet placeholder
			-- 	['<C-f>'] = cmp_action.vim_snippet_jump_forward(),
			-- 	['<C-b>'] = cmp_action.vim_snippet_jump_backward(),
			--
			-- 	-- Scroll up and down in the completion documentation
			-- 	['<C-u>'] = cmp.mapping.scroll_docs(-4),
			-- 	['<C-d>'] = cmp.mapping.scroll_docs(4),
			})
			cmp.setup(opts)
		end,
	},
	-- Helper functions
	{
		'VonHeikemen/lsp-zero.nvim',
		branch = 'v3.x',
		lazy = true,
		dependencies = { 'hrsh7th/cmp-nvim-lsp' },
		opts = {
			sign_text = true,
			capabailities = "",
			lsp_attach = function(client, bufnr)
				local opts = {buffer = bufnr}

				vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
				vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
				vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
				vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
				vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
				vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
				vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
				vim.keymap.set('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
				vim.keymap.set({'n', 'x'}, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
				vim.keymap.set('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
			end,
		},
		config = function(_, opts)
			opts.capabilities = require('cmp_nvim_lsp').default_capabilities()
			require("lsp-zero").extend_lspconfig(opts)
		end,
	},
	-- Download plugins automatically
	{
		'williamboman/mason-lspconfig.nvim',
		lazy = true,
		opts = {
			automatic_installation = true,
			handlers = {
				function(server_name)
					require('lspconfig')[server_name].setup({})
				end,
			},
		},
	},
	{
		'williamboman/mason.nvim',
		dependencies = { 'williamboman/mason-lspconfig.nvim' },
		lazy = false,
		config = true,
	},
}