vendor tsgo
This commit is contained in:
37
tools/tsgo/internal/lsp/lsproto/util.go
Normal file
37
tools/tsgo/internal/lsp/lsproto/util.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package lsproto
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
)
|
||||
|
||||
// Implements a cmp.Compare like function for two Position
|
||||
// ComparePositions(pos, other) == cmp.Compare(pos, other)
|
||||
func ComparePositions(pos, other Position) int {
|
||||
if lineComp := cmp.Compare(pos.Line, other.Line); lineComp != 0 {
|
||||
return lineComp
|
||||
}
|
||||
return cmp.Compare(pos.Character, other.Character)
|
||||
}
|
||||
|
||||
// Implements a cmp.Compare like function for two Range
|
||||
// CompareRanges(lsRange, other) == cmp.Compare(lsRange, other)
|
||||
//
|
||||
// Range.Start is compared before Range.End
|
||||
func CompareRanges(lsRange, other Range) int {
|
||||
if startComp := ComparePositions(lsRange.Start, other.Start); startComp != 0 {
|
||||
return startComp
|
||||
}
|
||||
return ComparePositions(lsRange.End, other.End)
|
||||
}
|
||||
|
||||
// AsString returns the plain text of a StringOrMarkupContent, reading the
|
||||
// MarkupContent value when the message is not a plain string.
|
||||
func (m StringOrMarkupContent) AsString() string {
|
||||
if m.String != nil {
|
||||
return *m.String
|
||||
}
|
||||
if m.MarkupContent != nil {
|
||||
return m.MarkupContent.Value
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user