internal/lsp: return code lenses in a deterministic order

Fixes golang/go#41961

Change-Id: I65f333caaa8568d90a59594019ac4296b8f56b98
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263527
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rebecca Stambler 2020-10-19 13:22:22 -04:00
parent eb9088fa2e
commit 2cbe144a5b
1 changed files with 8 additions and 0 deletions

View File

@ -7,6 +7,7 @@ package lsp
import (
"context"
"fmt"
"sort"
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/lsp/mod"
@ -44,5 +45,12 @@ func (s *Server) codeLens(ctx context.Context, params *protocol.CodeLensParams)
}
result = append(result, added...)
}
sort.Slice(result, func(i, j int) bool {
a, b := result[i], result[j]
if protocol.CompareRange(a.Range, b.Range) == 0 {
return a.Command.Command < b.Command.Command
}
return protocol.CompareRange(a.Range, b.Range) < 0
})
return result, nil
}