From 5a658d4bb98bcacacaecd5f93569f40c1a51b7c8 Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Wed, 7 Aug 2024 20:28:42 -0500 Subject: [PATCH] update --- lazy-lock.json | 116 +++++++-------- lua/rayandrew/lazy.lua | 2 + lua/rayandrew/plugins/editor.lua | 29 +++- lua/rayandrew/plugins/general.lua | 9 ++ lua/rayandrew/plugins/lsp.lua | 2 +- lua/rayandrew/plugins/treesitter.lua | 139 ++++++++---------- lua/rayandrew/plugins/utilities.lua | 9 +- lua/rayandrew/root.lua | 205 +++++++++++++++++++++++++++ lua/rayandrew/theme.lua | 3 +- lua/rayandrew/tools.lua | 2 + lua/rayandrew/util.lua | 109 ++++++++++++-- 11 files changed, 461 insertions(+), 164 deletions(-) create mode 100644 lua/rayandrew/root.lua diff --git a/lazy-lock.json b/lazy-lock.json index 03a4426..aef69d5 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,68 +1,68 @@ { - "LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" }, + "LuaSnip": { "branch": "master", "commit": "ce0a05ab4e2839e1c48d072c5236cce846a387bc" }, "bufresize.nvim": { "branch": "master", "commit": "3b19527ab936d6910484dcc20fb59bdb12322d8b" }, - "cellular-automaton.nvim": { "branch": "main", "commit": "b7d056dab963b5d3f2c560d92937cb51db61cb5b" }, - "chezmoi.nvim": { "branch": "refactor", "commit": "a0fd6e164493b9d16137ee362c6b2106e5c32fa3" }, - "chezmoi.vim": { "branch": "main", "commit": "a35b426db9d83f8fcf43981f299ad3145d001af2" }, - "cloak.nvim": { "branch": "main", "commit": "9abe4e986e924fc54a972c1b0ff52b65a0622624" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, - "conform.nvim": { "branch": "master", "commit": "34b81e70da83e26c048290204de44268eb59814e" }, - "copilot.vim": { "branch": "release", "commit": "57a0115908895f465eb3476f03a0aaa7096e8fe1" }, - "everforest": { "branch": "main", "commit": "eedb19079c6bf9d162f74a5c48a6d2759f38cc76" }, + "chezmoi.nvim": { "branch": "main", "commit": "e5d2b2f534d2a1701ea2f9a8849732b28ea4c8c3" }, + "chezmoi.vim": { "branch": "main", "commit": "abf37336437867cbd99ce2f8849b717415391cc3" }, + "cloak.nvim": { "branch": "main", "commit": "648aca6d33ec011dc3166e7af3b38820d01a71e4" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "conform.nvim": { "branch": "master", "commit": "25d48271e3d4404ba017cb92a37d3a681c1ad149" }, + "copilot.vim": { "branch": "release", "commit": "25f73977033c597d530c7ab0e211d99b60927d2d" }, + "everforest": { "branch": "main", "commit": "8fdccd1e45088be3309aaf82072b1f7fec2f6f2c" }, "focus.nvim": { "branch": "master", "commit": "4135f976afe5d6e1fe66dff121db9d06643f439f" }, - "fzf": { "branch": "master", "commit": "507089d7b235b602f2f400be34c79a895e8c10dc" }, - "fzf.vim": { "branch": "master", "commit": "8ea9574b3ebdc44fbe3dc6381a13f9ce0c290e2f" }, - "gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" }, + "fzf": { "branch": "master", "commit": "af4917dbb643a7991c50091ec55ec25acb7d28cb" }, + "fzf.vim": { "branch": "master", "commit": "f7c7b44764a601e621432b98c85709c9a53a7be8" }, + "gitsigns.nvim": { "branch": "main", "commit": "f074844b60f9e151970fbcdbeb8a2cd52b6ef25a" }, "glow.nvim": { "branch": "main", "commit": "238070a686c1da3bccccf1079700eb4b5e19aea4" }, + "gruber-darker.nvim": { "branch": "main", "commit": "1793c0929ca965430410f7ec578272a4af9226ee" }, "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, - "image.nvim": { "branch": "master", "commit": "0dd8bdbb8855bc98c534a902c91dc9eddb8155b1" }, - "indent-blankline.nvim": { "branch": "master", "commit": "821a7acd88587d966f7e464b0b3031dfe7f5680c" }, - "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, - "lsp-zero.nvim": { "branch": "v3.x", "commit": "8cce56f62f3b67a44b71106bc687e13e53ff95b0" }, - "lualine.nvim": { "branch": "master", "commit": "8b56462bfb746760465264de41b4907310f113ec" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" }, - "mason-tool-installer.nvim": { "branch": "main", "commit": "1212fb6082b7177dde17ea65e429e027835aeb40" }, - "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, - "meh": { "branch": "master", "commit": "e2962284bbd53db5cbe2db39efaa3ea74ade0fb1" }, - "mini.bufremove": { "branch": "main", "commit": "931a3bb514147d9e812767275c4beba6b779b1d3" }, - "mini.comment": { "branch": "main", "commit": "a4b7e46deb9ad2feb8902cc5dbf087eced112ee5" }, + "hydra.nvim": { "branch": "master", "commit": "55de54543d673824435930ecf533256eea2e565b" }, + "image.nvim": { "branch": "master", "commit": "61c76515cfc3cdac8123ece9e9761b20c3dc1315" }, + "indent-blankline.nvim": { "branch": "master", "commit": "65e20ab94a26d0e14acac5049b8641336819dfc7" }, + "lazy.nvim": { "branch": "main", "commit": "077102c5bfc578693f12377846d427f49bc50076" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "56db3d5ce5476b183783160e6045f7337ba12b83" }, + "lualine.nvim": { "branch": "master", "commit": "544dd1583f9bb27b393f598475c89809c4d5e86b" }, + "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "ba9c2f0b93deb48d0a99ae0e8d8dd36f7cc286d6" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "meh": { "branch": "master", "commit": "41dd74e2d5afc6c1e975b01c84512a8951a39569" }, + "mini.bufremove": { "branch": "main", "commit": "1ee294a97e091d3cf967974df622c0d887890dc2" }, + "mini.comment": { "branch": "main", "commit": "03c13e37318bdb18481311c0ac1adc9ed731caf1" }, + "multicursors.nvim": { "branch": "main", "commit": "782820896b1691ed664e4c24f1cd9793dcb33dfb" }, "nabla.nvim": { "branch": "master", "commit": "27a6ea9ed7452bb9e0b19eb0942b5bcf7d051b2f" }, - "neo-tree.nvim": { "branch": "v3.x", "commit": "459c60317cc1d251f6eb3b6f010d015d5d24b806" }, - "nui.nvim": { "branch": "main", "commit": "fbb139c6f14896b434d0229099e1acd863ae6bec" }, - "nvim-bqf": { "branch": "main", "commit": "b51a37fcd808edafd52511458467c8c9a701ea8d" }, - "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, - "nvim-lint": { "branch": "master", "commit": "e824adb9bc01647f71e55457353a68f0f37f9931" }, - "nvim-lspconfig": { "branch": "master", "commit": "9ad7021267c6caeb01f839c91ad8f15fb608807e" }, - "nvim-spectre": { "branch": "master", "commit": "3712ff0cdf4f9f877d9ca708d835a877d9a0abaf" }, - "nvim-surround": { "branch": "main", "commit": "d47001f8ddf9646c24f16d2732d4d0255acd2121" }, - "nvim-treesitter": { "branch": "master", "commit": "cc6b108ea1251bd361f091b7d5a0dd41c04f8611" }, - "nvim-treesitter-context": { "branch": "master", "commit": "b8b7e52c1517d401d7c519787d5dc4528c41291a" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "b7a0bfa3e93697ca5b61b15df633404bf8f45883" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "7ab799a9792f7cf3883cf28c6a00ad431f3d382a" }, - "nvim-web-devicons": { "branch": "master", "commit": "4adea17610d140a99c313e3f79a9dc01825d59ae" }, - "oil.nvim": { "branch": "master", "commit": "18dfd2458dc741fea683357a17aaa95870b25a3c" }, - "playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" }, - "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, - "rasmus": { "branch": "main", "commit": "f824de95d446686e479781c0c2b778c177da528f" }, + "neo-tree.nvim": { "branch": "v3.x", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" }, + "nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" }, + "nvim-bqf": { "branch": "main", "commit": "1b24dc6050c34e8cd377b6b4cd6abe40509e0187" }, + "nvim-cmp": { "branch": "main", "commit": "d818fd0624205b34e14888358037fb6f5dc51234" }, + "nvim-lint": { "branch": "master", "commit": "efc6fc83f0772283e064c53a8f9fb5645bde0bc0" }, + "nvim-lspconfig": { "branch": "master", "commit": "fdc44768a09a65140aa00c92872a5381ad486485" }, + "nvim-spectre": { "branch": "master", "commit": "ba7fb777edff6c1fbbeffd343e113af64c04e90a" }, + "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" }, + "nvim-treesitter": { "branch": "master", "commit": "65310b64eee19a6e74e1b6f607a9f46f751290fe" }, + "nvim-treesitter-context": { "branch": "master", "commit": "2aba92ceb1479485953007f4d5adf34d0b66917e" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "6b5f95aa4d24f2c629a74f2c935c702b08dbde62" }, + "nvim-web-devicons": { "branch": "master", "commit": "5be6c4e685618b99c3210a69375b38a1202369b4" }, + "oil.nvim": { "branch": "master", "commit": "fcca212c2e966fc3dec1d4baf888e670631d25d1" }, + "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, + "rasmus": { "branch": "main", "commit": "86d608bd1d12a53b39d9b4b2847cd7c3ea81d473" }, "readline.nvim": { "branch": "main", "commit": "5cb27349bc01cdcdb3d3494e5337d8b3834aef1a" }, - "refactoring.nvim": { "branch": "master", "commit": "93d69cce9f0cbee8afae5b2380b296323792645f" }, - "rose-pine": { "branch": "main", "commit": "a29b09d15a9ef5cd575fbe5ae2a3cfb854876caf" }, - "smart-splits.nvim": { "branch": "master", "commit": "1ae8794e9e7fbdf0ec4074f2d0e056556a834f75" }, - "snakemake": { "branch": "main", "commit": "2887604ebe8a1e4c9c226780129312f556150dca" }, + "rose-pine": { "branch": "main", "commit": "e4b08d74b7272cb21e4e9c71b8b9e0830fd722fe" }, + "smart-splits.nvim": { "branch": "master", "commit": "209c136a5bee236094245196986ce94920dd3fdf" }, + "snakemake": { "branch": "main", "commit": "e8735c1477a2a82110757ba86bbd1ccbcaf327ba" }, "symbols-outline.nvim": { "branch": "master", "commit": "564ee65dfc9024bdde73a6621820866987cbb256" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, - "telescope.nvim": { "branch": "master", "commit": "dc1ea28cc2a02cd1cebb9d80e967807d668f78f8" }, - "todo-comments.nvim": { "branch": "main", "commit": "833d8dd8b07eeda37a09e99460f72a02616935cb" }, - "tree-sitter-just": { "branch": "main", "commit": "43f2c5efb96e51bbd8e64284662911b60849df00" }, - "trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" }, - "undotree": { "branch": "master", "commit": "9dbbf3b7d19dda0d22ceca461818e4739ad8154d" }, - "venn.nvim": { "branch": "main", "commit": "e4d68341a73dd56c64955058821a58295fb337b1" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, + "telescope.nvim": { "branch": "master", "commit": "10b8a82b042caf50b78e619d92caf0910211973d" }, + "todo-comments.nvim": { "branch": "main", "commit": "8f45f353dc3649cb9b44cecda96827ea88128584" }, + "trouble.nvim": { "branch": "main", "commit": "6efc446226679fda0547c0fd6a7892fd5f5b15d8" }, + "undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" }, + "venn.nvim": { "branch": "main", "commit": "b09c2f36ddf70b498281845109bedcf08a7e0de0" }, "vim-dispatch": { "branch": "master", "commit": "4c695bc052cad2ae6b980aebbe48d046466e27ae" }, - "vim-fugitive": { "branch": "master", "commit": "41beedabc7e948c787ea5696e04c3544c3674e23" }, - "vim-illuminate": { "branch": "master", "commit": "305bf07b919ac526deb5193280379e2f8b599926" }, - "vim-startuptime": { "branch": "master", "commit": "308b0088a864c4711a96e45b6734cf9294074f65" }, - "vim-tmux-navigator": { "branch": "master", "commit": "38b1d0402c4600543281dc85b3f51884205674b6" }, - "vimtex": { "branch": "master", "commit": "a77d14b2e4391c0d3e860708bb1fd56161ab68eb" }, - "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }, - "zen-mode.nvim": { "branch": "main", "commit": "78557d972b4bfbb7488e17b5703d25164ae64e6a" } + "vim-fugitive": { "branch": "master", "commit": "0444df68cd1cdabc7453d6bd84099458327e5513" }, + "vim-illuminate": { "branch": "master", "commit": "5eeb7951fc630682c322e88a9bbdae5c224ff0aa" }, + "vim-startuptime": { "branch": "master", "commit": "ac2cccb5be617672add1f4f3c0a55ce99ba34e01" }, + "vim-tmux-navigator": { "branch": "master", "commit": "5b3c701686fb4e6629c100ed32e827edf8dad01e" }, + "vimtex": { "branch": "master", "commit": "5ac62e0315c6f54f53a7d6da7c485cf8e9cf7240" }, + "which-key.nvim": { "branch": "main", "commit": "6c1584eb76b55629702716995cca4ae2798a9cca" }, + "zen-mode.nvim": { "branch": "main", "commit": "29b292bdc58b76a6c8f294c961a8bf92c5a6ebd6" } } \ No newline at end of file diff --git a/lua/rayandrew/lazy.lua b/lua/rayandrew/lazy.lua index 356239b..b242f27 100644 --- a/lua/rayandrew/lazy.lua +++ b/lua/rayandrew/lazy.lua @@ -12,6 +12,8 @@ end vim.opt.rtp:prepend(lazypath) +require("rayandrew.util").setup() + require("lazy").setup({ spec = { { import = "rayandrew.plugins" }, diff --git a/lua/rayandrew/plugins/editor.lua b/lua/rayandrew/plugins/editor.lua index 158d0c9..145171b 100644 --- a/lua/rayandrew/plugins/editor.lua +++ b/lua/rayandrew/plugins/editor.lua @@ -172,7 +172,7 @@ return { { "xvzc/chezmoi.nvim", dependencies = { "nvim-lua/plenary.nvim" }, - branch = "refactor", + -- branch = "refactor", opts = { edit = { watch = true, -- Set true to automatically apply on save. @@ -222,4 +222,31 @@ return { vim.opt.rtp:append(plugin.dir .. "/misc/vim") end, }, + + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + ft = { "markdown" }, + build = function() + vim.fn["mkdp#util#install"]() + end, + }, + + { + "smoka7/multicursors.nvim", + event = "VeryLazy", + dependencies = { + "smoka7/hydra.nvim", + }, + opts = {}, + cmd = { "MCstart", "MCvisual", "MCclear", "MCpattern", "MCvisualPattern", "MCunderCursor" }, + keys = { + { + mode = { "v", "n" }, + "", + "MCstart", + desc = "Create a selection for selected text or word under the cursor", + }, + }, + }, } diff --git a/lua/rayandrew/plugins/general.lua b/lua/rayandrew/plugins/general.lua index 50fb1c6..ca407ee 100644 --- a/lua/rayandrew/plugins/general.lua +++ b/lua/rayandrew/plugins/general.lua @@ -40,6 +40,15 @@ return { }, }, + { + "thimc/gruber-darker.nvim", + lazy = true, + opts = { + transparent = true, + }, + }, + + { "junegunn/fzf.vim", dependencies = { "junegunn/fzf" } }, -- { diff --git a/lua/rayandrew/plugins/lsp.lua b/lua/rayandrew/plugins/lsp.lua index 41d96af..21dfa2d 100644 --- a/lua/rayandrew/plugins/lsp.lua +++ b/lua/rayandrew/plugins/lsp.lua @@ -71,7 +71,7 @@ return { lsp_zero.on_attach(function(client, bufnr) -- see :help lsp-zero-keybindings -- to learn the available actions - lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = false }) + lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = true }) end) require("mason-lspconfig").setup({ diff --git a/lua/rayandrew/plugins/treesitter.lua b/lua/rayandrew/plugins/treesitter.lua index 64157eb..e37af0f 100644 --- a/lua/rayandrew/plugins/treesitter.lua +++ b/lua/rayandrew/plugins/treesitter.lua @@ -1,53 +1,55 @@ -local load_textobjects = false - return { ------------------------------ -- TreeSitter ------------------------------ { "nvim-treesitter/nvim-treesitter", + version = false, -- last release is way too old and doesn't work on Windows build = ":TSUpdate", - dependencies = { - { - "nvim-treesitter/nvim-treesitter-textobjects", - init = function() - require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects") - load_textobjects = true - end, - }, - - { - "IndianBoy42/tree-sitter-just", - dependencies = "nvim-treesitter/nvim-treesitter", - config = function(_, opts) - require("tree-sitter-just").setup({}) - end, - }, + event = { "VeryLazy" }, + lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline + init = function(plugin) + -- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early + -- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which + -- no longer trigger the **nvim-treesitter** module to be loaded in time. + -- Luckily, the only things that those plugins need are the custom queries, which we make available + -- during startup. + require("lazy.core.loader").add_to_rtp(plugin) + require("nvim-treesitter.query_predicates") + end, + cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" }, + keys = { + { "", desc = "Increment Selection" }, + { "", desc = "Decrement Selection", mode = "x" }, }, + ---@type TSConfig + ---@diagnostic disable-next-line: missing-fields opts = { highlight = { enable = true }, indent = { enable = true }, ensure_installed = { "bash", "c", + "diff", "html", "javascript", + "jsdoc", "json", - "latex", + "jsonc", "lua", "luadoc", "luap", "markdown", "markdown_inline", - "nix", "python", "query", "regex", - "rust", + "toml", "tsx", "typescript", "vim", "vimdoc", + "xml", "yaml", }, incremental_selection = { @@ -60,60 +62,17 @@ return { }, }, textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ["aa"] = "@parameter.outer", - ["ia"] = "@parameter.inner", - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - }, - }, move = { enable = true, - set_jumps = true, - goto_next_start = { - ["]k"] = { query = "@block.outer", desc = "Next block start" }, - ["]f"] = { query = "@function.outer", desc = "Next function start" }, - ["]a"] = { query = "@parameter.inner", desc = "Next parameter start" }, - }, - goto_next_end = { - ["]K"] = { query = "@block.outer", desc = "Next block end" }, - ["]F"] = { query = "@function.outer", desc = "Next function end" }, - ["]A"] = { query = "@parameter.inner", desc = "Next parameter end" }, - }, - goto_previous_start = { - ["[k"] = { query = "@block.outer", desc = "Previous block start" }, - ["[f"] = { query = "@function.outer", desc = "Previous function start" }, - ["[a"] = { query = "@parameter.inner", desc = "Previous parameter start" }, - }, - goto_previous_end = { - ["[K"] = { query = "@block.outer", desc = "Previous block end" }, - ["[F"] = { query = "@function.outer", desc = "Previous function end" }, - ["[A"] = { query = "@parameter.inner", desc = "Previous parameter end" }, - }, - }, - swap = { - enable = true, - swap_next = { - ["a"] = "@parameter.inner", - }, - swap_previous = { - ["A"] = "@parameter.inner", - }, + goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" }, + goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer" }, + goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" }, + goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer" }, }, }, }, - cmd = { "TSUpdateSync" }, - keys = { - { "", desc = "Increment selection" }, - { "", desc = "Decrement selection", mode = "x" }, - }, + ---@param opts TSConfig config = function(_, opts) - require("nvim-treesitter.install").compilers = { "gcc", "clang" } if type(opts.ensure_installed) == "table" then ---@type table local added = {} @@ -126,28 +85,42 @@ return { end, opts.ensure_installed) end require("nvim-treesitter.configs").setup(opts) + -- vim.schedule(function() + -- require("lazy").load({ plugins = { "nvim-treesitter-textobjects" } }) + -- end) + end, + }, - if load_textobjects then - -- PERF: no need to load the plugin, if we only need its queries for mini.ai - if opts.textobjects then - for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do - if opts.textobjects[mod] and opts.textobjects[mod].enable then - local Loader = require("lazy.core.loader") - Loader.disabled_rtp_plugins["nvim-treesitter-textobjects"] = nil - local plugin = require("lazy.core.config").plugins["nvim-treesitter-textobjects"] - require("lazy.core.loader").source_runtime(plugin.dir, "plugin") - break + -- { + -- "nvim-treesitter/playground", + -- }, + { + "nvim-treesitter/nvim-treesitter-textobjects", + lazy = true, + config = function() + -- When in diff mode, we want to use the default + -- vim text objects c & C instead of the treesitter ones. + local move = require("nvim-treesitter.textobjects.move") ---@type table + local configs = require("nvim-treesitter.configs") + for name, fn in pairs(move) do + if name:find("goto") == 1 then + move[name] = function(q, ...) + if vim.wo.diff then + local config = configs.get_module("textobjects.move")[name] ---@type table + for key, query in pairs(config or {}) do + if q == query and key:find("[%]%[][cC]") then + vim.cmd("normal! " .. key) + return + end + end end + return fn(q, ...) end end end end, }, - { - "nvim-treesitter/playground", - }, - { "nvim-treesitter/nvim-treesitter-context", opts = { diff --git a/lua/rayandrew/plugins/utilities.lua b/lua/rayandrew/plugins/utilities.lua index a348b5f..530d818 100644 --- a/lua/rayandrew/plugins/utilities.lua +++ b/lua/rayandrew/plugins/utilities.lua @@ -225,10 +225,6 @@ return { }, }, - { - "theprimeagen/refactoring.nvim", - }, - { "github/copilot.vim", init = function() @@ -242,12 +238,9 @@ return { end, }, - { - "eandrju/cellular-automaton.nvim", - }, - { "mbbill/undotree", + cmd = { "UndotreeToggle" }, }, { diff --git a/lua/rayandrew/root.lua b/lua/rayandrew/root.lua new file mode 100644 index 0000000..45bffda --- /dev/null +++ b/lua/rayandrew/root.lua @@ -0,0 +1,205 @@ +local lazy_util = require("lazy.util") + +---@class lazyvim.util.root +---@overload fun(): string +local M = setmetatable({}, { + __call = function(m) + return m.get() + end, +}) + +---@class LazyRoot +---@field paths string[] +---@field spec LazyRootSpec + +---@alias LazyRootFn fun(buf: number): (string|string[]) + +---@alias LazyRootSpec string|string[]|LazyRootFn + +---@type LazyRootSpec[] +M.spec = { "lsp", { ".git", "lua" }, "cwd" } + +M.detectors = {} + +function M.detectors.cwd() + return { vim.uv.cwd() } +end + +function M.detectors.lsp(buf) + local bufpath = M.bufpath(buf) + if not bufpath then + return {} + end + local roots = {} ---@type string[] + for _, client in pairs(LazyVim.lsp.get_clients({ bufnr = buf })) do + -- only check workspace folders, since we're not interested in clients + -- running in single file mode + local workspace = client.config.workspace_folders + for _, ws in pairs(workspace or {}) do + roots[#roots + 1] = vim.uri_to_fname(ws.uri) + end + end + return vim.tbl_filter(function(path) + path = lazy_util.norm(path) + return path and bufpath:find(path, 1, true) == 1 + end, roots) +end + +---@param patterns string[]|string +function M.detectors.pattern(buf, patterns) + patterns = type(patterns) == "string" and { patterns } or patterns + local path = M.bufpath(buf) or vim.uv.cwd() + local pattern = vim.fs.find(function(name) + for _, p in ipairs(patterns) do + if name == p then + return true + end + if p:sub(1, 1) == "*" and name:find(p:sub(2) .. "$") then + return true + end + end + return false + end, { path = path, upward = true })[1] + return pattern and { vim.fs.dirname(pattern) } or {} +end + +function M.bufpath(buf) + return M.realpath(vim.api.nvim_buf_get_name(assert(buf))) +end + +function M.cwd() + return M.realpath(vim.uv.cwd()) or "" +end + +function M.realpath(path) + if path == "" or path == nil then + return nil + end + path = vim.uv.fs_realpath(path) or path + return lazy_util.norm(path) +end + +---@param spec LazyRootSpec +---@return LazyRootFn +function M.resolve(spec) + if M.detectors[spec] then + return M.detectors[spec] + elseif type(spec) == "function" then + return spec + end + return function(buf) + return M.detectors.pattern(buf, spec) + end +end + +---@param opts? { buf?: number, spec?: LazyRootSpec[], all?: boolean } +function M.detect(opts) + opts = opts or {} + opts.spec = opts.spec or type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec + opts.buf = (opts.buf == nil or opts.buf == 0) and vim.api.nvim_get_current_buf() or opts.buf + + local ret = {} ---@type LazyRoot[] + for _, spec in ipairs(opts.spec) do + local paths = M.resolve(spec)(opts.buf) + paths = paths or {} + paths = type(paths) == "table" and paths or { paths } + local roots = {} ---@type string[] + for _, p in ipairs(paths) do + local pp = M.realpath(p) + if pp and not vim.tbl_contains(roots, pp) then + roots[#roots + 1] = pp + end + end + table.sort(roots, function(a, b) + return #a > #b + end) + if #roots > 0 then + ret[#ret + 1] = { spec = spec, paths = roots } + if opts.all == false then + break + end + end + end + return ret +end + +function M.info() + local spec = type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec + + local roots = M.detect({ all = true }) + local lines = {} ---@type string[] + local first = true + for _, root in ipairs(roots) do + for _, path in ipairs(root.paths) do + lines[#lines + 1] = ("- [%s] `%s` **(%s)**"):format( + first and "x" or " ", + path, + type(root.spec) == "table" and table.concat(root.spec, ", ") or root.spec + ) + first = false + end + end + lines[#lines + 1] = "```lua" + lines[#lines + 1] = "vim.g.root_spec = " .. vim.inspect(spec) + lines[#lines + 1] = "```" + LazyVim.info(lines, { title = "LazyVim Roots" }) + return roots[1] and roots[1].paths[1] or vim.uv.cwd() +end + +---@type table +M.cache = {} + +function M.setup() + vim.api.nvim_create_user_command("LazyRoot", function() + LazyVim.root.info() + end, { desc = "LazyVim roots for the current buffer" }) + + -- FIX: doesn't properly clear cache in neo-tree `set_root` (which should happen presumably on `DirChanged`), + -- probably because the event is triggered in the neo-tree buffer, therefore add `BufEnter` + -- Maybe this is too frequent on `BufEnter` and something else should be done instead?? + vim.api.nvim_create_autocmd({ "LspAttach", "BufWritePost", "DirChanged", "BufEnter" }, { + group = vim.api.nvim_create_augroup("lazyvim_root_cache", { clear = true }), + callback = function(event) + M.cache[event.buf] = nil + end, + }) +end + +-- returns the root directory based on: +-- * lsp workspace folders +-- * lsp root_dir +-- * root pattern of filename of the current buffer +-- * root pattern of cwd +---@param opts? {normalize?:boolean} +---@return string +function M.get(opts) + local buf = vim.api.nvim_get_current_buf() + local ret = M.cache[buf] + if not ret then + local roots = M.detect({ all = false }) + ret = roots[1] and roots[1].paths[1] or vim.uv.cwd() + M.cache[buf] = ret + end + if opts and opts.normalize then + return ret + end + return M.is_win() and ret:gsub("/", "\\") or ret +end + +function M.is_win() + return vim.uv.os_uname().sysname:find("Windows") ~= nil +end + +function M.git() + local root = M.get() + local git_root = vim.fs.find(".git", { path = root, upward = true })[1] + local ret = git_root and vim.fn.fnamemodify(git_root, ":h") or root + return ret +end + +---@param opts? {hl_last?: string} +function M.pretty_path(opts) + return "" +end + +return M diff --git a/lua/rayandrew/theme.lua b/lua/rayandrew/theme.lua index 3779fb3..0fae810 100644 --- a/lua/rayandrew/theme.lua +++ b/lua/rayandrew/theme.lua @@ -3,7 +3,8 @@ local M = {} -- M.colorscheme = "rose-pine" -- M.colorscheme = "meh" -- M.colorscheme = "rasmus" -M.colorscheme = "everforest" +-- M.colorscheme = "everforest" +M.colorscheme = "gruber-darker" M.background = "dark" -- M.colorscheme = "" diff --git a/lua/rayandrew/tools.lua b/lua/rayandrew/tools.lua index 23099a1..dd5a8f0 100644 --- a/lua/rayandrew/tools.lua +++ b/lua/rayandrew/tools.lua @@ -3,6 +3,7 @@ local M = {} local lsps = { lua = { "lua-language-server" }, python = { "pyright" }, + rust = { "rust_analyzer" }, } -- https://github.com/chrisgrieser/.config/blob/7dc36c350976010b32ece078edd581687634811a/nvim/lua/plugins/linter-formatter.lua#L214-L234 @@ -40,6 +41,7 @@ M.formatters = { nix = { "alejandra" }, yaml = { "prettier" }, html = { "prettier" }, + rust = { "rustfmt" }, markdown = { "markdown-toc", "markdownlint", diff --git a/lua/rayandrew/util.lua b/lua/rayandrew/util.lua index a8d6271..5d7e823 100644 --- a/lua/rayandrew/util.lua +++ b/lua/rayandrew/util.lua @@ -1,3 +1,5 @@ +local root = require("rayandrew.root") + -- shamelessly copied from -- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/init.lua @@ -88,30 +90,76 @@ function M.get_root() return root end +-- function M.telescope(builtin, opts) +-- local params = { builtin = builtin, opts = opts } +-- return function() +-- builtin = params.builtin +-- opts = params.opts +-- opts = vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {}) +-- if builtin == "files" then +-- if vim.loop.fs_stat((opts.cwd or vim.loop.cwd()) .. "/.git") then +-- opts.show_untracked = true +-- builtin = "git_files" +-- else +-- builtin = "find_files" +-- end +-- end +-- if opts.cwd and opts.cwd ~= vim.loop.cwd() then +-- opts.attach_mappings = function(_, map) +-- map("i", "", function() +-- local action_state = require("telescope.actions.state") +-- local line = action_state.get_current_line() +-- M.telescope( +-- params.builtin, +-- vim.tbl_deep_extend("force", {}, params.opts or {}, { cwd = false, default_text = line }) +-- )() +-- end) +-- return true +-- end +-- end +-- +-- require("telescope.builtin")[builtin](opts) +-- end +-- end + +-- this will return a function that calls telescope. +-- cwd will default to lazyvim.util.get_root +-- for `files`, git_files or find_files will be chosen depending on .git +---@param builtin string +---@param opts? lazyvim.util.telescope.opts function M.telescope(builtin, opts) local params = { builtin = builtin, opts = opts } return function() builtin = params.builtin opts = params.opts - opts = vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {}) + opts = vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {}) --[[@as lazyvim.util.telescope.opts]] if builtin == "files" then - if vim.loop.fs_stat((opts.cwd or vim.loop.cwd()) .. "/.git") then - opts.show_untracked = true + if + vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.git") + and not vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.ignore") + and not vim.uv.fs_stat((opts.cwd or vim.uv.cwd()) .. "/.rgignore") + then + if opts.show_untracked == nil then + opts.show_untracked = true + end builtin = "git_files" else builtin = "find_files" end end - if opts.cwd and opts.cwd ~= vim.loop.cwd() then + if opts.cwd and opts.cwd ~= vim.uv.cwd() then + local function open_cwd_dir() + local action_state = require("telescope.actions.state") + local line = action_state.get_current_line() + M.telescope( + params.builtin, + vim.tbl_deep_extend("force", {}, params.opts or {}, { cwd = false, default_text = line }) + )() + end + ---@diagnostic disable-next-line: inject-field opts.attach_mappings = function(_, map) - map("i", "", function() - local action_state = require("telescope.actions.state") - local line = action_state.get_current_line() - M.telescope( - params.builtin, - vim.tbl_deep_extend("force", {}, params.opts or {}, { cwd = false, default_text = line }) - )() - end) + -- opts.desc is overridden by telescope, until it's changed there is this fix + map("i", "", open_cwd_dir, { desc = "Open cwd Directory" }) return true end end @@ -177,4 +225,41 @@ function M.on_very_lazy(fn) }) end +function M.lazy_file() + -- This autocmd will only trigger when a file was loaded from the cmdline. + -- It will render the file as quickly as possible. + vim.api.nvim_create_autocmd("BufReadPost", { + once = true, + callback = function(event) + -- Skip if we already entered vim + if vim.v.vim_did_enter == 1 then + return + end + + -- Try to guess the filetype (may change later on during Neovim startup) + local ft = vim.filetype.match({ buf = event.buf }) + if ft then + -- Add treesitter highlights and fallback to syntax + local lang = vim.treesitter.language.get_lang(ft) + if not (lang and pcall(vim.treesitter.start, event.buf, lang)) then + vim.bo[event.buf].syntax = ft + end + + -- Trigger early redraw + vim.cmd([[redraw]]) + end + end, + }) + + -- Add support for the LazyFile event + local Event = require("lazy.core.handler.event") + + Event.mappings.LazyFile = { id = "LazyFile", event = M.lazy_file_events } + Event.mappings["User LazyFile"] = Event.mappings.LazyFile +end + +function M.setup() + -- M.lazy_file() +end + return M