Skip to content

Commit a8e53fc

Browse files
committed
fix ci fail
1 parent f08b007 commit a8e53fc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

modules/indexer/code/search.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
7676

7777
contentLines := strings.SplitAfter(result.Content[startIndex:endIndex], "\n")
7878
lines := make([]ResultLine, 0, len(contentLines))
79+
highlightedLines := make([]string, 0, len(contentLines))
7980
index := startIndex
8081
for i, line := range contentLines {
8182
var err error
@@ -100,11 +101,17 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
100101

101102
lines = append(lines, ResultLine{Num: startLineNum + i})
102103
index += len(line)
104+
105+
// highlight.Code will remove the last `\n`, e.g. if input is `a\n`, output will be `a`
106+
// Then the length of `lines` and `highlightedLines` will not be equal, so we need to add an empty line manually
107+
if line == "" {
108+
highlightedLines = append(highlightedLines, "")
109+
}
103110
}
104111

105112
// we should highlight the whole code block first, otherwise it doesn't work well with multiple line highlighting
106113
hl, _ := highlight.Code(result.Filename, "", formattedLinesBuffer.String())
107-
highlightedLines := strings.Split(string(hl), "\n")
114+
highlightedLines = append(strings.Split(string(hl), "\n"), highlightedLines...)
108115

109116
if len(highlightedLines) != len(lines) {
110117
return nil, fmt.Errorf("the length of line numbers [%d] don't match the length of highlighted contents [%d]", len(lines), len(highlightedLines))

0 commit comments

Comments
 (0)