From bbb0cb9c5bb3073b7581c54493cd52efa784ef2b Mon Sep 17 00:00:00 2001 From: Tony Grosinger Date: Thu, 3 Oct 2024 11:52:15 -0700 Subject: [PATCH] Neovim: Update to Kickstart at 4120893 Latest commit to Kickstart as of 2024-10-02. --- nvim/init.lua | 209 +++++++++++++++--------- nvim/lua/kickstart/health.lua | 6 +- nvim/lua/kickstart/plugins/debug.lua | 35 ++-- nvim/lua/kickstart/plugins/lint.lua | 2 +- nvim/lua/kickstart/plugins/neo-tree.lua | 2 +- 5 files changed, 162 insertions(+), 92 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index cff147a..ec7ca68 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -39,6 +39,9 @@ Kickstart Guide: If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. +NOTE: Updated to 4120893 +https://github.com/nvim-lua/kickstart.nvim/compare/4120893..master + --]] -- Set as the leader key @@ -68,9 +71,12 @@ vim.opt.mouse = 'a' vim.opt.showmode = false -- Sync clipboard between OS and Neovim. +-- Schedule the setting after `UiEnter` because it can increase startup-time. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` -vim.opt.clipboard = 'unnamedplus' +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) -- Display tabs as 2 spaces vim.opt.tabstop = 2 @@ -117,14 +123,11 @@ vim.opt.scrolloff = 10 -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` --- Set highlight on search, but clear on pressing in normal mode -vim.opt.hlsearch = true +-- Clear highlights on search when pressing in normal mode +-- See `:help hlsearch` vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier @@ -189,9 +192,12 @@ vim.api.nvim_create_autocmd({ 'BufWritePre' }, { -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' -if not vim.loop.fs_stat(lazypath) then +if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' - vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } + local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } + if vim.v.shell_error ~= 0 then + error('Error cloning lazy.nvim:\n' .. out) + end end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) @@ -210,12 +216,6 @@ require('lazy').setup({ 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically -- Use `opts = {}` to force a plugin to be loaded. - -- - -- This is equivalent to: - -- require('Comment').setup({}) - - -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, -- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- @@ -235,28 +235,58 @@ require('lazy').setup({ { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' - config = function() -- This is the function that runs, AFTER loading - require('which-key').setup() + opts = { + icons = { + -- set icon mappings to true if you have a Nerd Font + mappings = vim.g.have_nerd_font, + -- If you are using a Nerd Font: set icons.keys to an empty table which will use the + -- default whick-key.nvim defined Nerd Font icons, otherwise define a string table + keys = vim.g.have_nerd_font and {} or { + Up = ' ', + Down = ' ', + Left = ' ', + Right = ' ', + C = ' ', + M = ' ', + D = ' ', + S = ' ', + CR = ' ', + Esc = ' ', + ScrollWheelDown = ' ', + ScrollWheelUp = ' ', + NL = ' ', + BS = ' ', + Space = ' ', + Tab = ' ', + F1 = '', + F2 = '', + F3 = '', + F4 = '', + F5 = '', + F6 = '', + F7 = '', + F8 = '', + F9 = '', + F10 = '', + F11 = '', + F12 = '', + }, + }, -- Document existing key chains - require('which-key').register { - ['a'] = { name = '[A]i', _ = 'which_key_ignore' }, - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, - ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, - ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, - ['x'] = { name = 'Trouble [X]', _ = 'which_key_ignore' }, - ['p'] = { name = '[P]review', _ = 'which_key_ignore' }, - } - -- visual mode - require('which-key').register({ - ['a'] = { '[A]i' }, - ['h'] = { 'Git [H]unk' }, - }, { mode = 'v' }) - end, + spec = { + { 'a', group = '[A]i', mode = { 'n', 'v' } }, + { 'c', group = '[C]ode', mode = { 'n', 'x' } }, + { 'd', group = '[D]ocument' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + { 'p', group = '[P]review' }, + { 'r', group = '[R]ename' }, + { 's', group = '[S]earch' }, + { 't', group = '[T]oggle' }, + { 'w', group = '[W]orkspace' }, + { 'x', group = 'Trouble [X]' }, + }, + }, }, { -- Fuzzy Finder (files, lsp, etc) @@ -398,7 +428,22 @@ require('lazy').setup({ end, }, - { -- LSP Configuration & Plugins + -- LSP Plugins + { + -- `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' } }, + }, + }, + }, + { 'Bilal2453/luvit-meta', lazy = true }, + { + -- Main LSP Configuration 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs and related tools to stdpath for Neovim @@ -410,9 +455,8 @@ require('lazy').setup({ -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'j-hui/fidget.nvim', opts = {} }, - -- `neodev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - { 'folke/neodev.nvim', opts = {} }, + -- Allows extra capabilities provided by nvim-cmp + 'hrsh7th/cmp-nvim-lsp', }, config = function() -- LSP provides Neovim with features like: @@ -437,8 +481,9 @@ require('lazy').setup({ callback = function(event) -- Create a function that lets us more easily define mappings specific -- for LSP related items. It sets the mode, buffer and description for us each time. - local map = function(keys, func, desc) - vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end -- Jump to the definition of the word under your cursor. @@ -472,11 +517,7 @@ require('lazy').setup({ -- Execute a code action, usually your cursor needs to be on top of an error -- or a suggestion from your LSP for this to activate. - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - - -- Opens a popup that displays documentation about the word under your cursor - -- See `:help K` for why this keymap. - map('K', vim.lsp.buf.hover, 'Hover Documentation') + map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. @@ -488,7 +529,7 @@ require('lazy').setup({ -- -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client.server_capabilities.documentHighlightProvider then + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, @@ -511,13 +552,13 @@ require('lazy').setup({ }) end - -- The following autocommand is used to enable inlay hints in your + -- The following code creates a keymap to toggle inlay hints in your -- code, if the language server you are using supports them -- -- This may be unwanted, since they displace some of your code - if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') end end, @@ -553,8 +594,8 @@ require('lazy').setup({ -- Some languages (like typescript) have entire language plugins that can be useful: -- https://github.com/pmizio/typescript-tools.nvim -- - -- But for many setups, the LSP (`tsserver`) will work just fine - tsserver = {}, + -- But for many setups, the LSP (`ts_ls`) will work just fine + ts_ls = {}, eslint_d = {}, tailwindcss = {}, @@ -610,12 +651,13 @@ require('lazy').setup({ { -- Autoformat 'stevearc/conform.nvim', - lazy = false, + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, keys = { { 'f', function() - require('conform').format { async = true, lsp_fallback = true } + require('conform').format { async = true } end, mode = '', desc = '[F]ormat buffer', @@ -628,9 +670,15 @@ require('lazy').setup({ -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. local disable_filetypes = { c = true, cpp = true } + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = 'never' + else + lsp_format_opt = 'fallback' + end return { timeout_ms = 500, - lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], + lsp_format = lsp_format_opt, } end, formatters_by_ft = { @@ -641,9 +689,8 @@ require('lazy').setup({ -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- - -- You can use a sub-list to tell conform to run *until* a formatter - -- is found. - -- javascript = { { "prettierd", "prettier" } }, + -- You can use 'stop_after_first' to run the first available formatter from the list + -- javascript = { "prettierd", "prettier", stop_after_first = true }, }, }, }, @@ -757,6 +804,11 @@ require('lazy').setup({ -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps }, sources = { + { + name = 'lazydev', + -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it + group_index = 0, + }, { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, @@ -834,7 +886,7 @@ require('lazy').setup({ -- -- Examples: -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [']quote + -- - yinq - [Y]ank [I]nside [N]ext [Q]uote -- - ci' - [C]hange [I]nside [']quote require('mini.ai').setup { n_lines = 500 } @@ -867,8 +919,26 @@ require('lazy').setup({ { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate', + main = 'nvim-treesitter.configs', -- Sets main module to use for opts + -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'vim', 'vimdoc', 'sql', 'go', 'templ', 'typescript', 'javascript' }, + ensure_installed = { + 'bash', + 'diff', + 'html', + 'lua', + 'luadoc', + 'markdown', + 'markdown_inline', + 'query', + 'vim', + 'vimdoc', + 'sql', + 'go', + 'templ', + 'typescript', + 'javascript', + }, -- Autoinstall languages that are not installed auto_install = true, highlight = { @@ -880,21 +950,12 @@ require('lazy').setup({ }, indent = { enable = true, disable = { 'ruby' } }, }, - config = function(_, opts) - -- [[ Configure Treesitter ]] See `:help nvim-treesitter` - - -- Prefer git instead of curl in order to improve connectivity in some environments - require('nvim-treesitter.install').prefer_git = true - ---@diagnostic disable-next-line: missing-fields - require('nvim-treesitter.configs').setup(opts) - - -- There are additional nvim-treesitter modules that you can use to interact - -- with nvim-treesitter. You should go explore a few and see what interests you: - -- - -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` - -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context - -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects - end, + -- There are additional nvim-treesitter modules that you can use to interact + -- with nvim-treesitter. You should go explore a few and see what interests you: + -- + -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` + -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context + -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects }, -- -- Here are some example plugins that I've included in the Kickstart repository. diff --git a/nvim/lua/kickstart/health.lua b/nvim/lua/kickstart/health.lua index 04df77b..b59d086 100644 --- a/nvim/lua/kickstart/health.lua +++ b/nvim/lua/kickstart/health.lua @@ -6,13 +6,13 @@ --]] local check_version = function() - local verstr = string.format('%s.%s.%s', vim.version().major, vim.version().minor, vim.version().patch) - if not vim.version.cmp then + local verstr = tostring(vim.version()) + if not vim.version.ge then vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) return end - if vim.version.cmp(vim.version(), { 0, 9, 4 }) >= 0 then + if vim.version.ge(vim.version(), '0.10-dev') then vim.health.ok(string.format("Neovim version is: '%s'", verstr)) else vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) diff --git a/nvim/lua/kickstart/plugins/debug.lua b/nvim/lua/kickstart/plugins/debug.lua index 5514e07..e89b5e7 100644 --- a/nvim/lua/kickstart/plugins/debug.lua +++ b/nvim/lua/kickstart/plugins/debug.lua @@ -23,6 +23,28 @@ return { -- Add your own debuggers here 'leoluz/nvim-dap-go', }, + keys = function(_, keys) + local dap = require 'dap' + local dapui = require 'dapui' + return { + -- Basic debugging keymaps, feel free to change to your liking! + { '', dap.continue, desc = 'Debug: Start/Continue' }, + { '', dap.step_into, desc = 'Debug: Step Into' }, + { '', dap.step_over, desc = 'Debug: Step Over' }, + { '', dap.step_out, desc = 'Debug: Step Out' }, + { 'b', dap.toggle_breakpoint, desc = 'Debug: Toggle Breakpoint' }, + { + 'B', + function() + dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') + end, + desc = 'Debug: Set Breakpoint', + }, + -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. + { '', dapui.toggle, desc = 'Debug: See last session result.' }, + unpack(keys), + } + end, config = function() local dap = require 'dap' local dapui = require 'dapui' @@ -44,16 +66,6 @@ return { }, } - -- Basic debugging keymaps, feel free to change to your liking! - vim.keymap.set('n', '', dap.continue, { desc = 'Debug: Start/Continue' }) - vim.keymap.set('n', '', dap.step_into, { desc = 'Debug: Step Into' }) - vim.keymap.set('n', '', dap.step_over, { desc = 'Debug: Step Over' }) - vim.keymap.set('n', '', dap.step_out, { desc = 'Debug: Step Out' }) - vim.keymap.set('n', 'b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' }) - vim.keymap.set('n', 'B', function() - dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, { desc = 'Debug: Set Breakpoint' }) - -- Dap UI setup -- For more information, see |:help nvim-dap-ui| dapui.setup { @@ -76,9 +88,6 @@ return { }, } - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - vim.keymap.set('n', '', dapui.toggle, { desc = 'Debug: See last session result.' }) - dap.listeners.after.event_initialized['dapui_config'] = dapui.open dap.listeners.before.event_terminated['dapui_config'] = dapui.close dap.listeners.before.event_exited['dapui_config'] = dapui.close diff --git a/nvim/lua/kickstart/plugins/lint.lua b/nvim/lua/kickstart/plugins/lint.lua index 4380513..902582d 100644 --- a/nvim/lua/kickstart/plugins/lint.lua +++ b/nvim/lua/kickstart/plugins/lint.lua @@ -48,7 +48,7 @@ return { vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { group = lint_augroup, callback = function() - require('lint').try_lint() + lint.try_lint() end, }) end, diff --git a/nvim/lua/kickstart/plugins/neo-tree.lua b/nvim/lua/kickstart/plugins/neo-tree.lua index c793b88..f126d68 100644 --- a/nvim/lua/kickstart/plugins/neo-tree.lua +++ b/nvim/lua/kickstart/plugins/neo-tree.lua @@ -11,7 +11,7 @@ return { }, cmd = 'Neotree', keys = { - { '\\', ':Neotree reveal', { desc = 'NeoTree reveal' } }, + { '\\', ':Neotree reveal', desc = 'NeoTree reveal' }, }, opts = { filesystem = {