The method syntax.Node.Span uses binary search to convert a file offset into a line number.
Location heavy tools, like our language server or formatter, would benefit from line-caches. For example like so:
func (t *tree) position(pos int) Position {
if t.cachedLineBegin <= pos && pos < t.cachedLineEnd {
line = t.cachedLine
}
// ...
}
To be efficient we probably need two separate line-caches, one for n.Pos() and one for n.End(). Best would be creating benchmarks comparing random position access, accessing only begin-offsets and accessing whole spans (begin- and end-offset).
The method
syntax.Node.Spanuses binary search to convert a file offset into a line number.Location heavy tools, like our language server or formatter, would benefit from line-caches. For example like so:
To be efficient we probably need two separate line-caches, one for
n.Pos()and one forn.End().Best would be creating benchmarks comparing random position access, accessing only begin-offsets and accessing whole spans (begin- and end-offset).