From 91e2296818db6110440a643218a4153d062a763e Mon Sep 17 00:00:00 2001 From: Sky Hearn Date: Fri, 1 Mar 2024 14:39:20 -0800 Subject: [PATCH] neovim configuration - thanks ku <3 --- configuration.nix | 164 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 152 insertions(+), 12 deletions(-) diff --git a/configuration.nix b/configuration.nix index 32e1be8..9b8f578 100644 --- a/configuration.nix +++ b/configuration.nix @@ -139,19 +139,159 @@ clipcatd & }; programs.neovim = { - enable = true; - defaultEditor = true; - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - plugins = with pkgs.vimPlugins; [ - lualine-nvim - nvim-lspconfig - nvim-treesitter.withAllGrammars - ]; - }; + enable = true; + defaultEditor = true; + extraConfig = '' + set shiftwidth=2 smarttab + set expandtab + set tabstop=8 softtabstop=0 + ''; + extraPackages = with pkgs; [ + # Use the project flake's language server to prevent version mismatches + # clang_12 + # rust-analyzer + ]; + plugins = with pkgs.vimPlugins; [ + { + plugin = sonokai; + type = "viml"; + # Better performance is off until I can figure out a way to make the cache outside the nix store + config = '' + if has('termguicolors') + set termguicolors + endif + let g:sonokai_style = 'shusia' + let g:sonokai_better_performance = 0 + colorscheme sonokai + set clipboard+=unnamedplus + ''; + } + { + plugin = lualine-nvim; + type = "lua"; + config = '' + require'lualine'.setup { + options = { + theme = 'sonokai' + }, + sections = { + lualine_c = {'lsp_progress'} + } + } + ''; + } + { + plugin = lsp-status-nvim; + type = "lua"; + config = '' + require'lsp-status'.register_progress() + ''; + } + { + plugin = nvim-lspconfig; + type = "lua"; + config = '' + -- Mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + local opts = { noremap=true, silent=true } + vim.keymap.set('n', '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', '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 + local on_attach = function(client, bufnr) + -- Set up status tracking + require'lsp-status'.on_attach(client) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- 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', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + end + + local lsp_flags = { + -- This is the default in Nvim 0.7+ + debounce_text_changes = 150, + } + + local servers = { 'clangd', 'rust_analyzer' } + + for _, lsp in ipairs(servers) do + require'lspconfig'[lsp].setup( + vim.tbl_extend('keep', + require('coq').lsp_ensure_capabilities({ + on_attach = on_attach, + flags = lsp_flags + }) or {}, + require'lsp-status'.capabilities + ) + ) + end + ''; + } + { + plugin = coq_nvim; + type = "lua"; + config = '' + vim.g.coq_settings = { auto_start = 'shut-up', xdg = true } + ''; + } + { + plugin = nvim-treesitter.withAllGrammars; + type = "lua"; + config = '' + require'nvim-treesitter.configs'.setup { + -- TODO: Make this use stdpath("data") + -- parser_install_dir = "~/.local/share/nvim/site", + -- ensure_installed = { "nix", "help", "rust", "c", "lua" }, + -- auto_install = true, + highlight = { + enable = true + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", -- set to `false` to disable one of the mappings + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + } + }, + indent = { + enable = true + }, + } + vim.cmd([[ + set foldmethod=expr + set foldexpr=nvim_treesitter#foldexpr() + set nofoldenable + ]]) + ''; + } + { + plugin = telescope-nvim; + } + ]; + }; - home.stateVersion = "23.11"; }; # List packages installed in system profile. To search, run: