From 7ccefe060165fbe4bdf3a57275f1198ee3aa51a8 Mon Sep 17 00:00:00 2001 From: teutat3s Date: Mon, 19 Aug 2024 10:18:12 +0200 Subject: [PATCH] terminal-life: reduce nvim config, switch to telescope Co-authored-by: b12f --- modules/desktop-extended/default.nix | 16 - modules/terminal-life/default.nix | 19 +- modules/terminal-life/nvim/cmp.vim | 48 +++ modules/terminal-life/nvim/default.nix | 187 +++------ modules/terminal-life/nvim/init.vim | 21 - modules/terminal-life/nvim/lsp.vim | 373 +++++++----------- modules/terminal-life/nvim/plugins.vim | 92 +++-- modules/terminal-life/nvim/preview-file.nix | 36 -- .../terminal-life/nvim/quickfixopenall.vim | 20 - modules/terminal-life/nvim/ui.vim | 17 - 10 files changed, 313 insertions(+), 516 deletions(-) create mode 100644 modules/terminal-life/nvim/cmp.vim delete mode 100644 modules/terminal-life/nvim/preview-file.nix delete mode 100644 modules/terminal-life/nvim/quickfixopenall.vim diff --git a/modules/desktop-extended/default.nix b/modules/desktop-extended/default.nix index ec293e56..43ea496e 100644 --- a/modules/desktop-extended/default.nix +++ b/modules/desktop-extended/default.nix @@ -17,22 +17,6 @@ in { signal-desktop tdesktop element-desktop - - binutils - ripgrep - jq - - # Nix specific utilities - alejandra - manix - nix-init - nix-inspect - nix-output-monitor - nix-tree - nvd - nixpkgs-review - nix-update - nix-search-cli ]; fonts = { diff --git a/modules/terminal-life/default.nix b/modules/terminal-life/default.nix index 347bcfec..7722ccf5 100644 --- a/modules/terminal-life/default.nix +++ b/modules/terminal-life/default.nix @@ -27,7 +27,6 @@ in { programs.nix-index.enableBashIntegration = false; users.users."${psCfg.user.name}".packages = with pkgs; [ - ack asciinema bat blesh @@ -43,10 +42,23 @@ in { ]; })) powerline + ripgrep screen - silver-searcher watson - ]; + ] ++ (if cfg.full then [ + binutils + jq + + # Nix specific utilities + manix + nix-index + nix-tree + nix-inspect + nvd + nixpkgs-review + nix-update + nix-search-cli + ] else []); # Get completion for system packages # https://nix-community.github.io/home-manager/options.xhtml#opt-programs.bash.enableCompletion @@ -89,6 +101,7 @@ in { inherit pkgs; inherit lib; }; + # Ensure nvim backup directory gets created # Workaround for E510: Can't make backup file (add ! to override) xdg.dataFile."nvim/backup/.keep".text = ""; diff --git a/modules/terminal-life/nvim/cmp.vim b/modules/terminal-life/nvim/cmp.vim new file mode 100644 index 00000000..fc44123e --- /dev/null +++ b/modules/terminal-life/nvim/cmp.vim @@ -0,0 +1,48 @@ +lua <'] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} + +EOF diff --git a/modules/terminal-life/nvim/default.nix b/modules/terminal-life/nvim/default.nix index 7a4e680a..d0df1cc0 100644 --- a/modules/terminal-life/nvim/default.nix +++ b/modules/terminal-life/nvim/default.nix @@ -7,8 +7,6 @@ psCfg = config.pub-solar; cfg = config.pub-solar.terminal-life; xdg = config.home-manager.users."${psCfg.user.name}".xdg; - - preview-file = pkgs.writeShellScriptBin "preview-file" (import ./preview-file.nix pkgs); in { enable = true; @@ -20,101 +18,35 @@ in { withRuby = true; withPython3 = true; - extraPackages = with pkgs; - lib.mkIf (cfg.full) [ - ansible-language-server - ccls - gopls - nixd - nodejs - nodePackages.bash-language-server - nodePackages.dockerfile-language-server-nodejs - nodePackages.svelte-language-server - nodePackages.typescript - nodePackages.typescript-language-server - nodePackages.vim-language-server - nodePackages.vue-language-server - nodePackages.vscode-langservers-extracted - nodePackages.yaml-language-server - python3Packages.python-lsp-server - python3Full - rust-analyzer - shellcheck - solargraph - terraform-ls - universal-ctags - ]; - - plugins = with pkgs.vimPlugins; lib.mkIf cfg.full [ - (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ - p.ini - p.json - p.json5 - p.markdown - p.nix - p.toml - p.yaml - - p.css - p.graphql - p.html - p.javascript - p.scss - p.tsx - p.typescript - p.vue - - p.c - p.cpp - p.go - p.gomod - p.gosum - p.haskell - p.lua - p.php - p.python - p.ruby - p.rust - - p.vim - p.vimdoc - - p.passwd - p.sql - - p.diff - p.gitcommit - p.gitignore - p.git_config - p.gitattributes - p.git_rebase - - p.bash - p.dockerfile - p.make - p.ninja - p.terraform - ])) - - # Dependencies for nvim-lspconfig - nvim-cmp - cmp-nvim-lsp - cmp_luasnip - luasnip - - # Quickstart configs for neovim LSP - lsp_extensions-nvim - nvim-lspconfig - - # Collaborative editing in Neovim using built-in capabilities - instant-nvim-nvfetcher - - # Search functionality behind :Ack - ack-vim - - # Go development - vim-go + extraPackages = with pkgs; [ + ripgrep + nixd + universal-ctags + # ansible-language-server + # clang-tools + # gopls + # nodePackages.bash-language-server + # nodePackages.svelte-language-server + # nodePackages.typescript + # nodePackages.typescript-language-server + # nodePackages.vue-language-server + # nodePackages.vscode-langservers-extracted + # nginx-language-server + # lua-language-server + # cmake-language-server + # vim-language-server + # yaml-language-server + # python3Packages.python-lsp-server + # nodePackages.dockerfile-language-server-nodejs + # docker-compose-language-service + # rust-analyzer + # cargo + # solargraph + # terraform-ls + # python3Full + ]; + plugins = with pkgs.vimPlugins; [ # The status bar in the bottom of the screen with the mode indication and file location vim-airline @@ -127,18 +59,9 @@ in { # Highlight characters when using f, F, t, and T quick-scope - # Get sudo in vim; :SudaWrite - vim-suda - # Undo history etc. per project vim-workspace-nvfetcher - # JSON schemas - SchemaStore-nvim - - # Work with tags files - vim-gutentags - # Neovim colorschemes / themes sonokai vim-hybrid-material @@ -155,9 +78,10 @@ in { # Ease your git workflow within Vim vimagit-nvfetcher - # FZF fuzzy finder - fzf-vim - fzfWrapper + # Telescope fuzzy finder + telescope-nvim + telescope-fzf-native-nvim + # Make the yanked region apparent vim-highlightedyank @@ -166,22 +90,39 @@ in { # Unload, delete or wipe a buffer without closing the window vim-bufkill + # Defaults everyone can agree on vim-sensible - # emmet for vim: http://emmet.io/ - emmet-vim + # Single tabpage interface for easily cycling through diffs for all modified files + diffview-nvim + + # Work with tags files + vim-gutentags + ] ++ (if cfg.full then [ + nvim-treesitter.withAllGrammars + + # Dependencies for nvim-lspconfig + nvim-cmp + cmp-nvim-lsp + cmp_luasnip + luasnip + + # Quickstart configs for neovim LSP + lsp_extensions-nvim + nvim-lspconfig + + # Collaborative editing in Neovim using built-in capabilities + instant-nvim-nvfetcher + # Caddyfile syntax support for Vim vim-caddyfile-nvfetcher - # Fix TOFU hashes when writing nix derivations without leaving neovim - vim-nixhash + # JSON schemas + SchemaStore-nvim + ] else []); - # Single tabpage interface for easily cycling through diffs for all modified files - diffview-nvim - ]; - - extraConfig = builtins.concatStringsSep "\n" [ + extraConfig = builtins.concatStringsSep "\n" ([ '' " Persistent undo set undofile @@ -194,13 +135,9 @@ in { (builtins.readFile ./plugins.vim) (builtins.readFile ./clipboard.vim) (builtins.readFile ./ui.vim) - (builtins.readFile ./quickfixopenall.vim) - (builtins.readFile ./lsp.vim) (builtins.readFile ./lastplace.lua) - '' - " fzf with file preview - command! -bang -nargs=? -complete=dir Files - \ call fzf#vim#files(, { 'options': ['--keep-right', '--cycle', '--layout', 'reverse', '--preview', '${preview-file}/bin/preview-file {}'] }, 0) - '' - ]; + ] ++ (if cfg.full then [ + (builtins.readFile ./lsp.vim) + (builtins.readFile ./cmp.vim) + ] else [])); } diff --git a/modules/terminal-life/nvim/init.vim b/modules/terminal-life/nvim/init.vim index f19302db..ae01ff33 100644 --- a/modules/terminal-life/nvim/init.vim +++ b/modules/terminal-life/nvim/init.vim @@ -77,9 +77,6 @@ nmap j :bprevious " This replicates the idea of closing a tab nmap q :bp bd # -" Show all open buffers and their status -nmap bl :ls -" " Move to the next tab nmap tl :tabnext @@ -89,23 +86,5 @@ nmap tj :tabprevious " Close the current tab nmap tq :tabclose -" Mapping selecting mappings -nmap (fzf-maps-n) -xmap (fzf-maps-x) -omap (fzf-maps-o) - -nmap :Files -imap :Files - -" Insert mode completion -imap (fzf-complete-word) -imap (fzf-complete-path) -imap (fzf-complete-file) -imap (fzf-complete-line) - " Clear quickfix shortcut nmap c :ccl - -nmap - :NnnPicker % -nmap n :NnnPicker % -nmap N :NnnPicker diff --git a/modules/terminal-life/nvim/lsp.vim b/modules/terminal-life/nvim/lsp.vim index f0ffcdb9..8d806dd3 100644 --- a/modules/terminal-life/nvim/lsp.vim +++ b/modules/terminal-life/nvim/lsp.vim @@ -1,258 +1,149 @@ -" Set completeopt to have a better completion experience -" :help completeopt -" menuone: popup even when there's only one match -" noinsert: Do not insert text until a selection is made -" noselect: Do not select, force user to select one from the menu -set completeopt=menuone,noinsert,noselect - -" Avoid showing extra messages when using completion -set shortmess+=c - -function AddTemplate(tmpl_file) - exe "0read " . a:tmpl_file - set nomodified - 6 -endfunction - -autocmd BufNewFile shell.nix call AddTemplate("$XDG_DATA_HOME/nvim/templates/shell.nix.tmpl") - " Configure neovim 0.6+ experimental LSPs " https://github.com/neovim/nvim-lspconfig " https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md " https://github.com/neovim/nvim-lspconfig/wiki/UI-Customization " https://gitlab.com/Iron_E/dotfiles/-/blob/master/.config/nvim/lua/_config/plugin/nvim_lsp.lua + lua <e', 'lua vim.diagnostic.open_float()', opts) - vim.api.nvim_set_keymap('n', 'g[', 'lua vim.diagnostic.goto_prev()', opts) - vim.api.nvim_set_keymap('n', 'g]', 'lua vim.diagnostic.goto_next()', opts) - vim.api.nvim_set_keymap('n', 'dq', 'lua vim.diagnostic.setloclist()', opts) - vim.api.nvim_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) +-- Set completeopt to have a better completion experience +vim.o.completeopt = 'menuone,noselect,noinsert' +vim.o.shortmess = vim.o.shortmess .. 'c' +vim.o.signcolumn = 'yes:2' - -- 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) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') +local lspconfig = require('lspconfig') - -- Mappings (available if LSP is configured and attached to buffer) - -- See `:help vim.lsp.*` for documentation on any of the below functions - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) +-- Mappings (global) +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap=true, silent=true } +vim.api.nvim_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) +vim.api.nvim_set_keymap('n', 'g[', 'lua vim.diagnostic.goto_prev()', opts) +vim.api.nvim_set_keymap('n', 'g]', 'lua vim.diagnostic.goto_next()', opts) +vim.api.nvim_set_keymap('n', 'dq', 'lua vim.diagnostic.setloclist()', opts) +vim.api.nvim_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) - -- Show diagnostic popup on cursor hold - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = 'rounded', - source = 'always', - prefix = ' ', - scope = 'cursor', - } - vim.diagnostic.open_float(nil, opts) - end - }) +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - end + -- Mappings (available if LSP is configured and attached to buffer) + -- See `:help vim.lsp.*` for documentation on any of the below functions + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - -- Add additional capabilities supported by nvim-cmp - local capabilities = require('cmp_nvim_lsp').default_capabilities() - -- vscode HTML lsp needs this https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#html - capabilities.textDocument.completion.completionItem.snippetSupport = true - - -- vscode HTML lsp needs this https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#html - capabilities.textDocument.completion.completionItem.snippetSupport = true - - local use_denols_for_typescript = not(os.getenv('NVIM_USE_DENOLS') == nil) - - for lsp_key, lsp_settings in pairs({ - 'ansiblels', ---------------------------- Ansible - 'bashls', ------------------------------- Bash - 'ccls', --------------------------------- C / C++ / Objective-C - 'cssls', -------------------------------- CSS / SCSS / LESS - 'dockerls', ----------------------------- Docker - ['gopls'] = { --------------------------- Go - ['settings'] = { - ['gopls'] = { - ['analyses'] = { - ['unusedparams'] = true, - }, - ['staticcheck'] = true - }, - }, - }, - 'html', --------------------------------- HTML - ['jdtls'] = { --------------------------- Java - ['root_dir'] = nvim_lsp.util.root_pattern('.git', 'pom.xml', 'build.xml'), - ['init_options'] = { - ['jvm_args'] = {['java.format.settings.url'] = vim.fn.stdpath('config')..'/eclipse-formatter.xml'}, - ['workspace'] = vim.fn.stdpath('cache')..'/java-workspaces' - } - }, - ['jsonls'] = { -------------------------- JSON - ['settings'] = { - ['json'] = { - ['schemas' ] = vim.list_extend( - { - { - ['description'] = 'JSON schema for Caddy v2', - ['fileMatch'] = { '*caddy*.json' }, - ['name'] = 'caddy_schema.json', - ['url'] = vim.fn.stdpath('data')..'/json-schemas/caddy_schema.json', - }, - }, - require('schemastore').json.schemas() - ), - ['validate'] = { ['enable'] = true } - } - } - }, - 'nixd', --------------------------------- Nix - 'phpactor', ----------------------------- PHP - 'pylsp', -------------------------------- Python - 'solargraph', --------------------------- Ruby - 'rust_analyzer', ------------------------ Rust - ['sqlls'] = { - ['cmd'] = {vim.fn.stdpath('data')..'/nvm/versions/node/v12.19.0/bin/sql-language-server', 'up', '--method', 'stdio'} - }, - ['terraformls'] = { --------------------- Terraform - ['filetypes'] = { 'terraform', 'hcl', 'tf' } - }, - - -- The TS/JS server is chosen depending on an environment variable, - -- since denols is nicer for Deno based projects - ------------------------ Deno TS/JS - ------------------------------------ Typescript / JavaScript - (use_denols_for_typescript and 'denols' or 'tsserver'), - - 'vuels', -------------------------------- Vue - 'svelte', ------------------------------- Svelte - ['yamlls'] = { -------------------------- YAML - ['settings'] = { - ['yaml'] = { - ['schemas'] = { - ['https://json.schemastore.org/github-workflow'] = '.github/workflows/*.{yml,yaml}', - ['https://json.schemastore.org/github-action'] = '.github/action.{yml,yaml}', - ['https://json.schemastore.org/drone'] = '*.drone.{yml,yaml}', - ['https://json.schemastore.org/swagger-2.0'] = 'swagger.{yml,yaml}', - } - } - } - } - }) do -- Setup all of the language servers. † - if type(lsp_key) == 'number' then -- Enable the LSP with defaults. - -- The `lsp` is an index in this case. - nvim_lsp[lsp_settings].setup{ - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - }, - capabilities = capabilities, + -- Show diagnostic popup on cursor hold + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = 'rounded', + source = 'always', + prefix = ' ', + scope = 'cursor', } - else -- Use the LSP's configuration. - lsp_settings.on_attach = on_attach - lsp_settings.capabilities = capabilities - - nvim_lsp[lsp_key].setup(lsp_settings) + vim.diagnostic.open_float(nil, opts) end - end -- ‡ - - -- configure floating diagnostics appearance, symbols - local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } - for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) - end - - -- Set completeopt to have a better completion experience - vim.o.completeopt = 'menuone,noselect' - - -- luasnip setup - local luasnip = require 'luasnip' - - -- nvim-cmp setup - local cmp = require 'cmp' - cmp.setup { - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, - [''] = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, - } - - -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#denols - vim.g.markdown_fenced_languages = { - "ts=typescript" - } - - -- Configure diagnostics - vim.diagnostic.config({ - virtual_text = false, - signs = true, - underline = true, - update_in_insert = false, - severity_sort = false, }) - -- Change diagnostic symbols in the sign column (gutter) - local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } - for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) - end -EOF +end -" have a fixed column for the diagnostics to appear in -" this removes the jitter when warnings/errors flow in -set signcolumn=yes:2 +local lspconfig = require 'lspconfig' +-- Add additional capabilities supported by nvim-cmp +local CAPABILITIES = require('cmp_nvim_lsp').default_capabilities() + +--- Event handlers +local HANDLERS = { + -- TODO: replace with vim.lsp.protocol.Methods + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, FLOAT_CONFIG), + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, FLOAT_CONFIG), +} + +-- vscode HTML lsp needs this https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#html +CAPABILITIES.textDocument.completion.completionItem.snippetSupport = true + +local function setup(lsp, config) + if config == nil then + config = {} + end + + config.capabilities = CAPABILITIES + config.handlers = HANDLERS + config.on_attach = on_attach + lspconfig[lsp].setup(config) +end + +setup('nixd') +setup('bashls') +setup('clangd') +setup('cssls') +setup('eslint') +setup('tsserver') +setup('denols') +setup('vuels') +setup('svelte') +setup('html') +setup('yamlls') +setup('jsonls', { + json = { + schemas = require('schemastore').json.schemas(), + validate = { + enable = true + } + } +}) +setup('gopls', { + settings = { + gopls = { semanticTokens = true } + } +}) +setup('phpactor') +setup('pylsp') +setup('solargraph') -- ruby +setup('rust_analyzer', { + settings = { + ['rust-analyzer'] = { + checkOnSave = { extraArgs = { "--target-dir", "/tmp/rust-analyzer-check" } }, + diagnostics = { disabled = { 'inactive-code' } }, + }, + } +}) +setup('sqlls') +setup('salt_ls') +setup('ansiblels') +setup('dockerls') +setup('docker_compose_language_service') +setup('terraformls') + +-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#denols +vim.g.markdown_fenced_languages = { + "ts=typescript" +} + +-- Configure diagnostics +vim.diagnostic.config({ + virtual_text = false, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = false, +}) + +-- Change diagnostic symbols in the sign column (gutter) +local signs = { Error = "x ", Warn = "! ", Hint = "? ", Info = "i " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) +end +EOF diff --git a/modules/terminal-life/nvim/plugins.vim b/modules/terminal-life/nvim/plugins.vim index 85891b16..6d8eaf6f 100644 --- a/modules/terminal-life/nvim/plugins.vim +++ b/modules/terminal-life/nvim/plugins.vim @@ -2,31 +2,22 @@ au! BufNewFile,BufReadPost *.{yaml,yml} set filetype=yaml autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab +function AddTemplate(tmpl_file) + exe "0read " . a:tmpl_file + set nomodified + 6 +endfunction + +autocmd BufNewFile shell.nix call AddTemplate("$XDG_DATA_HOME/nvim/templates/shell.nix.tmpl") + let g:gutentags_file_list_command = 'git ls-files' -" quick-scope " https://github.com/unblevable/quick-scope let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] -" Golang -" Go test, Def, Decls shortcut -nmap got :GoTest:botright copen -autocmd FileType go nmap gd :GoDef -autocmd FileType go nmap gD :GoDecls - -" Go formatting -autocmd FileType go setlocal noexpandtab shiftwidth=4 tabstop=4 softtabstop=4 nolist - " Caddyfile indentation autocmd FileType caddyfile setlocal noexpandtab shiftwidth=8 tabstop=8 softtabstop=8 nolist -" vim-go disable text-objects -let g:go_textobj_enabled = 0 - -" disable vim-go :GoDef short cut (gd) -" this is handled by LanguageClient [LC] -let g:go_def_mapping_enabled = 0 - " GitGutter and vim Magit " inspired by: https://jakobgm.com/posts/vim/git-integration/ " Don't map gitgutter keys automatically, set them ourselves @@ -51,9 +42,6 @@ nnoremap gP :! git push " git Push nmap [ :diffget //2 nmap ] :diffget //3 -" netrw -let g:netrw_fastbrowse=0 - " Auto-FMT rust code on save let g:rustfmt_autosave = 1 @@ -66,22 +54,52 @@ let g:highlightedyank_highlight_duration = 200 " Markdown options let g:vim_markdown_folding_disabled = 1 -" Haskell options -let g:haskell_enable_quantification = 1 " to enable highlighting of `forall` -let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec` -let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc` -let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern` -let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles -let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static` -let g:haskell_backpack = 1 " to enable highlighting of backpack keywords - -" Emmet -let g:user_emmet_leader_key='' - -" Ack -if executable('ag') - let g:ackprg = 'ag --vimgrep' -endif - " nnn let g:nnn#command = 'nnn -d -e -H -r' + +nmap - :NnnPicker % +nmap n :NnnPicker % +nmap N :NnnPicker + +lua <"] = actions.close, + }, + }, + }, + pickers = { + find_files = { + -- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d. + find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" }, + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + } + } +} + +telescope.load_extension('fzf') + +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'ff', builtin.find_files, {}) +vim.keymap.set('n', 'f/', builtin.live_grep, {}) +vim.keymap.set('n', 'f?', builtin.builtin, {}) +vim.keymap.set('n', 'fb', builtin.buffers, {}) +vim.keymap.set('n', 'fr', builtin.command_history, {}) +vim.keymap.set('n', 'fc', builtin.commands, {}) +vim.keymap.set('n', 'ft', builtin.treesitter, {}) +EOF diff --git a/modules/terminal-life/nvim/preview-file.nix b/modules/terminal-life/nvim/preview-file.nix deleted file mode 100644 index 2a52bdd8..00000000 --- a/modules/terminal-life/nvim/preview-file.nix +++ /dev/null @@ -1,36 +0,0 @@ -self: -with self; '' - IFS=':' read -r -a INPUT <<< "$1" - FILE=''${INPUT[0]} - CENTER=''${INPUT[1]} - - if [[ "$1" =~ ^[A-Za-z]:\\ ]]; then - FILE=$FILE:''${INPUT[1]} - CENTER=''${INPUT[2]} - fi - - if [[ -n "$CENTER" && ! "$CENTER" =~ ^[0-9] ]]; then - exit 1 - fi - CENTER=''${CENTER/[^0-9]*/} - - FILE="''${FILE/#\~\//$HOME/}" - if [ ! -r "$FILE" ]; then - echo "File not found ''${FILE}" - exit 1 - fi - - if [ -z "$CENTER" ]; then - CENTER=0 - fi - - exec cat "$FILE" \ - | sed -e '/[#|\/\/ ?]-- copyright/,/[#\/\/]++/c\\' \ - | ${pkgs.coreutils}/bin/tr -s '\n' \ - | ${pkgs.bat}/bin/bat \ - --style="''${BAT_STYLE:-numbers}" \ - --color=always \ - --pager=never \ - --file-name="''$FILE" \ - --highlight-line=$CENTER -'' diff --git a/modules/terminal-life/nvim/quickfixopenall.vim b/modules/terminal-life/nvim/quickfixopenall.vim deleted file mode 100644 index 6b4d8445..00000000 --- a/modules/terminal-life/nvim/quickfixopenall.vim +++ /dev/null @@ -1,20 +0,0 @@ -"Usage: -" 1. Perform a vimgrep search -" :vimgrep /def/ *.rb -" 2. Issue QuickFixOpenAll command -" :QuickFixOpenAll -function! QuickFixOpenAll() - if empty(getqflist()) - return - endif - let s:prev_val = "" - for d in getqflist() - let s:curr_val = bufname(d.bufnr) - if (s:curr_val != s:prev_val) - exec "edit " . s:curr_val - endif - let s:prev_val = s:curr_val - endfor -endfunction - -command! QuickFixOpenAll call QuickFixOpenAll() diff --git a/modules/terminal-life/nvim/ui.vim b/modules/terminal-life/nvim/ui.vim index b3e63a7e..b3e8166a 100644 --- a/modules/terminal-life/nvim/ui.vim +++ b/modules/terminal-life/nvim/ui.vim @@ -13,20 +13,3 @@ let g:airline#extensions#tabline#fnamemod = ':t' " Show just the filename let g:airline#extensions#tabline#formatter = 'unique_tail_improved' let g:airline_powerline_fonts = 1 " Use powerline fonts let g:airline_theme = 'apprentice' - -" Customize fzf colors to match your color scheme -" - fzf#wrap translates this to a set of `--color` options -let g:fzf_colors = -\ { 'fg': ['fg', 'Normal'], - \ 'bg': ['bg', 'Normal'], - \ 'hl': ['fg', 'Comment'], - \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], - \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], - \ 'hl+': ['fg', 'Statement'], - \ 'info': ['fg', 'PreProc'], - \ 'border': ['fg', 'Ignore'], - \ 'prompt': ['fg', 'Conditional'], - \ 'pointer': ['fg', 'Exception'], - \ 'marker': ['fg', 'Keyword'], - \ 'spinner': ['fg', 'Label'], - \ 'header': ['fg', 'Comment'] }