Skip to content

Commit

Permalink
score: remove unused contentProvider.matchScore
Browse files Browse the repository at this point in the history
My last PR missed this. Now that we only score by candidateMatch we can
remove the matchScore implementation which was used to score LineMatch.

Test Plan: go test
  • Loading branch information
keegancsmith committed Jan 23, 2024
1 parent fdc6ba2 commit e643511
Showing 1 changed file with 0 additions and 84 deletions.
84 changes: 0 additions & 84 deletions contentprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,90 +673,6 @@ func (p *contentProvider) candidateMatchScore(ms []*candidateMatch, language str
return maxScore.score, maxScore.what, symbolInfo
}

func (p *contentProvider) matchScore(secs []DocumentSection, m *LineMatch, language string, debug bool) (float64, string) {
type debugScore struct {
what string
score float64
}

score := &debugScore{}
maxScore := &debugScore{}

addScore := func(what string, s float64) {
if s != 0 && debug {
score.what += fmt.Sprintf("%s:%.2f, ", what, s)
}
score.score += s
}

data := p.data(m.FileName)
filename := p.data(true)

for _, f := range m.LineFragments {
startBoundary := f.LineOffset < len(m.Line) && (f.LineOffset == 0 || byteClass(m.Line[f.LineOffset-1]) != byteClass(m.Line[f.LineOffset]))

end := int(f.LineOffset) + f.MatchLength
endBoundary := end > 0 && (end == len(m.Line) || byteClass(m.Line[end-1]) != byteClass(m.Line[end]))

score.score = 0
score.what = ""

if startBoundary && endBoundary {
addScore("WordMatch", scoreWordMatch)
} else if startBoundary || endBoundary {
addScore("PartialWordMatch", scorePartialWordMatch)
}

if m.FileName {
sep := bytes.LastIndexByte(m.Line, '/')
startMatch := sep+1 == f.LineOffset
endMatch := len(m.Line) == f.LineOffset+f.MatchLength
if startMatch && endMatch {
addScore("Base", scoreBase)
} else if startMatch || endMatch {
addScore("EdgeBase", (scoreBase+scorePartialBase)/2)
} else if sep < f.LineOffset {
addScore("InnerBase", scorePartialBase)
}
} else if secIdx, ok := findSection(secs, f.Offset, uint32(f.MatchLength)); ok {
sec := secs[secIdx]
startMatch := sec.Start == f.Offset
endMatch := sec.End == f.Offset+uint32(f.MatchLength)
if startMatch && endMatch {
addScore("Symbol", scoreSymbol)
} else if startMatch || endMatch {
addScore("EdgeSymbol", (scoreSymbol+scorePartialSymbol)/2)
} else {
addScore("InnerSymbol", scorePartialSymbol)
}

si := f.SymbolInfo
if si == nil {
// for non-symbol queries, we need to hydrate in SymbolInfo.
start := p.id.fileEndSymbol[p.idx]
si = p.id.symbols.data(start + uint32(secIdx))
}
if si != nil {
// the LineFragment may not be on a symbol, then si will be nil.
symbolKind := ctags.ParseSymbolKind(si.Kind)
sym := sectionSlice(data, sec)
addScore(fmt.Sprintf("kind:%s:%s", language, si.Kind), scoreSymbolKind(language, filename, sym, symbolKind))
}
}

if score.score > maxScore.score {
maxScore.score = score.score
maxScore.what = score.what
}
}

if debug {
maxScore.what = fmt.Sprintf("score:%.2f <- %s", maxScore.score, strings.TrimSuffix(maxScore.what, ", "))
}

return maxScore.score, maxScore.what
}

// sectionSlice will return data[sec.Start:sec.End] but will clip Start and
// End such that it won't be out of range.
func sectionSlice(data []byte, sec DocumentSection) []byte {
Expand Down

0 comments on commit e643511

Please sign in to comment.