38 lines
1023 B
Go
38 lines
1023 B
Go
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 ""
|
|
}
|