pwntester / octo.nvim

Edit and review GitHub issues and pull requests from the comfort of your favorite editor
MIT License
2.28k stars 125 forks source link

make signcolumn configurable #367

Closed pwntester closed 1 year ago

pwntester commented 1 year ago

This PR adds to options to disable/enable the modified marks on the sign column. The reason for this is to enable users to not use the signcolumn for marking modified comments/body/title so that they can use the statuscolumn instead. Status column will be more customizable and does not suffer from https://github.com/pwntester/octo.nvim/issues/80

An an example you can disable the signcolumn using:

ui = {
    use_signcolumn = false
}

and add the following to your statuscolumn configuration

local function mk_hl(group, sym)
  return table.concat({ "%#", group, "#", sym, "%*" })
end

_G.get_statuscol_octo = function(bufnum, lnum)
  if vim.api.nvim_buf_get_option(bufnum, "filetype") == "octo" then
    if type(octo_buffers) == "table" then
      local buffer = octo_buffers[bufnum]
      if buffer then
        buffer:update_metadata()
        local hl = "OctoSignColumn"
        local metadatas = {buffer.titleMetadata, buffer.bodyMetadata}
        for _, comment_metadata in ipairs(buffer.commentsMetadata) do
          table.insert(metadatas, comment_metadata)
        end
        for _, metadata in ipairs(metadatas) do
          if metadata and metadata.startLine and metadata.endLine then
            if metadata.dirty then
              hl = "OctoDirty"
            else
              hl = "OctoSignColumn"
            end
            if lnum - 1 == metadata.startLine and lnum - 1 == metadata.endLine then
              return mk_hl(hl, "[ ")
            elseif lnum - 1 == metadata.startLine then
              return mk_hl(hl, "┌ ")
            elseif lnum - 1 == metadata.endLine then
              return mk_hl(hl, "└ ")
            elseif metadata.startLine < lnum - 1 and lnum - 1 < metadata.endLine then
              return mk_hl(hl, "│ ")
            end
          end
        end
      end
    end
  end
  return "  "
end

vim.opt.statuscolumn = "%{%v:lua.get_statuscol_octo(bufnr(), v:lnum)%}"