Skip to content

Commit f74dc0d

Browse files
authored
LSP optimize start/end location offset lookups (#4062)
1 parent d500877 commit f74dc0d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

private/buf/buflsp/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,9 @@ func (f *file) IndexSymbols(ctx context.Context) {
616616

617617
// Finally, sort the symbols in position order, with shorter symbols sorting smaller.
618618
slices.SortFunc(f.symbols, func(s1, s2 *symbol) int {
619-
diff := s1.span.StartLoc().Offset - s2.span.StartLoc().Offset
619+
diff := s1.span.Start - s2.span.Start
620620
if diff == 0 {
621-
return s1.span.EndLoc().Offset - s2.span.EndLoc().Offset
621+
return s1.span.End - s2.span.End
622622
}
623623
return diff
624624
})

private/buf/buflsp/symbol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func getCommentsFromDef(def ast.DeclDef) string {
280280
var comments []string
281281
// We drop the other side of "Around" because we only care about the beginning -- we're
282282
// traversing backwards for leading comemnts only.
283-
_, start := def.Context().Stream().Around(def.Span().StartLoc().Offset)
283+
_, start := def.Context().Stream().Around(def.Span().Start)
284284
cursor := token.NewCursorAt(start)
285285
t := cursor.PrevSkippable()
286286
for !t.IsZero() {

0 commit comments

Comments
 (0)