diff --git a/init.lua b/init.lua index d5ae6dc9b2a..187e36d97ab 100644 --- a/init.lua +++ b/init.lua @@ -93,6 +93,90 @@ vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = false +-- [[ LSP ]] +vim.g.rustaceanvim = function() + -- Update this path + local mason_registry = require 'mason-registry' + + local codelldb = vim.fn.expand '$MASON/packages/codelldb' + local extension_path = codelldb .. '/extension/' + local codelldb_path = extension_path .. 'adapter/codelldb' + local liblldb_path = extension_path .. 'lldb/lib/liblldb' + local this_os = vim.uv.os_uname().sysname + + -- The path is different on Windows + if this_os:find 'Windows' then + codelldb_path = extension_path .. 'adapter\\codelldb.exe' + liblldb_path = extension_path .. 'lldb\\bin\\liblldb.dll' + else + -- The liblldb extension is .so for Linux and .dylib for MacOS + liblldb_path = liblldb_path .. (this_os == 'Linux' and '.so' or '.dylib') + end + + local cfg = require 'rustaceanvim.config' + return { + --- Plugin configuration + tools = {}, + --- LSP Configuration + server = { + on_attach = function(client, bufnr) + -- you can also put keymaps in here + local opts = { noremap = true, silent = true } + + vim.api.nvim_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', { noremap = true, silent = true }) + end, + default_settings = { + -- rust-analyzer language server configuration + ['rust-analyzer'] = { + procMacro = { enable = true }, + cachePriming = { + enable = true, + numThreads = 12, + }, + diagnostics = { + enableExperimental = false, + }, + check = { + command = 'clippy', + allTargets = false, + allFeatures = false, + }, + cargo = { + allFeatures = false, + loadOutDirsFromCheck = true, + runBuildScripts = true, + }, + }, + }, + }, + -- DAP configuration + dap = { + adapter = cfg.get_codelldb_adapter(codelldb_path, liblldb_path), + }, + } +end + +vim.lsp.config('pyrefly', { + cmd = { 'pyrefly', 'lsp' }, + filetypes = { 'python' }, + root_dir = vim.fs.root(0, { 'pyproject.toml', 'setup.cfg', 'setup.py', '.git' }), + single_file_support = true, +}) + +vim.lsp.enable 'pyrefly' + +vim.api.nvim_create_autocmd('User', { + pattern = 'GitConflictDetected', + callback = function() + vim.notify('Conflict detected in ' .. vim.fn.expand '') + vim.keymap.set('n', 'cww', function() + engage.conflict_buster() + create_buffer_local_mappings() + end) + end, +}) + -- [[ Setting options ]] -- See `:help vim.o` -- NOTE: You can change these options as you wish! @@ -102,7 +186,7 @@ vim.g.have_nerd_font = false vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true +vim.o.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' @@ -110,6 +194,18 @@ vim.o.mouse = 'a' -- Don't show the mode, since it's already in the status line vim.o.showmode = false +-- A in file is 2 spaces +vim.opt.tabstop = 2 + +-- Indentation amount +vim.opt.shiftwidth = 2 + +-- Editing behavior (backspace/del) +vim.opt.softtabstop = 2 + +-- Use spaces, not tabs +vim.opt.expandtab = true + -- 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. @@ -146,7 +242,7 @@ vim.o.splitbelow = true -- Notice listchars is set using `vim.opt` instead of `vim.o`. -- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables. -- See `:help lua-options` --- and `:help lua-guide-options` +-- and `:help lua-options-guide` vim.o.list = true vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } @@ -171,22 +267,8 @@ vim.o.confirm = true -- See `:help hlsearch` vim.keymap.set('n', '', 'nohlsearch') --- Diagnostic Config & Keymaps --- See :help vim.diagnostic.Opts -vim.diagnostic.config { - update_in_insert = false, - severity_sort = true, - float = { border = 'rounded', source = 'if_many' }, - underline = { severity = vim.diagnostic.severity.ERROR }, - - -- Can switch between these as you prefer - virtual_text = true, -- Text shows up at the end of the line - virtual_lines = false, -- Teest shows up underneath the line, with virtual lines - - -- Auto open the float, so you can easily read the errors when jumping with `[d` and `]d` - jump = { float = true }, -} - +-- Diagnostic keymaps +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror message' }) 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 @@ -255,8 +337,15 @@ rtp:prepend(lazypath) -- -- NOTE: Here is where you install your plugins. require('lazy').setup({ - -- NOTE: Plugins can be added via a link or github org/name. To run setup automatically, use `opts = {}` - { 'NMAC427/guess-indent.nvim', opts = {} }, + -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). + 'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically + + -- NOTE: Plugins can also be added by using a table, + -- with the first argument being the link and the following + -- keys can be used to configure plugin behavior/loading/etc. + -- + -- Use `opts = {}` to automatically pass options to a plugin's `setup()` function, forcing the plugin to be loaded. + -- -- Alternatively, use `config = function() ... end` for full control over the configuration. -- If you prefer to call `setup` explicitly, use: @@ -302,15 +391,51 @@ require('lazy').setup({ { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', - event = 'VimEnter', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' opts = { -- delay between pressing a key and opening which-key (milliseconds) + -- this setting is independent of vim.o.timeoutlen delay = 0, - icons = { mappings = vim.g.have_nerd_font }, + 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 which-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 spec = { - { 's', group = '[S]earch', mode = { 'n', 'v' } }, + { 's', group = '[S]earch' }, { 't', group = '[T]oggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, }, @@ -326,16 +451,6 @@ require('lazy').setup({ { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', - -- By default, Telescope is included and acts as your picker for everything. - - -- If you would like to switch to a different picker (like snacks, or fzf-lua) - -- you can disable the Telescope plugin by setting enabled to false and enable - -- your replacement picker by requiring it explicitly (e.g. 'custom.plugins.snacks') - - -- Note: If you customize your config for yourself, - -- it’s best to remove the Telescope plugin config entirely - -- instead of just disabling it here, to keep your config clean. - enabled = true, event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim', @@ -388,7 +503,9 @@ require('lazy').setup({ -- }, -- pickers = {} extensions = { - ['ui-select'] = { require('telescope.themes').get_dropdown() }, + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, }, } @@ -402,49 +519,22 @@ require('lazy').setup({ vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set({ 'n', 'v' }, 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', 'sc', builtin.commands, { desc = '[S]earch [C]ommands' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - -- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info, - -- it is better explained there). This allows easily switching between pickers if you prefer using something else! - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }), - callback = function(event) - local buf = event.buf - - -- Find references for the word under your cursor. - vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' }) - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. - vim.keymap.set('n', 'gri', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' }) - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . - vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' }) - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' }) - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' }) - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. - vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' }) - end, + -- Git Worktree + vim.keymap.set('n', 'gw', "lua require('telescope').extensions.git_worktree()CR", { + desc = 'Git Worktrees', + }) + vim.keymap.set('n', 'gW', "lua require('telescope').extensions.create_git_worktree()CR", { + desc = 'Create Git Worktree', }) - -- Override default behavior and theme when searching + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { @@ -473,6 +563,18 @@ require('lazy').setup({ }, -- 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 = '${3rd}/luv/library', words = { 'vim%.uv' } }, + }, + }, + }, { -- Main LSP Configuration 'neovim/nvim-lspconfig', @@ -481,6 +583,7 @@ require('lazy').setup({ -- Mason must be loaded before its dependents so we need to set it up here. -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` { 'mason-org/mason.nvim', opts = {} }, + 'mason-org/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. @@ -540,17 +643,55 @@ require('lazy').setup({ -- or a suggestion from your LSP for this to activate. map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) + -- Find references for the word under your cursor. + map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + + -- Jump to the implementation of the word under your cursor. + -- Useful when your language has ways of declaring types without an actual implementation. + map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + + -- Jump to the definition of the word under your cursor. + -- This is where a variable was first declared, or where a function is defined, etc. + -- To jump back, press . + map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') + + -- Fuzzy find all the symbols in your current workspace. + -- Similar to document symbols, except searches over your entire project. + map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') + + -- Jump to the type of the word under your cursor. + -- Useful when you're not sure what type a variable is and you want to see + -- the definition of its *type*, not where it was *defined*. + map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') + + -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10) + ---@param client vim.lsp.Client + ---@param method vim.lsp.protocol.Method + ---@param bufnr? integer some lsp support methods only in specific files + ---@return boolean + local function client_supports_method(client, method, bufnr) + if vim.fn.has 'nvim-0.11' == 1 then + return client:supports_method(method, bufnr) + else + return client.supports_method(method, { bufnr = bufnr }) + end + end + -- The following two autocommands are used to highlight references of the -- word under your cursor when your cursor rests there for a little while. -- See `:help CursorHold` for information about when this is executed -- -- 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:supports_method('textDocument/documentHighlight', event.buf) then + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, @@ -577,32 +718,134 @@ require('lazy').setup({ -- 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:supports_method('textDocument/inlayHint', event.buf) then + if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then map('th', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') end end, }) + -- Diagnostic Config + -- See :help vim.diagnostic.Opts + vim.diagnostic.config { + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = { severity = vim.diagnostic.severity.ERROR }, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', + [vim.diagnostic.severity.WARN] = '󰀪 ', + [vim.diagnostic.severity.INFO] = '󰋽 ', + [vim.diagnostic.severity.HINT] = '󰌶 ', + }, + } or {}, + virtual_text = { + source = 'if_many', + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, + } + -- LSP servers and clients are able to communicate to each other what features they support. -- By default, Neovim doesn't support everything that is in the LSP specification. -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. local capabilities = require('blink.cmp').get_lsp_capabilities() - + capabilities.offsetEncoding = { 'utf-8' } -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- See `:help lsp-config` for information about keys and how to configure + -- + -- Add any additional override configuration in the following tables. Available keys are: + -- - cmd (table): Override the default command used to start the server + -- - filetypes (table): Override the default list of associated filetypes for the server + -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. + -- - settings (table): Override the default settings passed when initializing the server. + -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { -- clangd = {}, -- gopls = {}, - -- pyright = {}, + -- pyright = { + -- settings = { + -- python = { + -- pythonPath = './.venv/bin/python', + -- }, + -- }, + -- }, -- rust_analyzer = {}, + -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- -- 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 (`ts_ls`) will work just fine -- ts_ls = {}, + tailwindcss = { + filetypes = { 'html', 'css', 'javascriptreact', 'typescriptreact', 'vue', 'svelte' }, + -- If you need to add custom filetypes or logic: + -- settings = { + -- tailwindCSS = { + -- includeLanguages = { + -- elixir = "html-eex", + -- heex = "html-eex", + -- }, + -- }, + -- }, + }, + pylsp = { + settings = { + pylsp = { + plugins = { + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + autopep8 = { enabled = false }, + yapf = { enabled = false }, + mccabe = { enabled = false }, + pylsp_mypy = { enabled = false }, + pylsp_black = { enabled = false }, + pylsp_isort = { enabled = false }, + }, + }, + }, + }, + ruff = { + -- Notes on code actions: https://github.com/astral-sh/ruff-lsp/issues/119#issuecomment-1595628355 + -- Get isort like behavior: https://github.com/astral-sh/ruff/issues/8926#issuecomment-1834048218 + commands = { + RuffAutofix = { + function() + vim.lsp.buf.execute_command { + command = 'ruff.applyAutofix', + arguments = { + { uri = vim.uri_from_bufnr(0) }, + }, + } + end, + description = 'Ruff: Fix all auto-fixable problems', + }, + }, + }, + + lua_ls = { + -- cmd = { ... }, + -- filetypes = { ... }, + -- capabilities = {}, + settings = { + Lua = { + completion = { + callSnippet = 'Replace', + }, + -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings + -- diagnostics = { disable = { 'missing-fields' } }, + }, + }, + }, } -- Ensure the servers and tools above are installed @@ -612,88 +855,71 @@ require('lazy').setup({ -- :Mason -- -- You can press `g?` for help in this menu. + -- + -- `mason` had to be setup earlier: to configure its options see the + -- `dependencies` table for `nvim-lspconfig` above. + -- + -- You can add other tools here that you want Mason to install + -- for you, so that they are available from within Neovim. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { - 'lua_ls', -- Lua Language server 'stylua', -- Used to format Lua code - -- You can add other tools here that you want Mason to install }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - for name, server in pairs(servers) do - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - vim.lsp.config(name, server) - vim.lsp.enable(name) - end - - -- Special Lua Config, as recommended by neovim help docs - vim.lsp.config('lua_ls', { - on_init = function(client) - if client.workspace_folders then - local path = client.workspace_folders[1].name - if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end - end + for server, cfg in pairs(servers) do + -- For each LSP server (cfg), we merge: + -- 1. A fresh empty table (to avoid mutating capabilities globally) + -- 2. Your capabilities object with Neovim + cmp features + -- 3. Any server-specific cfg.capabilities if defined in `servers` + cfg.capabilities = vim.tbl_deep_extend('force', {}, capabilities, cfg.capabilities or {}) - client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { - runtime = { - version = 'LuaJIT', - path = { 'lua/?.lua', 'lua/?/init.lua' }, - }, - workspace = { - checkThirdParty = false, - -- NOTE: this is a lot slower and will cause issues when working on your own configuration. - -- See https://github.com/neovim/nvim-lspconfig/issues/3189 - library = vim.api.nvim_get_runtime_file('', true), - }, - }) - end, - settings = { - Lua = {}, - }, - }) - vim.lsp.enable 'lua_ls' + vim.lsp.config(server, cfg) + vim.lsp.enable(server) + end end, }, - { -- Autoformat - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'f', - function() require('conform').format { async = true, lsp_format = 'fallback' } end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- 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 } - if disable_filetypes[vim.bo[bufnr].filetype] then - return nil - else - return { - timeout_ms = 500, - lsp_format = 'fallback', - } - end - end, - formatters_by_ft = { - lua = { 'stylua' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, - }, - }, + -- { -- Autoformat + -- 'stevearc/conform.nvim', + -- event = { 'BufWritePre' }, + -- cmd = { 'ConformInfo' }, + -- keys = { + -- { + -- 'f', + -- function() + -- require('conform').format { async = true, lsp_format = 'fallback' } + -- end, + -- mode = '', + -- desc = '[F]ormat buffer', + -- }, + -- }, + -- opts = { + -- notify_on_error = false, + -- format_on_save = function(bufnr) + -- -- Disable "format_on_save lsp_fallback" for languages that don't + -- -- 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 } + -- if disable_filetypes[vim.bo[bufnr].filetype] then + -- return nil + -- else + -- return { + -- timeout_ms = 500, + -- lsp_format = 'fallback', + -- } + -- end + -- end, + -- formatters_by_ft = { + -- lua = { 'stylua' }, + -- -- Conform can also run multiple formatters sequentially + -- -- python = { "isort", "black" }, + -- -- + -- -- You can use 'stop_after_first' to run the first available formatter from the list + -- -- javascript = { "prettierd", "prettier", stop_after_first = true }, + -- }, + -- }, + -- }, { -- Autocompletion 'saghen/blink.cmp', @@ -715,15 +941,14 @@ require('lazy').setup({ -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, + { + 'rafamadriz/friendly-snippets', + config = function() require('luasnip.loaders.from_vscode').lazy_load() end, + }, }, opts = {}, }, + 'folke/lazydev.nvim', }, --- @module 'blink.cmp' --- @type blink.cmp.Config @@ -769,7 +994,10 @@ require('lazy').setup({ }, sources = { - default = { 'lsp', 'path', 'snippets' }, + default = { 'lsp', 'path', 'snippets', 'lazydev' }, + providers = { + lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 }, + }, }, snippets = { preset = 'luasnip' }, @@ -814,7 +1042,7 @@ require('lazy').setup({ { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, { -- Collection of various small independent plugins/modules - 'nvim-mini/mini.nvim', + 'echasnovski/mini.nvim', config = function() -- Better Around/Inside textobjects -- @@ -845,20 +1073,33 @@ require('lazy').setup({ statusline.section_location = function() return '%2l:%-2v' end -- ... and there is more! - -- Check out: https://github.com/nvim-mini/mini.nvim + -- Check out: https://github.com/echasnovski/mini.nvim end, }, - { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', - config = function() - local filetypes = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' } - require('nvim-treesitter').install(filetypes) - vim.api.nvim_create_autocmd('FileType', { - pattern = filetypes, - callback = function() vim.treesitter.start() end, - }) - end, + build = ':TSUpdate', + main = 'nvim-treesitter.configs', -- Sets main module to use for opts + -- [[ Configure Treesitter ]] See `:help nvim-treesitter` + opts = { + ensure_installed = { 'python', 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + -- Autoinstall languages that are not installed + auto_install = true, + highlight = { + enable = true, + -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. + -- If you are experiencing weird indenting issues, add the language to + -- the list of additional_vim_regex_highlighting and disabled languages for indent. + additional_vim_regex_highlighting = { 'ruby' }, + }, + indent = { enable = true, disable = { 'ruby' } }, + }, + -- 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 }, -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted the @@ -870,18 +1111,18 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', + require 'kickstart.plugins.debug', -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', + require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps + require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/custom/plugins/git-conflict.lua b/lua/custom/plugins/git-conflict.lua new file mode 100644 index 00000000000..aa718bc35bd --- /dev/null +++ b/lua/custom/plugins/git-conflict.lua @@ -0,0 +1,11 @@ +-- You can add your own plugins here or in other files in this directory! +-- I promise not to create any merge conflicts in this directory :) +-- +-- See the kickstart.nvim README for more information +return { + { + 'akinsho/git-conflict.nvim', + version = '*', + config = true, + }, +} diff --git a/lua/custom/plugins/git-worktree.lua b/lua/custom/plugins/git-worktree.lua new file mode 100644 index 00000000000..fdb209d71bf --- /dev/null +++ b/lua/custom/plugins/git-worktree.lua @@ -0,0 +1,12 @@ +return { + { + 'ThePrimeagen/git-worktree.nvim', + dependencies = { + 'nvim-telescope/telescope.nvim', + }, + config = function() + require('git-worktree').setup() + require('telescope').load_extension 'git_worktree' + end, + }, +} diff --git a/lua/custom/plugins/none-ls.lua b/lua/custom/plugins/none-ls.lua new file mode 100644 index 00000000000..ddf05778f12 --- /dev/null +++ b/lua/custom/plugins/none-ls.lua @@ -0,0 +1,87 @@ +-- Format on save and linters +return { + { + 'nvimtools/none-ls.nvim', + dependencies = { + 'nvimtools/none-ls-extras.nvim', + 'jayp0521/mason-null-ls.nvim', -- ensure dependencies are installed + }, + config = function() + local null_ls = require 'null-ls' + local formatting = null_ls.builtins.formatting -- to setup formatters + local diagnostics = null_ls.builtins.diagnostics -- to setup linters + + -- list of formatters & linters for mason to install + require('mason-null-ls').setup { + ensure_installed = { + 'checkmake', + 'prettier', -- ts/js formatter + 'stylua', -- lua formatter + 'eslint_d', -- ts/js linter + 'shfmt', + 'ruff', + }, + -- auto-install configured formatters & linters (with null-ls) + automatic_installation = true, + } + + local sources = { + -- Linters + diagnostics.checkmake, + + -- ESLint diagnostics (ESLint 9 compatible) + require('none-ls.diagnostics.eslint_d').with { + prefer_local = 'node_modules/.bin', + filetypes = { + 'javascript', + 'typescript', + 'javascriptreact', + 'typescriptreact', + }, + condition = function(utils) + return utils.root_has_file { + 'eslint.config.js', + 'eslint.config.mjs', + 'eslint.config.cjs', + } + end, + }, + + -- ESLint code actions + require('none-ls.code_actions.eslint_d').with { + prefer_local = 'node_modules/.bin', + }, + + -- Formatters + formatting.prettier.with { + filetypes = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'html', 'json', 'yaml', 'markdown' }, + }, + + formatting.stylua, + formatting.shfmt.with { args = { '-i', '4' } }, + formatting.terraform_fmt, + require('none-ls.formatting.ruff').with { extra_args = { '--config=pyproject.toml' } }, + -- require('none-ls.formatting.ruff_format').with { extra_args = { '--config=pyproject.toml' } }, + } + + local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) + null_ls.setup { + -- debug = true, -- Enable debug mode. Inspect logs with :NullLsLog. + sources = sources, + -- you can reuse a shared lspconfig on_attach callback here + on_attach = function(client, bufnr) + if client.supports_method 'textDocument/formatting' then + vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr } + vim.api.nvim_create_autocmd('BufWritePre', { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format { async = false } + end, + }) + end + end, + } + end, + }, +} diff --git a/lua/custom/plugins/rust.lua b/lua/custom/plugins/rust.lua new file mode 100644 index 00000000000..03186ac9ef0 --- /dev/null +++ b/lua/custom/plugins/rust.lua @@ -0,0 +1,7 @@ +return { + { + 'mrcjkb/rustaceanvim', + version = '^6', -- Recommended + lazy = false, -- This plugin is already lazy + }, +} diff --git a/lua/custom/plugins/tmux.lua b/lua/custom/plugins/tmux.lua new file mode 100644 index 00000000000..2ffb7a4fb2e --- /dev/null +++ b/lua/custom/plugins/tmux.lua @@ -0,0 +1,20 @@ +return { + { + 'christoomey/vim-tmux-navigator', + cmd = { + 'TmuxNavigateLeft', + 'TmuxNavigateDown', + 'TmuxNavigateUp', + 'TmuxNavigateRight', + 'TmuxNavigatePrevious', + 'TmuxNavigatorProcessList', + }, + keys = { + { '', 'TmuxNavigateLeft' }, + { '', 'TmuxNavigateDown' }, + { '', 'TmuxNavigateUp' }, + { '', 'TmuxNavigateRight' }, + { '', 'TmuxNavigatePrevious' }, + }, + }, +} diff --git a/lua/custom/plugins/typescript.lua b/lua/custom/plugins/typescript.lua new file mode 100644 index 00000000000..368002074d2 --- /dev/null +++ b/lua/custom/plugins/typescript.lua @@ -0,0 +1,7 @@ +return { + { + 'pmizio/typescript-tools.nvim', + dependencies = { 'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig' }, + opts = {}, + }, +} diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 1e3570f9bf3..807eacc41c3 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -7,21 +7,18 @@ -- kickstart.nvim and not kitchen-sink.nvim ;) return { - -- NOTE: Yes, you can install new plugins here! 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well dependencies = { - -- Creates a beautiful debugger UI + -- Create a beutifull debugger UI 'rcarriga/nvim-dap-ui', - - -- Required dependency for nvim-dap-ui + -- Required dependency for nvim dap ui + 'theHamsta/nvim-dap-virtual-text', 'nvim-neotest/nvim-nio', - - -- Installs the debug adapters for you - 'mason-org/mason.nvim', + -- Install the debug adapter for you + 'williamboman/mason.nvim', 'jay-babu/mason-nvim-dap.nvim', - - -- Add your own debuggers here + -- Add your own debugger here + 'mfussenegger/nvim-dap-python', 'leoluz/nvim-dap-go', }, keys = { @@ -65,70 +62,144 @@ return { }, config = function() local dap = require 'dap' - local dapui = require 'dapui' + local ui = require 'dapui' + + require('dapui').setup() + require('dap-go').setup() require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_installation = true, + automatic_instalation = true, - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information handlers = {}, - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want 'delve', + 'python', }, } - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', + require('nvim-dap-virtual-text').setup { + display_callback = function(variable) + local name = string.lower(variable.name) + local value = string.lower(variable.value) + if name:match 'secret' or name:match 'api' or value:match 'secret' or value:match 'api' then return '*****' end + + if #variable.value > 15 then return ' ' .. string.sub(variable.value, 1, 15) .. '... ' end + + return ' ' .. variable.value + end, + } + + -- Handled by nvim-dap-go + -- dap.adapters.go = { + -- type = "server", + -- port = "${port}", + -- executable = { + -- command = "dlv", + -- args = { "dap", "-l", "127.0.0.1:${port}" }, + -- }, + -- } + + local elixir_ls_debugger = vim.fn.exepath 'elixir-ls-debugger' + if elixir_ls_debugger ~= '' then + dap.adapters.mix_task = { + type = 'executable', + command = elixir_ls_debugger, + } + + dap.configurations.elixir = { + { + type = 'mix_task', + name = 'phoenix server', + task = 'phx.server', + request = 'launch', + projectDir = '${workspaceFolder}', + exitAfterTaskReturns = false, + debugAutoInterpretAllModules = false, }, + } + end + + -- CodeLLDB debug adapter location + local codelldb = vim.fn.expand '$MASON/packages/codelldb' + local extension_path = codelldb .. '/extension/' + local codelldb_path = extension_path .. 'adapter/codelldb' + + -- Configure the LLDB adapter + dap.adapters.codelldb = { + type = 'server', + port = '${port}', + executable = { + command = codelldb_path, + args = { '--port', '${port}' }, }, + enrich_config = function(config, on_config) + -- If the configuration(s) in `launch.json` contains a `cargo` section + -- send the configuration off to the cargo_inspector. + if config['cargo'] ~= nil then on_config(cargo_inspector(config)) end + end, } - -- Change breakpoint icons - -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) - -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) - -- local breakpoint_icons = vim.g.have_nerd_font - -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } - -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } - -- for type, icon in pairs(breakpoint_icons) do - -- local tp = 'Dap' .. type - -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' - -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) - -- end - - 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 - - -- Install golang specific config - require('dap-go').setup { - delve = { - -- On Windows delve must be run attached or it crashes. - -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring - detached = vim.fn.has 'win32' == 0, + -- Configure LLDB adapter + dap.adapters.lldb = { + type = 'server', + port = '${port}', + executable = { + command = codelldb_path, + args = { '--port', '${port}' }, + detached = false, }, } + + -- Default debug configuration for C, C++ + dap.configurations.c = { + { + name = 'Debug an Executable', + type = 'lldb', + request = 'launch', + program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + }, + } + + dap.configurations.cpp = dap.configurations.c + dap.configurations.rust = { + { + name = 'Debug an Executable', + type = 'lldb', + request = 'launch', + program = function() + local cwd = vim.fn.getcwd() + local default_binary = cwd .. '/target/debug/' .. vim.fn.fnamemodify(cwd, ':t') + return vim.fn.input('Path to executable: ', default_binary, 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + }, + } + + -- Override default configurations with `launch.json` + require('dap.ext.vscode').load_launchjs('.nvim/launch.json', { lldb = { 'c', 'cpp', 'rust' } }) + + vim.keymap.set('n', 'b', dap.toggle_breakpoint) + vim.keymap.set('n', 'gb', dap.run_to_cursor) + + -- Eval var under cursor + vim.keymap.set('n', '?', function() require('dapui').eval(nil, { enter = true }) end) + + vim.keymap.set('n', '', dap.continue) + vim.keymap.set('n', '', dap.step_into) + vim.keymap.set('n', '', dap.step_over) + vim.keymap.set('n', '', dap.step_out) + vim.keymap.set('n', '', dap.step_back) + vim.keymap.set('n', '', dap.restart) + + dap.listeners.before.attach.dapui_config = function() ui.open() end + dap.listeners.before.launch.dapui_config = function() ui.open() end + dap.listeners.before.event_terminated.dapui_config = function() ui.close() end + dap.listeners.before.event_exited.dapui_config = function() ui.close() end + + require('dap-python').setup() end, }