diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index cc226964..32716c0a 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -129,23 +129,8 @@ if vim.lsp.inlay_hint then LazyVim.toggle.map("uh", LazyVim.toggle.inlay_hints) end --- lazygit -map("n", "gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) -map("n", "gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" }) -map("n", "gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" }) -map("n", "gB", LazyVim.lazygit.browse, { desc = "Git Browse" }) - -map("n", "gf", function() - local git_path = vim.api.nvim_buf_get_name(0) - LazyVim.lazygit({args = { "-f", vim.trim(git_path) }, cwd = LazyVim.root.git()}) -end, { desc = "Lazygit Current File History" }) - -map("n", "gl", function() - LazyVim.lazygit({ args = { "log" }, cwd = LazyVim.root.git() }) -end, { desc = "Lazygit Log" }) -map("n", "gL", function() - LazyVim.lazygit({ args = { "log" } }) -end, { desc = "Lazygit Log (cwd)" }) +-- TODO: Change to Neogit +-- map("n", "gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" }) -- quit map("n", "qq", "qa", { desc = "Quit All" }) diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index 3ad70c16..b34c2ce9 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -18,16 +18,6 @@ vim.g.lazyvim_picker = "auto" -- * a function with signature `function(buf) -> string|string[]` vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } --- LazyVim automatically configures lazygit: --- * theme, based on the active colorscheme. --- * editPreset to nvim-remote --- * enables nerd font icons --- Set to false to disable. --- Set the options you want to override in `~/.config/lazygit/custom.yml` --- WARN: on Windows you might want to set `editPreset: "nvim"` due to --- this issue https://github.com/jesseduffield/lazygit/issues/3467 -vim.g.lazygit_config = true - -- Options for the LazyVim statuscolumn vim.g.lazyvim_statuscolumn = { folds_open = false, -- show fold sign when fold is open diff --git a/lua/lazyvim/health.lua b/lua/lazyvim/health.lua index 4822de86..e1e26558 100644 --- a/lua/lazyvim/health.lua +++ b/lua/lazyvim/health.lua @@ -16,26 +16,6 @@ function M.check() else error("Neovim >= 0.9.0 is required") end - - for _, cmd in ipairs({ "git", "rg", { "fd", "fdfind" }, "lazygit" }) do - local name = type(cmd) == "string" and cmd or vim.inspect(cmd) - local commands = type(cmd) == "string" and { cmd } or cmd - ---@cast commands string[] - local found = false - - for _, c in ipairs(commands) do - if vim.fn.executable(c) == 1 then - name = c - found = true - end - end - - if found then - ok(("`%s` is installed"):format(name)) - else - warn(("`%s` is not installed"):format(name)) - end - end end return M diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index a57d9aeb..89fb3843 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -1,131 +1,5 @@ return { - -- file explorer - { - "nvim-neo-tree/neo-tree.nvim", - cmd = "Neotree", - keys = { - { - "fe", - function() - require("neo-tree.command").execute({ toggle = true, dir = LazyVim.root() }) - end, - desc = "Explorer NeoTree (Root Dir)", - }, - { - "fE", - function() - require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) - end, - desc = "Explorer NeoTree (cwd)", - }, - { "e", "fe", desc = "Explorer NeoTree (Root Dir)", remap = true }, - { "E", "fE", desc = "Explorer NeoTree (cwd)", remap = true }, - { - "ge", - function() - require("neo-tree.command").execute({ source = "git_status", toggle = true }) - end, - desc = "Git Explorer", - }, - { - "be", - function() - require("neo-tree.command").execute({ source = "buffers", toggle = true }) - end, - desc = "Buffer Explorer", - }, - }, - deactivate = function() - vim.cmd([[Neotree close]]) - end, - init = function() - -- FIX: use `autocmd` for lazy-loading neo-tree instead of directly requiring it, - -- because `cwd` is not set up properly. - vim.api.nvim_create_autocmd("BufEnter", { - group = vim.api.nvim_create_augroup("Neotree_start_directory", { clear = true }), - desc = "Start Neo-tree with directory", - once = true, - callback = function() - if package.loaded["neo-tree"] then - return - else - local stats = vim.uv.fs_stat(vim.fn.argv(0)) - if stats and stats.type == "directory" then - require("neo-tree") - end - end - end, - }) - end, - opts = { - sources = { "filesystem", "buffers", "git_status" }, - open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, - filesystem = { - bind_to_cwd = false, - follow_current_file = { enabled = true }, - use_libuv_file_watcher = true, - }, - window = { - mappings = { - ["l"] = "open", - ["h"] = "close_node", - [""] = "none", - ["Y"] = { - function(state) - local node = state.tree:get_node() - local path = node:get_id() - vim.fn.setreg("+", path, "c") - end, - desc = "Copy Path to Clipboard", - }, - ["O"] = { - function(state) - require("lazy.util").open(state.tree:get_node().path, { system = true }) - end, - desc = "Open with System Application", - }, - ["P"] = { "toggle_preview", config = { use_float = false } }, - }, - }, - default_component_configs = { - indent = { - with_expanders = true, -- if nil and file nesting is enabled, will enable expanders - expander_collapsed = "", - expander_expanded = "", - expander_highlight = "NeoTreeExpander", - }, - git_status = { - symbols = { - unstaged = "󰄱", - staged = "󰱒", - }, - }, - }, - }, - config = function(_, opts) - local function on_move(data) - LazyVim.lsp.on_rename(data.source, data.destination) - end - - local events = require("neo-tree.events") - opts.event_handlers = opts.event_handlers or {} - vim.list_extend(opts.event_handlers, { - { event = events.FILE_MOVED, handler = on_move }, - { event = events.FILE_RENAMED, handler = on_move }, - }) - require("neo-tree").setup(opts) - vim.api.nvim_create_autocmd("TermClose", { - pattern = "*lazygit", - callback = function() - if package.loaded["neo-tree.sources.git_status"] then - require("neo-tree.sources.git_status").refresh() - end - end, - }) - end, - }, - -- search/replace in multiple files { "MagicDuck/grug-far.nvim", diff --git a/lua/lazyvim/plugins/extras/ui/edgy.lua b/lua/lazyvim/plugins/extras/ui/edgy.lua index f63e31ad..f92f42bb 100644 --- a/lua/lazyvim/plugins/extras/ui/edgy.lua +++ b/lua/lazyvim/plugins/extras/ui/edgy.lua @@ -54,7 +54,6 @@ return { }, left = { { title = "Neotest Summary", ft = "neotest-summary" }, - -- "neo-tree", }, right = { { title = "Grug Far", ft = "grug-far", size = { width = 0.4 } }, @@ -79,30 +78,6 @@ return { }, } - if LazyVim.has("neo-tree.nvim") then - local pos = { - filesystem = "left", - buffers = "top", - git_status = "right", - document_symbols = "bottom", - diagnostics = "bottom", - } - local sources = LazyVim.opts("neo-tree.nvim").sources or {} - for i, v in ipairs(sources) do - table.insert(opts.left, i, { - title = "Neo-Tree " .. v:gsub("_", " "):gsub("^%l", string.upper), - ft = "neo-tree", - filter = function(buf) - return vim.b[buf].neo_tree_source == v - end, - pinned = true, - open = function() - vim.cmd(("Neotree show position=%s %s dir=%s"):format(pos[v] or "bottom", v, LazyVim.root())) - end, - }) - end - end - for _, pos in ipairs({ "top", "bottom", "left", "right" }) do opts[pos] = opts[pos] or {} table.insert(opts[pos], { @@ -134,17 +109,6 @@ return { }, }, - -- prevent neo-tree from opening files in edgy windows - { - "nvim-neo-tree/neo-tree.nvim", - optional = true, - opts = function(_, opts) - opts.open_files_do_not_replace_types = opts.open_files_do_not_replace_types - or { "terminal", "Trouble", "qf", "Outline", "trouble" } - table.insert(opts.open_files_do_not_replace_types, "edgy") - end, - }, - -- Fix bufferline offsets when edgy is loaded { "akinsho/bufferline.nvim", diff --git a/lua/lazyvim/plugins/extras/ui/mini-indentscope.lua b/lua/lazyvim/plugins/extras/ui/mini-indentscope.lua index 1b8beeb6..62093ad3 100644 --- a/lua/lazyvim/plugins/extras/ui/mini-indentscope.lua +++ b/lua/lazyvim/plugins/extras/ui/mini-indentscope.lua @@ -21,7 +21,6 @@ return { "lazy", "lazyterm", "mason", - "neo-tree", "notify", "toggleterm", "Trouble", diff --git a/lua/lazyvim/plugins/extras/util/gitui.lua b/lua/lazyvim/plugins/extras/util/gitui.lua index b5033235..3c3b31c6 100644 --- a/lua/lazyvim/plugins/extras/util/gitui.lua +++ b/lua/lazyvim/plugins/extras/util/gitui.lua @@ -20,16 +20,5 @@ return { desc = "GitUi (Root Dir)", }, }, - init = function() - -- delete lazygit keymap for file history - vim.api.nvim_create_autocmd("User", { - pattern = "LazyVimKeymaps", - once = true, - callback = function() - pcall(vim.keymap.del, "n", "gf") - pcall(vim.keymap.del, "n", "gl") - end, - }) - end, }, } diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index 14807497..716ce61a 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -66,14 +66,6 @@ return { .. (diag.warning and icons.Warn .. diag.warning or "") return vim.trim(ret) end, - offsets = { - { - filetype = "neo-tree", - text = "Neo-tree", - highlight = "Directory", - text_align = "left", - }, - }, ---@param opts bufferline.IconFetcherOpts get_element_icon = function(opts) return LazyVim.config.icons.ft[opts.filetype] @@ -194,7 +186,7 @@ return { end, }, }, - extensions = { "neo-tree", "lazy" }, + extensions = { "lazy" }, } -- do not add trouble symbols if aerial is enabled @@ -247,7 +239,6 @@ return { "help", "alpha", "dashboard", - "neo-tree", "Trouble", "trouble", "lazy", diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 106cbdc0..8ea1ab79 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -6,7 +6,6 @@ local LazyUtil = require("lazy.core.util") ---@field lsp lazyvim.util.lsp ---@field root lazyvim.util.root ---@field terminal lazyvim.util.terminal ----@field lazygit lazyvim.util.lazygit ---@field toggle lazyvim.util.toggle ---@field format lazyvim.util.format ---@field plugin lazyvim.util.plugin diff --git a/lua/lazyvim/util/lazygit.lua b/lua/lazyvim/util/lazygit.lua deleted file mode 100644 index ff96c85c..00000000 --- a/lua/lazyvim/util/lazygit.lua +++ /dev/null @@ -1,231 +0,0 @@ ----@class lazyvim.util.lazygit ----@field config_dir? string ----@overload fun(cmd: string|string[], opts: LazyTermOpts): LazyFloat -local M = setmetatable({}, { - __call = function(m, ...) - return m.open(...) - end, -}) - ----@alias LazyGitColor {fg?:string, bg?:string, bold?:boolean} - ----@class LazyGitTheme: table ----@field activeBorderColor LazyGitColor ----@field cherryPickedCommitBgColor LazyGitColor ----@field cherryPickedCommitFgColor LazyGitColor ----@field defaultFgColor LazyGitColor ----@field inactiveBorderColor LazyGitColor ----@field optionsTextColor LazyGitColor ----@field searchingActiveBorderColor LazyGitColor ----@field selectedLineBgColor LazyGitColor ----@field unstagedChangesColor LazyGitColor -M.theme = { - [241] = { fg = "Special" }, - activeBorderColor = { fg = "MatchParen", bold = true }, - cherryPickedCommitBgColor = { fg = "Identifier" }, - cherryPickedCommitFgColor = { fg = "Function" }, - defaultFgColor = { fg = "Normal" }, - inactiveBorderColor = { fg = "FloatBorder" }, - optionsTextColor = { fg = "Function" }, - searchingActiveBorderColor = { fg = "MatchParen", bold = true }, - selectedLineBgColor = { bg = "Visual" }, -- set to `default` to have no background colour - unstagedChangesColor = { fg = "DiagnosticError" }, -} - -M.theme_path = LazyVim.norm(vim.fn.stdpath("cache") .. "/lazygit-theme.yml") - --- re-create config file on startup -M.dirty = true - --- re-create theme file on ColorScheme change -vim.api.nvim_create_autocmd("ColorScheme", { - callback = function() - M.dirty = true - end, -}) - --- Opens lazygit ----@param opts? LazyTermOpts | {args?: string[]} -function M.open(opts) - if vim.g.lazygit_theme ~= nil then - LazyVim.deprecate("vim.g.lazygit_theme", "vim.g.lazygit_config") - end - - opts = vim.tbl_deep_extend("force", {}, { - esc_esc = false, - ctrl_hjkl = false, - }, opts or {}) - - local cmd = { "lazygit" } - vim.list_extend(cmd, opts.args or {}) - - if vim.g.lazygit_config then - if M.dirty then - M.update_config() - end - - if not M.config_dir then - local Process = require("lazy.manage.process") - local ok, lines = pcall(Process.exec, { "lazygit", "-cd" }) - if ok then - M.config_dir = lines[1] - vim.env.LG_CONFIG_FILE = LazyVim.norm(M.config_dir .. "/config.yml" .. "," .. M.theme_path) - local custom_config = LazyVim.norm(M.config_dir .. "/custom.yml") - if vim.uv.fs_stat(custom_config) and vim.uv.fs_stat(custom_config).type == "file" then - vim.env.LG_CONFIG_FILE = vim.env.LG_CONFIG_FILE .. "," .. custom_config - end - else - ---@diagnostic disable-next-line: cast-type-mismatch - ---@cast lines string - LazyVim.error( - { "Failed to get **lazygit** config directory.", "Will not apply **lazygit** config.", "", "# Error:", lines }, - { title = "lazygit" } - ) - end - end - end - - return LazyVim.terminal(cmd, opts) -end - -function M.set_ansi_color(idx, color) - io.write(("\27]4;%d;%s\7"):format(idx, color)) -end - ----@param v LazyGitColor ----@return string[] -function M.get_color(v) - ---@type string[] - local color = {} - if v.fg then - color[1] = LazyVim.ui.color(v.fg) - elseif v.bg then - color[1] = LazyVim.ui.color(v.bg, true) - end - if v.bold then - table.insert(color, "bold") - end - return color -end - -function M.update_config() - ---@type table - local theme = {} - - for k, v in pairs(M.theme) do - if type(k) == "number" then - local color = M.get_color(v) - -- LazyGit uses color 241 a lot, so also set it to a nice color - -- pcall, since some terminals don't like this - pcall(M.set_ansi_color, k, color[1]) - else - theme[k] = M.get_color(v) - end - end - - local config = [[ -os: - editPreset: "nvim-remote" -gui: - nerdFontsVersion: 3 - theme: -]] - - ---@type string[] - local lines = {} - for k, v in pairs(theme) do - lines[#lines + 1] = (" %s:"):format(k) - for _, c in ipairs(v) do - lines[#lines + 1] = (" - %q"):format(c) - end - end - config = config .. table.concat(lines, "\n") - require("lazy.util").write_file(M.theme_path, config) - M.dirty = false -end - ----@param opts? {count?: number}|LazyCmdOptions -function M.blame_line(opts) - opts = vim.tbl_deep_extend("force", { - count = 3, - filetype = "git", - size = { - width = 0.6, - height = 0.6, - }, - border = "rounded", - }, opts or {}) - local cursor = vim.api.nvim_win_get_cursor(0) - local line = cursor[1] - local file = vim.api.nvim_buf_get_name(0) - local root = LazyVim.root.detectors.pattern(0, { ".git" })[1] or "." - local cmd = { "git", "-C", root, "log", "-n", opts.count, "-u", "-L", line .. ",+1:" .. file } - return require("lazy.util").float_cmd(cmd, opts) -end - --- stylua: ignore -M.remote_patterns = { - { "^(https?://.*)%.git$" , "%1" }, - { "^git@(.+):(.+)%.git$" , "https://%1/%2" }, - { "^git@(.+):(.+)$" , "https://%1/%2" }, - { "^git@(.+)/(.+)$" , "https://%1/%2" }, - { "^ssh://git@(.*)$" , "https://%1" }, - { "ssh%.dev%.azure%.com/v3/(.*)/(.*)$", "dev.azure.com/%1/_git/%2" }, - { "^https://%w*@(.*)" , "https://%1" }, - { "^git@(.*)" , "https://%1" }, - { ":%d+" , "" }, - { "%.git$" , "" }, -} - ----@param remote string -function M.get_url(remote) - local ret = remote - for _, pattern in ipairs(M.remote_patterns) do - ret = ret:gsub(pattern[1], pattern[2]) - end - return ret:find("https://") == 1 and ret or ("https://%s"):format(ret) -end - -function M.browse() - local lines = require("lazy.manage.process").exec({ "git", "remote", "-v" }) - local remotes = {} ---@type {name:string, url:string}[] - - for _, line in ipairs(lines) do - local name, remote = line:match("(%S+)%s+(%S+)%s+%(fetch%)") - if name and remote then - local url = M.get_url(remote) - if url then - table.insert(remotes, { - name = name, - url = url, - }) - end - end - end - - local function open(remote) - if remote then - LazyVim.info(("Opening [%s](%s)"):format(remote.name, remote.url)) - if vim.fn.has("nvim-0.10") == 0 then - require("lazy.util").open(remote.url, { system = true }) - return - end - vim.ui.open(remote.url) - end - end - - if #remotes == 0 then - return LazyVim.error("No git remotes found") - elseif #remotes == 1 then - return open(remotes[1]) - end - - vim.ui.select(remotes, { - prompt = "Select remote to browse", - format_item = function(item) - return item.name .. (" "):rep(8 - #item.name) .. " 🔗 " .. item.url - end, - }, open) -end - -return M diff --git a/tests/util/lazygit_spec.lua b/tests/util/lazygit_spec.lua deleted file mode 100644 index 518e886a..00000000 --- a/tests/util/lazygit_spec.lua +++ /dev/null @@ -1,42 +0,0 @@ ----@module "luassert" - -_G.LazyVim = require("lazyvim.util") - --- stylua: ignore -local git_remotes_cases = { - ["https://github.com/LazyVim/LazyVim.git"] = "https://github.com/LazyVim/LazyVim", - ["https://github.com/LazyVim/LazyVim"] = "https://github.com/LazyVim/LazyVim", - ["git@github.com:LazyVim/LazyVim"] = "https://github.com/LazyVim/LazyVim", - ["git@ssh.dev.azure.com:v3/neovim-org/owner/repo"] = "https://dev.azure.com/neovim-org/owner/_git/repo", - ["https://folkelemaitre@bitbucket.org/samiulazim/neovim.git"] = "https://bitbucket.org/samiulazim/neovim", - ["git@bitbucket.org:samiulazim/neovim.git"] = "https://bitbucket.org/samiulazim/neovim", - ["git@gitlab.com:inkscape/inkscape.git"] = "https://gitlab.com/inkscape/inkscape", - ["https://gitlab.com/inkscape/inkscape.git"] = "https://gitlab.com/inkscape/inkscape", - ["git@github.com:torvalds/linux.git"] = "https://github.com/torvalds/linux", - ["https://github.com/torvalds/linux.git"] = "https://github.com/torvalds/linux", - ["git@bitbucket.org:team/repo.git"] = "https://bitbucket.org/team/repo", - ["https://bitbucket.org/team/repo.git"] = "https://bitbucket.org/team/repo", - ["git@gitlab.com:example-group/example-project.git"] = "https://gitlab.com/example-group/example-project", - ["https://gitlab.com/example-group/example-project.git"] = "https://gitlab.com/example-group/example-project", - ["git@ssh.dev.azure.com:v3/org/project/repo"] = "https://dev.azure.com/org/project/_git/repo", - ["https://username@dev.azure.com/org/project/_git/repo"] = "https://dev.azure.com/org/project/_git/repo", - ["ssh://git@ghe.example.com:2222/org/repo.git"] = "https://ghe.example.com/org/repo", - ["https://ghe.example.com/org/repo.git"] = "https://ghe.example.com/org/repo", - ["git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo"] = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", - ["https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo"] = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo", - ["ssh://git@source.developers.google.com:2022/p/project/r/repo"] = "https://source.developers.google.com/p/project/r/repo", - ["https://source.developers.google.com/p/project/r/repo"] = "https://source.developers.google.com/p/project/r/repo", - ["git@git.sr.ht:~user/repo"] = "https://git.sr.ht/~user/repo", - ["https://git.sr.ht/~user/repo"] = "https://git.sr.ht/~user/repo", - ["git@git.sr.ht:~user/another-repo"] = "https://git.sr.ht/~user/another-repo", - ["https://git.sr.ht/~user/another-repo"] = "https://git.sr.ht/~user/another-repo", -} - -describe("util.lazygit", function() - for remote, expected in pairs(git_remotes_cases) do - it("should parse git remote " .. remote, function() - local url = LazyVim.lazygit.get_url(remote) - assert.are.equal(expected, url) - end) - end -end)