Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow hiding hunks from full blame #767

Conversation

danielleontiev
Copy link

Fixes #765.

Hi! I am trying to implement a feature described in #765, I have a couple questions:

  1. I was able to successfully hide hunks from full blame, but I have trouble to find the origin of trailing newline that is added after the commit message
  2. I've not found unit tests for blame_line function, only for current_line_blame. Should I add a new unit test and if yes, how can I approach this?

@danielleontiev danielleontiev force-pushed the hide-hunks-from-full-blame branch from 8d60bb2 to be70a43 Compare March 24, 2023 19:34
@danielleontiev danielleontiev force-pushed the hide-hunks-from-full-blame branch from be70a43 to b5769ab Compare March 24, 2023 19:35
@danielleontiev danielleontiev marked this pull request as ready for review March 24, 2023 19:36
@danielleontiev
Copy link
Author

danielleontiev commented Mar 24, 2023

I've figured out the (1) - trailing newline was caused by "" as the last element in info.body table

like this:

info = {
  body = { "feat: allow hiding hunks from full blame", "", "Fixes #765.", "" },
}

@lewis6991
Copy link
Owner

My solution for this was to expose a format string for the preview layout. The main changes needed for this have mostly been done internally. It just needs exposing in a robust way.

@danielleontiev
Copy link
Author

My solution for this was to expose a format string for the preview layout. The main changes needed for this have mostly been done internally. It just needs exposing in a robust way.

Sorry, I am not sure that I fully understand your suggestion, could you please elaborate a bit more on it?

Do you mean that instead of adding info.hunk based on opts.hide_hunks option we should instead control the representation only by changing the formatting table? For example, info will always be filled with all necessary data (i.e. commit body, hunks, etc) but the actual representation will differ because of the formatting table for full blame will/will not contain hunks formatting data?

Example - given the following blame info:

{
  abbrev_sha = "2a107231",
  author = "Lewis Russell",
  author_mail = "<[email protected]>",
  author_time = "1646155791",
  author_tz = "+0000",
  body = { "refactor: vendor in async lib", "", "- Typed teal implementation", "- Better error diagnostics", "- Removes dependency on plenary.nvim", "" },
  committer = "Lewis Russell",
  committer_mail = "<[email protected]>",
  committer_time = "1648229045",
  committer_tz = "+0000",
  filename = "teal/gitsigns/actions.tl",
  final_lnum = 1,
  hunk = { "-local void      = require('plenary.async.async').void", "-local scheduler = require('plenary.async.util').scheduler", "+local void      = require('gitsigns.async').void", "+local scheduler = require('gitsigns.async').scheduler" },
  hunk_head = "@@ -1,2 +1,2 @@",
  hunk_no = 1,
  num_hunks = 1,
  orig_lnum = 1,
  previous = "7ff03e1ebad8941f53cbc9da349cf2c557a58aff teal/gitsigns/actions.tl",
  previous_filename = "teal/gitsigns/actions.tl",
  previous_sha = "7ff03e1ebad8941f53cbc9da349cf2c557a58aff",
  sha = "2a107231d92fa37224efdbc475abfba71f94b5ee",
  summary = "refactor: vendor in async lib"
}

It's filled with all information (including hunks info).

So, in your solution, if I understand correctly, when opts.hide_hunks = false the formatting table should be as follows:

{
  {
    { "<abbrev_sha> ", "Directory" },
    { "<author> ", "MoreMsg" },
    { "(<author_time:%Y-%m-%d %H:%M>)", "Label" },
    { ":", "NormalFloat" }
  },
  {
    { "<body>", "NormalFloat" }
  },
  {
    { "Hunk <hunk_no> of <num_hunks>", "Title" },
    { " <hunk_head>", "LineNr" }
  },
  {
    { "<hunk>", {
        { end_row = 4, hl_group = "NormalFloat", start_row = 0 },
        { end_row = 2, hl_group = "GitSignsDeletePreview", start_row = 0 },
        { end_row = 4, hl_group = "GitSignsAddPreview", start_row = 2 },
        { end_col = 41, hl_group = "GitSignsDeleteInline", start_col = 28, start_row = 0 },
        { end_col = 35, hl_group = "GitSignsDeleteInline", start_col = 28, start_row = 1 },
        { end_col = 46, hl_group = "GitSignsDeleteInline", start_col = 41, start_row = 1 },
        { end_col = 36, hl_group = "GitSignsAddInline", start_col = 28, start_row = 2 },
        { end_col = 36, hl_group = "GitSignsAddInline", start_col = 28, start_row = 3 },
        { end_col = 42, hl_group = "GitSignsAddInline", start_col = 42, start_row = 3 }
      }
    }
  }
}

and when opts.hide_hunks = true:

{
  {
    { "<abbrev_sha> ", "Directory" },
    { "<author> ", "MoreMsg" },
    { "(<author_time:%Y-%m-%d %H:%M>)", "Label" },
    { ":", "NormalFloat" }
  },
  {
    { "<body>", "NormalFloat" }
  }
}

And that formatting should fully control the look of the preview without the need to mutate info.hunks, correct?

@danielleontiev
Copy link
Author

@lewis6991 have you got a chance to address questions above? I would like to follow your guidelines in implementation of the feature but I need a bit more info on it to go further

@lewis6991
Copy link
Owner

lewis6991 commented Apr 21, 2023

Yes to the questions above.

Just like we have:

  current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',

We can have something similar for preview windows. However this format will match nvim virtual_lines so the user can also provide highlights.

@danielleontiev
Copy link
Author

Superseded by #803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide hunks in blame_line floating window
2 participants