Summary Files Commits Branches @commit @diff @stats
path: root / lua / plugins / lsp.lua
diff options
context:
space:
mode:
1 files changed, 92 insertions, 10 deletions
-rw-r--r--lua/plugins/lsp.lua102
diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua
index 8144527..d778448 100644
--- a/lua/plugins/lsp.lua
+++ b/lua/plugins/lsp.lua
@@ -9,8 +9,10 @@ vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { callback = functi
end})
return {
+ -- Syntax parsing (for highlighting)
{
- "nvim-treesitter/nvim-treesitter", -- Advanced syntax parsing
+ "nvim-treesitter/nvim-treesitter",
+ lazy = false,
build = ":TSUpdate",
opts = {
ensure_installed = "all",
@@ -23,19 +25,99 @@ return {
require("nvim-treesitter.configs").setup(opts)
end,
},
+ -- LSP server utilisation
{
"neovim/nvim-lspconfig",
- enabled = false, -- Figure out config property
- event = "LazyFile",
- -- dependencies = {
- -- "mason.nvim",
- -- { "williamboman/mason-lspconfig.nvim", config = function() end },
- -- },
+ dependencies = { 'VonHeikemen/lsp-zero.nvim' },
+ lazy = true,
opts = {
- servers = {
- awk_ls = { settings = {}, },
+ awk_ls = { },
+ 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.nvim', config = true, },
+ {
+ 'williamboman/mason-lspconfig.nvim',
+ lazy = false,
+ dependencies = { 'neovim/nvim-lspconfig' },
+ opts = {
+ handlers = {
+ function(server_name)
+ require('lspconfig')[server_name].setup({})
+ end,
},
},
- setup = {},
},
}