Git Product home page Git Product logo

Comments (3)

lucobellic avatar lucobellic commented on June 16, 2024 1

@Betelgeuse1 Thanks for sharing this code snippet, I was just trying to do the same thing.

For those who would also like to get GitChange highlight, you can rely on the non public function of gitsign require('gitsigns.hunks').calc_signs

View Code
local gitsign = require('gitsigns')
local gitsign_hunks = require('gitsigns.hunks')

require('scrollbar.handlers').register('git', function(bufnr)
    local nb_lines = vim.api.nvim_buf_line_count(bufnr)
    -- NOTE: change to corresponding marks from scrollbar setup 
    local colors_type = {
        add = 'GitAdd',
        delete = 'GitDelete',
        change = 'GitChange',
        changedelete = 'GitChange'
    }

    local lines = {}
    local hunks = gitsign.get_hunks(bufnr)
    if hunks then
        for _, hunk in ipairs(hunks) do
            hunk.vend = math.min(hunk.added.start, hunk.removed.start) + hunk.added.count + hunk.removed.count
            local signs = gitsign_hunks.calc_signs(hunk, 0, nb_lines)
            for _, sign in ipairs(signs) do
                table.insert(lines, {
                    line = sign.lnum,
                    type = colors_type[sign.type]
                })
            end
        end
    end
    return lines
end)

from nvim-scrollbar.

Betelgeuse1 avatar Betelgeuse1 commented on June 16, 2024

Don't know if it's pertinent but I started working on an handler for that purpose, got this far.

-- new marks
GitAdd = {
  text = { "" },
  priority = 5,
  color = palette.blue[1],
  cterm = nil,
  highlight = "CursorColumn",
},
GitDel = {
  text = { "" },
  priority = 5,
  color = palette.red[1],
  cterm = nil,
  highlight = "CursorColumn",
},
GitChg = {
  text = { "" },
  priority = 5,
  color = palette.orange[1],
  cterm = nil,
  highlight = "CursorColumn",
},

-- custom handler -- not working right now
require('scrollbar.handlers').register('git', function()
  local hunks = require('gitsigns').get_hunks()
  local lines = {}

  if hunks == nil then
    return lines
  end

  for _, hunk in pairs(hunks) do
    for i = 1, #hunk.added, 1 do
      table.insert(lines, {
        line = hunk.added[i].start + (i - 2),
        type = "GitAdd",
      })
    end
    for i = 1, #hunk.removed, 1 do
      table.insert(lines, {
        line = hunk.removed[i].start + (i - 2),
        type = "GitDel",
      })
    end
  end

  return lines
end)

I'm fairly new to Lua and nvim programming, code might look bad, just wanted to relaunch the topic

from nvim-scrollbar.

Gelio avatar Gelio commented on June 16, 2024

I implemented it in #60. I hope it will land soon

from nvim-scrollbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.