From 1c5dffb8ed75525804b11ba153ebc863c7e87336 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Mon, 20 Nov 2023 08:02:47 -0700 Subject: [PATCH] Have on_attach/capabilites associated with each LSP. --- jrpotter/neovim/lang/lean.nix | 2 +- jrpotter/neovim/lang/nix.nix | 2 +- jrpotter/neovim/lua/init/lsp.lua | 22 ++++++++++++++++++++++ jrpotter/neovim/lua/init/lua.lua | 2 +- jrpotter/neovim/lua/init/python.lua | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 jrpotter/neovim/lua/init/lsp.lua diff --git a/jrpotter/neovim/lang/lean.nix b/jrpotter/neovim/lang/lean.nix index 1dbd8b1..51f0414 100644 --- a/jrpotter/neovim/lang/lean.nix +++ b/jrpotter/neovim/lang/lean.nix @@ -8,7 +8,7 @@ let "Julian/lean.nvim"; config = '' lua << EOF - require('lean').setup { + require('init.lsp').setup(require('lean')) { abbreviations = { builtin = true }, mappings = true, } diff --git a/jrpotter/neovim/lang/nix.nix b/jrpotter/neovim/lang/nix.nix index 48be98b..75ceeb4 100644 --- a/jrpotter/neovim/lang/nix.nix +++ b/jrpotter/neovim/lang/nix.nix @@ -2,7 +2,7 @@ { programs.neovim = { nvim-lspconfig = '' - require('lspconfig').nil_ls.setup {} + require('init.lsp').setup(require('lspconfig').nil_ls) {} ''; extraPackages = [ pkgs.nil ]; diff --git a/jrpotter/neovim/lua/init/lsp.lua b/jrpotter/neovim/lua/init/lsp.lua new file mode 100644 index 0000000..aed57c0 --- /dev/null +++ b/jrpotter/neovim/lua/init/lsp.lua @@ -0,0 +1,22 @@ +local M = {} + +local function on_attach(client, bufnr) + local opts = { buffer = bufnr } + vim.keymap.set('n', 'gq', function() + vim.lsp.buf.format { async = true } + end, opts) +end + +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +function M.setup(client) + -- Return a nested function so that we can continue invoking `setup` in the + -- familiar way. + return function(opts) + opts.on_attach = opts.on_attach or on_attach + opts.cabailities = opts.cabailities or capabilities + client.setup(opts) + end +end + +return M diff --git a/jrpotter/neovim/lua/init/lua.lua b/jrpotter/neovim/lua/init/lua.lua index d69fe34..4e6787c 100644 --- a/jrpotter/neovim/lua/init/lua.lua +++ b/jrpotter/neovim/lua/init/lua.lua @@ -1,7 +1,7 @@ local M = {} function M.nvim_lspconfig() - require('lspconfig').lua_ls.setup { + require('init.lsp').setup(require('lspconfig').lua_ls) { -- Provide completions, analysis, and location handling for plugins on the -- vim runtime path. -- https://github.com/neovim/nvim-lspconfig/blob/48347089666d5b77d054088aa72e4e0b58026e6e/doc/server_configurations.md#lua_ls diff --git a/jrpotter/neovim/lua/init/python.lua b/jrpotter/neovim/lua/init/python.lua index 15b7339..2b5cd8a 100644 --- a/jrpotter/neovim/lua/init/python.lua +++ b/jrpotter/neovim/lua/init/python.lua @@ -26,7 +26,7 @@ function M.nvim_dap(options) end function M.nvim_lspconfig() - require('lspconfig').pylsp.setup { + require('init.lsp').setup(require('lspconfig').pylsp) { settings = { pylsp = { -- `flake8` currently fails in some cases. Prefer the default set of