From e22762255d8d326b0d2b2de4e56d2dbda0b34c25 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 23 Sep 2024 09:52:11 +0300 Subject: [PATCH] feat(nvim): configuration, refactoring, fixes --- config/asdf/python-packages | 1 + config/nvim/.neoconf.json | 24 ++ config/nvim/init.lua | 34 +- config/nvim/lua/config/misc.lua | 10 - config/nvim/lua/keymaps.lua | 18 +- config/nvim/lua/options.lua | 5 + config/nvim/lua/plugins/git.lua | 6 +- config/nvim/lua/plugins/goto-preview.lua | 3 + config/nvim/lua/plugins/lsp.lua | 456 ++++++++++++----------- config/nvim/lua/plugins/lualine.lua | 4 + config/nvim/lua/plugins/neotree.lua | 2 +- config/nvim/lua/plugins/noice.lua | 152 ++++---- config/nvim/lua/plugins/telescope.lua | 47 ++- config/nvim/lua/plugins/trouble.lua | 17 +- config/nvim/lua/plugins/ui.lua | 23 +- 15 files changed, 427 insertions(+), 375 deletions(-) create mode 100644 config/nvim/.neoconf.json delete mode 100644 config/nvim/lua/config/misc.lua diff --git a/config/asdf/python-packages b/config/asdf/python-packages index 4fde2d0..b939d61 100644 --- a/config/asdf/python-packages +++ b/config/asdf/python-packages @@ -1,3 +1,4 @@ ansible pipenv semgrep +neovim diff --git a/config/nvim/.neoconf.json b/config/nvim/.neoconf.json new file mode 100644 index 0000000..aea72e4 --- /dev/null +++ b/config/nvim/.neoconf.json @@ -0,0 +1,24 @@ +{ + "neodev": { + "library": { + "enabled": true, + "plugins": [ + "nvim-lspconfig", + "lsp", + "completion", + ] + } + }, + "neoconf": { + "plugins": { + "lua_ls": { + "enabled": true + }, + } + }, + "lspconfig": { + "lua_ls": { + "Lua.completion.callSnippet": "Replace", + }, + } +} diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 78d2117..56f448c 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -3,15 +3,18 @@ -- Install lazylazy -- https://github.com/folke/lazy.nvim local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' -if not vim.loop.fs_stat(lazypath) then - vim.fn.system { - 'git', - 'clone', - '--filter=blob:none', - 'https://github.com/folke/lazy.nvim.git', - '--branch=stable', -- latest stable release - lazypath, - } +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' + local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { 'Failed to clone lazy.nvim:\n', 'ErrorMsg' }, + { out, 'WarningMsg' }, + { '\nPress any key to exit...' }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end end vim.opt.rtp:prepend(lazypath) @@ -22,14 +25,20 @@ require('lazy').setup { checker = { -- Automatically check for updates enabled = true, + nofity = false, }, spec = { -- Useful plugin to show you pending keybinds. -- https://github.com/folke/which-key.nvim { 'folke/which-key.nvim', - event = 'VimEnter', -- Sets the loading event to 'VimEnter' + lazy = false, -- Load this plugin lazily + version = '*', priority = 1001, -- Make sure to load this as soon as possible + dependencies = { + 'nvim-lua/plenary.nvim', + 'echasnovski/mini.icons', + }, config = function() -- This is the function that runs, AFTER loading local wk = require 'which-key' wk.setup() @@ -38,15 +47,14 @@ require('lazy').setup { { 'b', group = '[b] Buffer' }, { 'c', group = '[c] Code' }, { 'd', group = '[d] Document' }, - { 'f', group = '[f] File' }, { 'g', group = '[g] Git' }, { 'l', group = '[l] LSP' }, - { 'o', group = '[o] Open' }, { 'p', group = '[p] Project' }, { 'q', group = '[q] Quit' }, { 's', group = '[s] Search' }, { 't', group = '[t] Toggle' }, { 'w', group = '[w] Workspace' }, + { 'x', group = '[z] Trouble' }, { 'z', group = '[x] FZF' }, { '?', group = '[?] Help' }, { @@ -63,5 +71,3 @@ require('lazy').setup { { import = 'plugins' }, }, } - -require 'config.misc' diff --git a/config/nvim/lua/config/misc.lua b/config/nvim/lua/config/misc.lua deleted file mode 100644 index 15e9adf..0000000 --- a/config/nvim/lua/config/misc.lua +++ /dev/null @@ -1,10 +0,0 @@ --- Go -local format_sync_grp = vim.api.nvim_create_augroup('GoFormat', {}) -vim.api.nvim_create_autocmd('BufWritePre', { - pattern = '*.go', - callback = function() - require('go.format').goimport() - end, - group = format_sync_grp, -}) -require('go').setup() diff --git a/config/nvim/lua/keymaps.lua b/config/nvim/lua/keymaps.lua index 832741b..b638173 100644 --- a/config/nvim/lua/keymaps.lua +++ b/config/nvim/lua/keymaps.lua @@ -1,15 +1,12 @@ vim.api.nvim_set_keymap('i', 'jj', '', { noremap = false }) --- twilight -vim.api.nvim_set_keymap('n', 'tw', ':Twilight', { noremap = false }) - -- buffers -vim.api.nvim_set_keymap('n', 'bk', ':blast', { desc = 'Last', noremap = false }) -vim.api.nvim_set_keymap('n', 'bj', ':bfirst', { desc = 'First', noremap = false }) -vim.api.nvim_set_keymap('n', 'bh', ':bprev', { desc = 'Prev', noremap = false }) -vim.api.nvim_set_keymap('n', 'bl', ':bnext', { desc = 'Next', noremap = false }) -vim.api.nvim_set_keymap('n', 'bd', ':bdelete', { desc = 'Delete', noremap = false }) -vim.api.nvim_set_keymap('n', '', ':bdelete', { desc = 'Delete buffer', noremap = false }) +vim.api.nvim_set_keymap('n', 'bk', ':blast', { desc = 'Buffer: Last', noremap = false }) +vim.api.nvim_set_keymap('n', 'bj', ':bfirst', { desc = 'Buffer: First', noremap = false }) +vim.api.nvim_set_keymap('n', 'bh', ':bprev', { desc = 'Buffer: Prev', noremap = false }) +vim.api.nvim_set_keymap('n', 'bl', ':bnext', { desc = 'Buffer: Next', noremap = false }) +vim.api.nvim_set_keymap('n', 'bd', ':Bdelete', { desc = 'Buffer: Delete', noremap = false }) +vim.api.nvim_set_keymap('n', 'bw', ':Bwipeout', { desc = 'Buffer: Wipeout', noremap = false }) -- files vim.api.nvim_set_keymap('n', 'QQ', ':q!', { desc = 'Quickly Quit', noremap = false }) @@ -34,9 +31,6 @@ vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) --- Noice -vim.api.nvim_set_keymap('n', 'nn', ':Noice dismiss', { desc = 'Noice dismiss', noremap = true }) - vim.keymap.set('n', 'xe', 'GoIfErr', { desc = 'Go If Error', silent = true, noremap = true }) -- TIP: Disable arrow keys in normal mode diff --git a/config/nvim/lua/options.lua b/config/nvim/lua/options.lua index 0396f70..9404b1f 100644 --- a/config/nvim/lua/options.lua +++ b/config/nvim/lua/options.lua @@ -78,3 +78,8 @@ vim.o.undofile = true vim.o.completeopt = 'menuone,noselect' -- Fixes Notify opacity issues vim.o.termguicolors = true + +-- Set spell checking +vim.o.spell = true + +vim.g.loaded_perl_provider = 0 diff --git a/config/nvim/lua/plugins/git.lua b/config/nvim/lua/plugins/git.lua index 9376569..6634beb 100644 --- a/config/nvim/lua/plugins/git.lua +++ b/config/nvim/lua/plugins/git.lua @@ -1,9 +1,5 @@ return { - -- fugitive.vim: A Git wrapper so awesome, it should be illegal - -- https://github.com/tpope/vim-fugitive - { 'tpope/vim-fugitive' }, - -- Git integration for buffers -- https://github.com/lewis6991/gitsigns.nvim { @@ -19,7 +15,7 @@ return { }, current_line_blame = false, on_attach = function(bufnr) - local gs = package.loaded.gitsigns + local gs = require 'gitsigns' local function map(mode, l, r, opts) opts = opts or {} diff --git a/config/nvim/lua/plugins/goto-preview.lua b/config/nvim/lua/plugins/goto-preview.lua index 01a434a..a016151 100644 --- a/config/nvim/lua/plugins/goto-preview.lua +++ b/config/nvim/lua/plugins/goto-preview.lua @@ -2,6 +2,9 @@ return { -- A small Neovim plugin for previewing definitions using floating windows. -- https://github.com/rmagatti/goto-preview 'rmagatti/goto-preview', + dependencies = { + { 'nvim-telescope/telescope.nvim' }, + }, config = function() require('goto-preview').setup { width = 120, -- Width of the floating window diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index 8dae782..d13cc25 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -1,254 +1,262 @@ -- Quickstart configs for Nvim LSP -- https://github.com/neovim/nvim-lspconfig return { - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs to stdpath for neovim - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - -- Useful status updates for LSP - { - 'j-hui/fidget.nvim', - opts = { - notification = { - window = { - winblend = 50, - align = 'top', + -- Neovim plugin to manage global and project-local settings + -- Should be included before LSP Config + -- https://github.com/folke/neoconf.nvim + { + 'folke/neoconf.nvim', + keys = { + { '?c', 'Neoconf', desc = 'Neoconf: Open' }, + { '?g', 'Neoconf global', desc = 'Neoconf: Global' }, + { '?l', 'Neoconf local', desc = 'Neoconf: Local' }, + { '?m', 'Neoconf lsp', desc = 'Neoconf: Show merged LSP config' }, + { '?s', 'Neoconf show', desc = 'Neoconf: Show merged config' }, + }, + config = function() + require('neoconf').setup() + end, + }, + + { + 'neovim/nvim-lspconfig', + dependencies = { + -- Automatically install LSPs to stdpath for neovim + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', + -- Useful status updates for LSP + { + 'j-hui/fidget.nvim', + opts = { + notification = { + window = { + winblend = 50, + align = 'top', + }, }, }, }, - }, - 'b0o/schemastore.nvim', - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + 'b0o/schemastore.nvim', + { + -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + 'folke/lazydev.nvim', + dependencies = { + -- `wezterm-types` provides types for the Wezterm terminal + { + 'justinsgithub/wezterm-types', + as = 'wezterm', + }, + }, + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + -- Load wezterm types when the `wezterm` word is found + { path = 'wezterm-types', mods = { 'wezterm' } }, + }, }, }, + 'folke/neoconf.nvim', }, - }, - config = function() - -- Diagnostic keymaps - vim.keymap.set('n', 'dp', vim.diagnostic.goto_prev, { desc = 'Diagnostic: Goto Prev' }) - vim.keymap.set('n', 'dn', vim.diagnostic.goto_next, { desc = 'Diagnostic: Goto Next' }) - vim.keymap.set('n', 'do', vim.diagnostic.open_float, { desc = 'Diagnostic: Open float' }) - vim.keymap.set('n', 'dq', vim.diagnostic.setloclist, { desc = 'Diagnostic: Set loc list' }) - - -- LSP settings. - -- This function gets run when an LSP connects to a particular buffer. - local on_attach = function(_, bufnr) - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end - - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + keys = { + { 'do', 'lua vim.diagnostic.open_float()', desc = 'Diagnostic: Open float' }, + { 'dq', 'lua vim.diagnostic.setloclist()', desc = 'Diagnostic: Set loc list' }, + { 'dn', 'lua vim.diagnostic.goto_next()', desc = 'Diagnostic: Goto Next' }, + { 'dp', 'lua vim.diagnostic.goto_prev()', desc = 'Diagnostic: Goto Prev' }, + { 'cr', 'lua vim.lsp.buf.rename()', desc = 'LSP: Rename' }, + { 'ca', 'lua vim.lsp.buf.code_action()', desc = 'LSP: Code Action' }, + { 'gd', 'lua vim.lsp.buf.definition()', desc = 'LSP: Goto Definition' }, + { 'gr', 'lua require("telescope.builtin").lsp_references()', desc = 'LSP: Goto References' }, + { 'gI', 'lua vim.lsp.buf.implementation()', desc = 'LSP: Goto Implementation' }, + { 'D', 'lua vim.lsp.buf.type_definition()', desc = 'LSP: Type Definition' }, + { 'ds', 'lua require("telescope.builtin").lsp_document_symbols()', desc = 'LSP: Document Symbols' }, + { 'ws', 'lua require("telescope.builtin").lsp_dynamic_workspace_symbols()', desc = 'LSP: Workspace Symbols' }, + { 'K', 'lua vim.lsp.buf.hover()', desc = 'LSP: Hover Documentation' }, + { '', 'lua vim.lsp.buf.signature_help()', desc = 'LSP: Signature Documentation' }, + { 'gD', 'lua vim.lsp.buf.declaration()', desc = 'LSP: Goto Declaration' }, + { 'wa', 'lua vim.lsp.buf.add_workspace_folder()', desc = 'LSP: Workspace Add Folder' }, + { 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', desc = 'LSP: Workspace Remove Folder' }, + { 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', desc = 'LSP: Workspace List Folders' }, + }, + config = function() + -- LSP settings. + -- This function gets run when an LSP connects to a particular buffer. + local on_attach = function(_, bufnr) + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + if vim.lsp.buf.format then + vim.lsp.buf.format() + elseif vim.lsp.buf.formatting then + vim.lsp.buf.formatting() + end + end, { desc = 'Format current buffer with LSP' }) end - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') - nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + -- Setup mason so it can manage external tooling + require('mason').setup() - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + -- Enable the following language servers + -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. + local servers = { + -- :help lspconfig-all for all pre-configured LSPs + ast_grep = {}, - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') + actionlint = {}, -- GitHub Actions + ansiblels = {}, -- Ansible + bashls = {}, -- Bash + css_variables = {}, -- CSS + cssls = {}, -- CSS + docker_compose_language_service = {}, -- Docker compose + dockerls = {}, -- Docker + eslint = {}, -- ESLint + gitlab_ci_ls = {}, -- GitLab CI + gopls = {}, -- Go + html = {}, -- HTML + intelephense = {}, -- PHP + pest_ls = {}, -- Pest (PHP) + phpactor = {}, -- PHP + psalm = {}, -- PHP + pyright = {}, -- Python + semgrep = {}, -- Security + shellcheck = {}, -- Shell scripts + shfmt = {}, -- Shell scripts formatting + stylelint_lsp = {}, -- Stylelint for S/CSS + stylua = {}, -- Used to format Lua code + tailwindcss = {}, -- Tailwind CSS + terraformls = {}, -- Terraform + tflint = {}, -- Terraform + ts_ls = {}, -- TypeScript/JS + typos_lsp = {}, -- Better writing + volar = {}, -- Vue + yamlls = {}, -- YAML - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - if vim.lsp.buf.format then - vim.lsp.buf.format() - elseif vim.lsp.buf.formatting then - vim.lsp.buf.formatting() - end - end, { desc = 'Format current buffer with LSP' }) - end - - -- Setup mason so it can manage external tooling - require('mason').setup() - - -- Enable the following language servers - -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - local servers = { - -- :help lspconfig-all for all pre-configured LSPs - ast_grep = {}, - - actionlint = {}, -- GitHub Actions - ansiblels = {}, -- Ansible - bashls = {}, -- Bash - css_variables = {}, -- CSS - cssls = {}, -- CSS - docker_compose_language_service = {}, -- Docker compose - dockerls = {}, -- Docker - eslint = {}, -- ESLint - gitlab_ci_ls = {}, -- GitLab CI - gopls = {}, -- Go - grammarly = {}, -- Grammar and better writing - html = {}, -- HTML - intelephense = {}, -- PHP - jinja_lsp = {}, -- Jinja templates - pest_ls = {}, -- Pest (PHP) - phpactor = {}, -- PHP - psalm = {}, -- PHP - pyright = {}, -- Python - semgrep = {}, -- Security - shellcheck = {}, -- Shell scripts - shfmt = {}, -- Shell scripts formatting - stylelint_lsp = {}, -- Stylelint for S/CSS - stylua = {}, -- Used to format Lua code - tailwindcss = {}, -- Tailwind CSS - terraformls = {}, -- Terraform - tflint = {}, -- Terraform - ts_ls = {}, -- TypeScript/JS - typos_lsp = {}, -- Better writing - volar = {}, -- Vue - yamlls = {}, -- YAML - - lua_ls = { - -- cmd = {...}, - -- filetypes = { ...}, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', + lua_ls = { + settings = { + Lua = { + completion = { + callSnippet = 'Replace', + }, + -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings + diagnostics = { disable = { 'missing-fields' } }, }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - diagnostics = { disable = { 'missing-fields' } }, }, }, - }, - jsonls = { - settings = { - json = { - schemas = require('schemastore').json.schemas(), - validate = { enable = true }, - }, - yaml = { - schemaStore = { - -- You must disable built-in schemaStore support if you want to use - -- this plugin and its advanced options like `ignore`. - enable = false, - -- Avoid TypeError: Cannot read properties of undefined (reading 'length') - url = '', + jsonls = { + settings = { + json = { + schemas = require('schemastore').json.schemas(), + validate = { enable = true }, + }, + yaml = { + schemaStore = { + -- You must disable built-in schemaStore support if you want to use + -- this plugin and its advanced options like `ignore`. + enable = false, + -- Avoid TypeError: Cannot read properties of undefined (reading 'length') + url = '', + }, + schemas = require('schemastore').yaml.schemas(), }, - schemas = require('schemastore').yaml.schemas(), }, }, - }, - } + } - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'actionlint', - 'ansible-language-server', - 'ansible-lint', - 'bash-language-server', - 'blade-formatter', - 'codespell', - 'commitlint', - 'diagnostic-languageserver', - 'docker-compose-language-service', - 'dockerfile-language-server', - 'editorconfig-checker', - 'fixjson', - 'flake8', - 'html-lsp', - 'jq', - 'jsonlint', - 'luacheck', - 'php-cs-fixer', - 'phpcs', - 'phpmd', - 'semgrep', - 'shellcheck', - 'shfmt', - 'stylelint', - 'stylua', - 'yamllint', - }) - require('mason-tool-installer').setup { - ensure_installed = ensure_installed, - auto_update = true, - } + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + 'actionlint', + 'ansible-language-server', + 'ansible-lint', + 'bash-language-server', + 'blade-formatter', + 'commitlint', + 'diagnostic-languageserver', + 'docker-compose-language-service', + 'dockerfile-language-server', + 'editorconfig-checker', + 'fixjson', + 'flake8', + 'html-lsp', + 'jq', + 'jsonlint', + 'luacheck', + 'php-cs-fixer', + 'phpcs', + 'phpmd', + 'semgrep', + 'shellcheck', + 'shfmt', + 'stylelint', + 'stylua', + 'yamllint', + }) + require('mason-tool-installer').setup { + ensure_installed = ensure_installed, + auto_update = true, + } - -- Ensure the servers above are installed - require('mason-lspconfig').setup { - automatic_installation = true, - ensure_installed = servers, - } + -- Ensure the servers above are installed + require('mason-lspconfig').setup { + automatic_installation = true, + ensure_installed = servers, + } - -- nvim-cmp supports additional completion capabilities - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + -- nvim-cmp supports additional completion capabilities + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - for _, lsp in ipairs(servers) do - require('lspconfig')[lsp].setup { + for _, lsp in ipairs(servers) do + require('lspconfig')[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } + end + + -- Turn on lsp status information + require('fidget').setup() + + -- Example custom configuration for lua + -- + -- Make runtime files discoverable to the server + local runtime_path = vim.split(package.path, ';') + table.insert(runtime_path, 'lua/?.lua') + table.insert(runtime_path, 'lua/?/init.lua') + + require('lspconfig').lua_ls.setup { on_attach = on_attach, capabilities = capabilities, - } - end - - -- Turn on lsp status information - require('fidget').setup() - - -- Example custom configuration for lua - -- - -- Make runtime files discoverable to the server - local runtime_path = vim.split(package.path, ';') - table.insert(runtime_path, 'lua/?.lua') - table.insert(runtime_path, 'lua/?/init.lua') - - require('lspconfig').lua_ls.setup { - on_attach = on_attach, - capabilities = capabilities, - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT) - version = 'LuaJIT', - -- Setup your lua path - path = runtime_path, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file('', true), + checkThirdParty = false, + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { enable = false }, }, - diagnostics = { - globals = { 'vim' }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file('', true), - checkThirdParty = false, - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { enable = false }, }, - }, - } + } - vim.api.nvim_create_autocmd('FileType', { - pattern = 'sh', - callback = function() - vim.lsp.start { - name = 'bash-language-server', - cmd = { 'bash-language-server', 'start' }, - } - end, - }) - end, + vim.api.nvim_create_autocmd('FileType', { + pattern = 'sh', + callback = function() + vim.lsp.start { + name = 'bash-language-server', + cmd = { 'bash-language-server', 'start' }, + } + end, + }) + end, + }, } diff --git a/config/nvim/lua/plugins/lualine.lua b/config/nvim/lua/plugins/lualine.lua index 2e6de97..91a94ca 100644 --- a/config/nvim/lua/plugins/lualine.lua +++ b/config/nvim/lua/plugins/lualine.lua @@ -2,6 +2,10 @@ -- https://github.com/nvim-lualine/lualine.nvim return { 'nvim-lualine/lualine.nvim', + dependencies = { + 'kyazdani42/nvim-web-devicons', + 'folke/noice.nvim', + }, config = function() require('lualine').setup { options = { diff --git a/config/nvim/lua/plugins/neotree.lua b/config/nvim/lua/plugins/neotree.lua index a60c7bc..695c9b6 100644 --- a/config/nvim/lua/plugins/neotree.lua +++ b/config/nvim/lua/plugins/neotree.lua @@ -30,7 +30,7 @@ return { }, cmd = 'Neotree', keys = { - { 'e', ':Neotree reveal', { desc = 'NeoTree reveal' } }, + { 'e', ':Neotree reveal', desc = 'NeoTree reveal' }, }, opts = { close_if_last_window = true, diff --git a/config/nvim/lua/plugins/noice.lua b/config/nvim/lua/plugins/noice.lua index 9eeb748..eab0457 100644 --- a/config/nvim/lua/plugins/noice.lua +++ b/config/nvim/lua/plugins/noice.lua @@ -2,79 +2,83 @@ return { -- Highly experimental plugin that completely replaces the UI -- for messages, cmdline and the popupmenu. -- https://github.com/folke/noice.nvim - { - 'folke/noice.nvim', - dependencies = { - 'MunifTanjim/nui.nvim', - -- A fancy, configurable, notification manager for NeoVim - -- https://github.com/rcarriga/nvim-notify - { - 'rcarriga/nvim-notify', - config = function() - require('notify').setup { - background_colour = '#000000', - enabled = false, - } - end, - }, - }, - setup = function() - vim.g.noice_ignored_filetypes = { 'fugitiveblame', 'fugitive', 'gitcommit' } - require('noice').setup { - -- you can enable a preset for easier configuration - presets = { - bottom_search = true, -- use a classic bottom cmdline for search - command_palette = true, -- position the cmdline and popupmenu together - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = false, -- add a border to hover docs and signature help - }, - views = { - cmdline_popup = { - position = { - row = 5, - col = '50%', - }, - size = { - width = 60, - height = 'auto', - }, - }, - popupmenu = { - relative = 'editor', - position = { - row = 8, - col = '50%', - }, - size = { - width = 60, - height = 10, - }, - border = { - style = 'rounded', - padding = { 0, 1 }, - }, - win_options = { - winhighlight = { Normal = 'Normal', FloatBorder = 'DiagnosticInfo' }, - }, - }, - }, - routes = { - { - filter = { - event = 'msg_show', - any = { - { find = '%d+L, %d+B' }, - { find = '; after #%d+' }, - { find = '; before #%d+' }, - { find = '%d fewer lines' }, - { find = '%d more lines' }, - }, - }, - opts = { skip = true }, - }, - }, - } - end, + 'folke/noice.nvim', + lazy = false, + enabled = true, + dependencies = { + 'MunifTanjim/nui.nvim', + -- A fancy, configurable, notification manager for NeoVim + -- https://github.com/rcarriga/nvim-notify + 'rcarriga/nvim-notify', + 'hrsh7th/nvim-cmp', }, + keys = { + { 'n', 'tn', ':Noice dismiss', desc = 'Noice dismiss' }, + }, + config = function() + vim.g.noice_ignored_filetypes = { 'fugitiveblame', 'fugitive', 'gitcommit', 'noice' } + require('noice').setup { + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ['vim.lsp.util.convert_input_to_markdown_lines'] = true, + ['vim.lsp.util.stylize_markdown'] = true, + ['cmp.entry.get_documentation'] = true, -- requires hrsh7th/nvim-cmp + }, + }, + -- you can enable a preset for easier configuration + presets = { + bottom_search = false, -- use a classic bottom cmdline for search + command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = false, -- add a border to hover docs and signature help + }, + routes = { + { + filter = { + event = 'msg_show', + any = { + { find = '%d+L, %d+B' }, + { find = '; after #%d+' }, + { find = '; before #%d+' }, + { find = '%d fewer lines' }, + { find = '%d more lines' }, + }, + }, + opts = { skip = true }, + }, + }, + views = { + cmdline_popup = { + position = { + row = 5, + col = '50%', + }, + size = { + width = 60, + height = 'auto', + }, + }, + popupmenu = { + relative = 'editor', + position = { + row = 8, + col = '50%', + }, + size = { + width = 60, + height = 10, + }, + border = { + style = 'rounded', + padding = { 0, 1 }, + }, + win_options = { + winhighlight = { Normal = 'Normal', FloatBorder = 'DiagnosticInfo' }, + }, + }, + }, + } + end, } diff --git a/config/nvim/lua/plugins/telescope.lua b/config/nvim/lua/plugins/telescope.lua index ba62f81..12f6f6e 100644 --- a/config/nvim/lua/plugins/telescope.lua +++ b/config/nvim/lua/plugins/telescope.lua @@ -4,9 +4,12 @@ return { { 'nvim-telescope/telescope.nvim', version = '*', + lazy = false, dependencies = { { 'nvim-lua/plenary.nvim' }, { 'nvim-telescope/telescope-symbols.nvim' }, + { 'folke/which-key.nvim' }, + { 'ThePrimeagen/harpoon' }, -- Fuzzy Finder Algorithm which requires local dependencies to be built. -- Only load if `make` is available @@ -16,13 +19,10 @@ return { cond = vim.fn.executable 'make' == 1, }, }, - setup = function() + config = function() local t = require 'telescope' local a = require 'telescope.actions' - local b = require 'telescope.builtin' local themes = require 'telescope.themes' - require('telescope').load_extension 'harpoon' - t.load_extension 'git_worktree' -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` @@ -54,11 +54,34 @@ return { }, } + -- Load extensions + pcall(t.load_extension, 'harpoon') + pcall(t.load_extension, 'git_worktree') -- Enable telescope fzf native, if installed pcall(t.load_extension, 'fzf') + -- [[ Telescope Keymaps ]] -- See `:help telescope.builtin` - vim.keymap.set('n', 'so', b.oldfiles, { desc = '[?] Find recently opened files' }) + -- See `:help telescope.keymap` + local b = require 'telescope.builtin' + + local wk = require 'which-key' + wk.add { + -- { '', b.buffers, desc = '[ ] Find existing buffers' }, + { 'gR', "lua require('telescope').extensions.git_worktree.create_git_worktree()", desc = 'Create Git worktree' }, + { 'gr', "lua require('telescope').extensions.git_worktree.git_worktrees()", desc = 'Git worktrees' }, + { 'sS', b.git_status, desc = '' }, + { 'sd', b.diagnostics, desc = '[S]earch [D]iagnostics' }, + { 'sf', b.find_files, desc = '[S]earch [F]iles' }, + { 'sg', b.live_grep, desc = '[S]earch by [G]rep' }, + { 'sm', ':Telescope harpoon marks', desc = 'Harpoon Marks' }, + { 'sn', "lua require('telescope').extensions.notify.notify()", desc = 'Notify' }, + { 'so', b.oldfiles, desc = '[?] Find recently opened files' }, + { 'sw', b.grep_string, desc = '[S]earch current [W]ord' }, + { 'st', ':TodoTelescope', desc = 'Telescope: Todo' }, + { '', "lua require('telescope.builtin').commands()", desc = 'Telescope: Commands' }, + } + vim.keymap.set('n', '/', function() -- You can pass additional configuration to telescope to change theme, layout, etc. b.current_buffer_fuzzy_find(themes.get_dropdown { @@ -66,20 +89,6 @@ return { previewer = true, }) end, { desc = '[/] Fuzzily search in current buffer]' }) - - vim.keymap.set('n', 'sf', b.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'sw', b.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', b.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', b.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sb', b.buffers, { desc = '[ ] Find existing buffers' }) - vim.keymap.set('n', 'sS', b.git_status, { desc = '' }) - vim.keymap.set('n', 'sm', ':Telescope harpoon marks', { desc = 'Harpoon [M]arks' }) - vim.keymap.set('n', 'sr', "lua require('telescope').extensions.git_worktree.git_worktrees()") - vim.keymap.set('n', 'sR', "lua require('telescope').extensions.git_worktree.create_git_worktree()") - vim.keymap.set('n', 'sn', "lua require('telescope').extensions.notify.notify()") - - vim.api.nvim_set_keymap('n', 'st', ':TodoTelescope', { noremap = true }) - vim.api.nvim_set_keymap('n', '', "lua require('telescope.builtin').commands()", { noremap = false }) end, }, } diff --git a/config/nvim/lua/plugins/trouble.lua b/config/nvim/lua/plugins/trouble.lua index 38b9d5e..9e9fa67 100644 --- a/config/nvim/lua/plugins/trouble.lua +++ b/config/nvim/lua/plugins/trouble.lua @@ -9,12 +9,17 @@ return { auto_close = true, use_lsp_diagnostic_signs = true, } - vim.keymap.set('n', 'xx', 'TroubleToggle', { silent = true, noremap = true }) - vim.keymap.set('n', 'xw', 'TroubleToggle workspace_diagnostics', { silent = true, noremap = true }) - vim.keymap.set('n', 'xd', 'TroubleToggle document_diagnostics', { silent = true, noremap = true }) - vim.keymap.set('n', 'xl', 'TroubleToggle loclist', { silent = true, noremap = true }) - vim.keymap.set('n', 'xq', 'TroubleToggle quickfix', { silent = true, noremap = true }) - vim.keymap.set('n', 'gR', 'TroubleToggle lsp_references', { silent = true, noremap = true }) + + -- Keybindings + local wk = require 'which-key' + wk.add { + { 'xx', 'TroubleToggle', desc = 'Toggle Trouble' }, + { 'xw', 'TroubleToggle workspace_diagnostics', desc = 'Toggle Workspace Diagnostics' }, + { 'xd', 'TroubleToggle document_diagnostics', desc = 'Toggle Document Diagnostics' }, + { 'xl', 'TroubleToggle loclist', desc = 'Toggle Loclist' }, + { 'xq', 'TroubleToggle quickfix', desc = 'Toggle Quickfix' }, + { 'gR', 'TroubleToggle lsp_references', desc = 'Toggle LSP References' }, + } -- Diagnostic signs -- https://github.com/folke/trouble.nvim/issues/52 diff --git a/config/nvim/lua/plugins/ui.lua b/config/nvim/lua/plugins/ui.lua index e6d5482..08f7bbf 100644 --- a/config/nvim/lua/plugins/ui.lua +++ b/config/nvim/lua/plugins/ui.lua @@ -39,6 +39,9 @@ return { { 'folke/twilight.nvim', ft = 'markdown', -- Highlight markdown files + keys = { + { 'n', 'tw', 'Twilight', desc = 'Twilight' }, + }, }, -- Seamless navigation between tmux panes and vim splits @@ -55,11 +58,11 @@ return { 'TmuxNavigatePrevious', }, keys = { - { '', 'TmuxNavigateLeft' }, - { '', 'TmuxNavigateDown' }, - { '', 'TmuxNavigateUp' }, - { '', 'TmuxNavigateRight' }, - { '', 'TmuxNavigatePrevious' }, + { '', 'TmuxNavigateLeft', desc = 'tmux: Navigate Left' }, + { '', 'TmuxNavigateDown', desc = 'tmux: Navigate Down' }, + { '', 'TmuxNavigateUp', desc = 'tmux: Navigate Up' }, + { '', 'TmuxNavigateRight', desc = 'tmux: Navigate Right' }, + { '', 'TmuxNavigatePrevious', desc = 'tmux: Navigate Previous' }, }, }, -- Cloak allows you to overlay *'s over defined patterns in defined files. @@ -127,11 +130,11 @@ return { wk.add { { 'cb', group = 'CommentBox' }, - { 'cbt', 'CBccbox', desc = 'CommentBox: Box Title' }, - { 'cbd', 'CBd', desc = 'Remove a box' }, - { 'cbl', 'CBline', desc = 'CommentBox: Simple Line' }, - { 'cbm', 'CBllbox14', desc = 'CommentBox: Marked' }, - { 'cbt', 'CBllline', desc = 'CommentBox: Titled Line' }, + { 'cbb', 'CBccbox', desc = 'CommentBox: Box Title' }, + { 'cbd', 'CBd', desc = 'CommentBox: Remove a box' }, + { 'cbl', 'CBline', desc = 'CommentBox: Simple Line' }, + { 'cbm', 'CBllbox14', desc = 'CommentBox: Marked' }, + { 'cbt', 'CBllline', desc = 'CommentBox: Titled Line' }, } end, },