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
57
58
59
60
61
62
63
|
package tuigen
type SourceMap struct {
SourceFile string `json:"sourceFile"`
Mappings []SourceMapping `json:"mappings"`
}
type SourceMapping struct {
GoLine int `json:"goLine"`
GoCol int `json:"goCol"`
GsxLine int `json:"gsxLine"`
GsxCol int `json:"gsxCol"`
Length int `json:"length"`
}
func NewSourceMap(sourceFile string) *SourceMap {
return &SourceMap{
SourceFile: sourceFile,
Mappings: make([]SourceMapping, 0),
}
}
func (sm *SourceMap) AddMapping(m SourceMapping) {
sm.Mappings = append(sm.Mappings, m)
}
func (sm *SourceMap) GoToGsx(goLine, goCol int) (gsxLine, gsxCol int, found bool) {
for _, m := range sm.Mappings {
if m.GoLine == goLine && goCol >= m.GoCol && goCol <= m.GoCol+m.Length {
offset := goCol - m.GoCol
return m.GsxLine, m.GsxCol + offset, true
}
}
return goLine, goCol, false
}
func (sm *SourceMap) GsxToGo(gsxLine, gsxCol int) (goLine, goCol int, found bool) {
for _, m := range sm.Mappings {
if m.GsxLine == gsxLine && gsxCol >= m.GsxCol && gsxCol <= m.GsxCol+m.Length {
offset := gsxCol - m.GsxCol
return m.GoLine, m.GoCol + offset, true
}
}
return gsxLine, gsxCol, false
}
|