1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-22 08:42:32 -05:00

git-grep: add comments on highlighting support

This commit is contained in:
Radosław Piliszek 2024-09-16 14:23:15 +02:00
parent 9c70c7a8ea
commit cd62d0f5e8

View file

@ -85,6 +85,9 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
"-I", "--null", "--break", "--heading",
"--line-number", "--ignore-case", "--full-name")
if opts.Mode == RegExpGrepMode {
// No `--column` -- regexp mode does not support highlighting in the
// current implementation as the length of the match is unknown from
// `grep` but required for highlighting.
cmd.AddArguments("--perl-regexp")
} else {
cmd.AddArguments("--fixed-strings", "--column")
@ -161,6 +164,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
if lineNum, lineCode, ok := strings.Cut(line, "\x00"); ok {
lineNumInt, _ := strconv.Atoi(lineNum)
res.LineNumbers = append(res.LineNumbers, lineNumInt)
// We support highlighting only when `--column` parameter is used.
if lineCol, lineCode2, ok := strings.Cut(lineCode, "\x00"); ok {
lineColInt, _ := strconv.Atoi(lineCol)
start := lineColInt - 1