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: add git_live_grep #1974

Closed
wants to merge 4 commits into from

Conversation

antoinemadec
Copy link
Contributor

@antoinemadec antoinemadec commented May 27, 2022

git_live_grep is to live_grep what git_files is to find_files.

@antoinemadec antoinemadec changed the title feat: add git_grep feat: add git_live_grep May 27, 2022
@Conni2461 Conni2461 self-assigned this May 28, 2022
@antoinemadec
Copy link
Contributor Author

@Conni2461 maybe that could be its own separate plugin ?
I was thinking of creating:

  • git_browse live_grep
  • git_browse grep_string
  • git_browse commit_msg
  • git_browse commit_diff
  • git_browse commit_author

What do you think ?

@Conni2461
Copy link
Member

I wanted to argue that this doesn't really need to be in telescope core. Its already somewhat possible with this, there are just no supported shorthands and we dont have git cwd detection.

lua require("telescope.builtin").live_grep({ vimgrep_arguments = {"git", "grep", "--line-number", "--column", "-I", "--ignore-case"} })

If you want to make an extension feel free, we already argued for this some time ago anyway 😆 see #1228

@antoinemadec
Copy link
Contributor Author

@Conni2461 got it.
To me, the git grep feature is a must have, but after searching for similar requests on the internets it seems that people don't really care about it 😆

Another issue is the fact that git_commits does not respect the chronological order of commits once you start filtering them.
I looked for a builtin sorter which only filters and don't reorder, but I didn't find one. So I created one myself.
However, there is no generic get_score() that could be overriden by extensions like fzf-native etc. So I had to point to fzy's get_score() specifically.

Long story short: I will create an extension.
When it's done, we can discuss including code in the builtin such as the sorter which respects the order.

Thanks for the excellent plugin ❤️

@Conni2461
Copy link
Member

I think this can be done with any sorter. See :help telescope.defaults.tiebreak

You then can pass a opt tiebreak = function() return false end to git_commits / git_bcommits

We can even argue that we should make that default for those. If that works, PR welcome :)

@antoinemadec
Copy link
Contributor Author

antoinemadec commented May 29, 2022

@Conni2461 it does not work for me, here is what I tried:

  local tiebreak = function() return false end
  opts.defaults.tiebreak = tiebreak;
  opts.tiebreak = tiebreak;

After reading the help, it seems not to do what I want.
It's supposed to only break a tie. What I want is to keep the order whatever the score is (unless it is -1 i.e. filtered).
This is what I wrote, and what works for me:

local sorter_preserve_order = function(opts)
  opts = opts or {}
  local fzy = opts.fzy_mod or require "telescope.algos.fzy"

  return sorters.Sorter:new {
    scoring_function = function(_, prompt, line, _)
      if not fzy.has_match(prompt, line) then
        return -1
      end
      return 1
    end,

    highlighter = function(_, prompt, display)
      return fzy.positions(prompt, display)
    end,
  }
end

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.

None yet

2 participants