NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit
MIT License
3.62k stars 218 forks source link

Some neogit buffers break `statuscolumn` #1400

Closed mehalter closed 6 days ago

mehalter commented 6 days ago

Description

I use a custom statuscolumn to nicely display folds which a lot of the time works perfectly with Neogit since it adds in folds for things. But I noticed some recent update has made a lot of buffers break the pretty folds and reverse my custom statuscolumn completely causing things to look ugly again.

Neovim version

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713484068

Operating system and version

Arch linux

Steps to reproduce

  1. nvim -u minimal.lua, start up the minimal configuration
  2. cd <some_git_dir>, change directories to a git tracked directory
  3. :Neogit, open neogit and see that the folds look nice (notice the > and v with a nice line in the fold area, ignore the signs added by neogit as I didn't disable them to show both the signs and the foldcolumn) 2024-06-29_11:29:30_screenshot
  4. :set statuscolumn?, see that it is set to our custom statuscolumn
  5. Select a commit to open the commitview
  6. Scroll down and see that now we have ugly folds rather than our nice looking folds 2024-06-29_11:30:37_screenshot
  7. :set statuscolumn?, see that it is not set to our custom statuscolumn

Expected behavior

Neogit should not modify my statuscolumn at all. If they want to modify information that is shown in a buffer then it should change things like set foldcolumn?, set number?, etc.

That way I can get the look that I have configured

2024-06-29_11:31:18_screenshot

Actual behavior

My custom statuscol is completely removed and is now just using the default columns from neovim.

Minimal config

-- NOTE: See the end of this file if you are reporting an issue, etc. Ignore all the "scary" functions up top, those are
-- used for setup and other operations.
local M = {}

local base_root_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") .. "/.min"
function M.root(path)
    return base_root_path .. "/" .. (path or "")
end

function M.load_plugin(plugin_name, plugin_url)
    local package_root = M.root("plugins/")
    local install_destination = package_root .. plugin_name
    vim.opt.runtimepath:append(install_destination)

    if not vim.loop.fs_stat(package_root) then
        vim.fn.mkdir(package_root, "p")
    end

    if not vim.loop.fs_stat(install_destination) then
        print(string.format("> Downloading plugin '%s' to '%s'", plugin_name, install_destination))
        vim.fn.system({
            "git",
            "clone",
            "--depth=1",
            plugin_url,
            install_destination,
        })
        if vim.v.shell_error > 0 then
            error(
                string.format("> Failed to clone plugin: '%s' in '%s'!", plugin_name, install_destination),
                vim.log.levels.ERROR
            )
        end
    end
end

---@alias PluginName string The plugin name, will be used as part of the git clone destination
---@alias PluginUrl string The git url at which a plugin is located, can be a path. See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols for details
---@alias MinPlugins table<PluginName, PluginUrl>

---Do the initial setup. Downloads plugins, ensures the minimal init does not pollute the filesystem by keeping
---everything self contained to the CWD of the minimal init file. Run prior to running tests, reproducing issues, etc.
---@param plugins? table<PluginName, PluginUrl>
function M.setup(plugins)
    vim.opt.packpath = {} -- Empty the package path so we use only the plugins specified
    vim.opt.runtimepath:append(M.root(".min")) -- Ensure the runtime detects the root min dir

    -- Install required plugins
    if plugins ~= nil then
        for plugin_name, plugin_url in pairs(plugins) do
            M.load_plugin(plugin_name, plugin_url)
        end
    end

    vim.env.XDG_CONFIG_HOME = M.root("xdg/config")
    vim.env.XDG_DATA_HOME = M.root("xdg/data")
    vim.env.XDG_STATE_HOME = M.root("xdg/state")
    vim.env.XDG_CACHE_HOME = M.root("xdg/cache")

    -- NOTE: Cleanup the xdg cache on exit so new runs of the minimal init doesn't share any previous state, e.g. shada
    vim.api.nvim_create_autocmd("VimLeave", {
        callback = function()
            vim.fn.system({
                "rm",
                "-r",
                "-f",
                M.root("xdg"),
            })
        end,
    })
end

-- NOTE: If you have additional plugins you need to install to reproduce your issue, include them in the plugins
-- table within the setup call below.
M.setup({
    plenary = "https://github.com/nvim-lua/plenary.nvim.git",
    telescope = "https://github.com/nvim-telescope/telescope.nvim",
    diffview = "https://github.com/sindrets/diffview.nvim",
    neogit = "https://github.com/NeogitOrg/neogit",
    statuscol = "https://github.com/luukvbaal/statuscol.nvim", -- add statuscolumn plugin
})

local builtin = require("statuscol.builtin")
require("statuscol").setup({ -- do some basic configuration of a statuscolumn to illustrate folds looking nice
    relculright = true,
    segments = {
        { text = { builtin.foldfunc }, click = "v:lua.ScFa" },
        { text = { "%s" }, click = "v:lua.ScSa" },
        { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
    },
})
vim.opt.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]] -- set fold chars
vim.opt.foldcolumn = "1" -- enable fold column to show pretty folds that we configured

-- WARN: Do all plugin setup, test runs, reproductions, etc. AFTER calling setup with a list of plugins!
-- Basically, do all that stuff AFTER this line.
require("neogit").setup({}) -- For instance, setup Neogit
mehalter commented 5 days ago

Thanks for the quick fix! This works great as long as the user sets disable_signs. I don't think that is always applicable. They might use statuscolumn to change the order or signs and numbers and things and in that case the user still will get some bad looking stuff even if they still rely on the signs to see the fold indicators in Neogit. It seems like the only reason status_column would be getting changed is simply to "remove" things which should be done with :set nonumber, :set foldcolumn=0, and :set norelnum.

Luckily I'm not in this case so for me simply disabling all of the indicators is totally fine for me so maybe this isn't an issue that matters. Thanks for your help!