summaryrefslogtreecommitdiff
path: root/shared/home-manager/neovim/lsp.nix
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2024-12-21 15:47:33 +0100
committerLinnnus <[email protected]>2024-12-21 16:19:04 +0100
commit8353554315564b89dfe27d5130080ed04a0a65ad (patch)
tree896de88b6ea2701692b3ffe977c23947a786318e /shared/home-manager/neovim/lsp.nix
parent9b7ed17b27157a25e57a6e38be3bcfeaa70ec9e8 (diff)
Move to a profile-based configuration where common
This patch makes it so common configuration is now located in shared/ and each host basically just becomes a bunch of import statements. The exception here is host-specific configuration like the `*.linus.onl` that live inside `hosts/ahmed/`. Specifically I have: - moved common configuration `shared/{nixos,home-manager,nix-darwin}`. - moved `hosts/common.nix` to `shared/nixos/common-{nix,shell}-settings.nix`. - split `hosts/muhammed/{dev-utils,neovim}` into per-language configuration. This patch was done in preparation for the arrival of a new host, which will need to share a lot of configuration with Muhammed.
Diffstat (limited to 'shared/home-manager/neovim/lsp.nix')
-rw-r--r--shared/home-manager/neovim/lsp.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/shared/home-manager/neovim/lsp.nix b/shared/home-manager/neovim/lsp.nix
new file mode 100644
index 0000000..bc10487
--- /dev/null
+++ b/shared/home-manager/neovim/lsp.nix
@@ -0,0 +1,59 @@
+# Installs and configures lspconfig. The actual LSPs are added in the per-language profiles.
+{pkgs, ...}: {
+ programs.neovim.plugins = [
+ {
+ plugin = pkgs.vimPlugins.nvim-lspconfig;
+ type = "lua";
+ config = ''
+ local lspconfig = require("lspconfig")
+ local util = require("lspconfig.util")
+
+ -- Mappings.
+ -- See `:help vim.diagnostic.*` for documentation on any of the below functions
+ local opts = { noremap=true, silent=true }
+ vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
+ vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
+ vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
+ vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, opts)
+
+ -- Use an on_attach function to only map the following keys
+ -- after the language server attaches to the current buffer
+ vim.api.nvim_create_autocmd("LspAttach", {
+ callback = function(args)
+ local bufnr = args.buf
+ local client = vim.lsp.get_client_by_id(args.data.client_id)
+
+ -- Enable completion triggered by <c-x><c-o>
+ if client.server_capabilities.completionProvider then
+ vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
+ end
+
+ -- XXX: What does this do?
+ if client.server_capabilities.definitionProvider then
+ vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
+ end
+
+ -- Mappings.
+ -- See `:help vim.lsp.*` for documentation on any of the below functions
+ local bufopts = { noremap=true, silent=true, buffer=bufnr }
+ vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
+ vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
+ vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
+ vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
+ vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
+ vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)
+ vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
+ vim.keymap.set('n', '<leader>wl', function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end, bufopts)
+ vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, bufopts)
+ vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
+ vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, bufopts)
+ vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
+ vim.keymap.set('n', '<leader>f', function() vim.lsp.buf.format { async = true } end, bufopts)
+ end,
+ })
+ '';
+ }
+ ];
+}