/
range.go
56 lines (48 loc) · 1.21 KB
/
range.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package lsp
import (
"github.com/kralicky/protocompile/ast"
"github.com/kralicky/tools-lite/gopls/pkg/protocol"
)
type ranger interface {
Start() ast.SourcePos
End() ast.SourcePos
}
func toRange[T ranger](t T) protocol.Range {
return positionsToRange(t.Start(), t.End())
}
func toPosition(pos ast.SourcePos) protocol.Position {
return protocol.Position{
Line: uint32(pos.Line - 1),
Character: uint32(pos.Col - 1),
}
}
func positionsToRange(start, end ast.SourcePos) protocol.Range {
return protocol.Range{
Start: toPosition(start),
End: toPosition(end),
}
}
func pointToRange(point ast.SourcePos) protocol.Range {
return protocol.Range{
Start: toPosition(point),
End: toPosition(point),
}
}
func adjustColumns(r protocol.Range, leftAdjust int, rightAdjust int) protocol.Range {
return protocol.Range{
Start: protocol.Position{
Line: r.Start.Line,
Character: r.Start.Character + uint32(leftAdjust),
},
End: protocol.Position{
Line: r.End.Line,
Character: r.End.Character + uint32(rightAdjust),
},
}
}
func adjustColumn(r protocol.Position, adjust int) protocol.Position {
return protocol.Position{
Line: r.Line,
Character: r.Character + uint32(adjust),
}
}