5
5
"errors"
6
6
"fmt"
7
7
"path/filepath"
8
- "sort"
9
8
"strings"
10
9
11
10
"github.com/google/go-jsonnet"
@@ -52,55 +51,6 @@ func (s *server) DefinitionLink(ctx context.Context, params *protocol.Definition
52
51
return definition , nil
53
52
}
54
53
55
- type NodeStack struct {
56
- from ast.Node
57
- stack []ast.Node
58
- }
59
-
60
- func NewNodeStack (from ast.Node ) * NodeStack {
61
- return & NodeStack {
62
- from : from ,
63
- stack : []ast.Node {from },
64
- }
65
- }
66
-
67
- func (s * NodeStack ) Push (n ast.Node ) * NodeStack {
68
- s .stack = append (s .stack , n )
69
- return s
70
- }
71
-
72
- func (s * NodeStack ) Pop () (* NodeStack , ast.Node ) {
73
- l := len (s .stack )
74
- if l == 0 {
75
- return s , nil
76
- }
77
- n := s .stack [l - 1 ]
78
- s .stack = s .stack [:l - 1 ]
79
- return s , n
80
- }
81
-
82
- func (s * NodeStack ) IsEmpty () bool {
83
- return len (s .stack ) == 0
84
- }
85
-
86
- func (s * NodeStack ) reorderDesugaredObjects () * NodeStack {
87
- sort .SliceStable (s .stack , func (i , j int ) bool {
88
- _ , iIsDesugared := s .stack [i ].(* ast.DesugaredObject )
89
- _ , jIsDesugared := s .stack [j ].(* ast.DesugaredObject )
90
- if ! iIsDesugared && ! jIsDesugared {
91
- return false
92
- }
93
-
94
- iLoc , jLoc := s .stack [i ].Loc (), s .stack [j ].Loc ()
95
- if iLoc .Begin .Line < jLoc .Begin .Line && iLoc .End .Line > jLoc .End .Line {
96
- return true
97
- }
98
-
99
- return false
100
- })
101
- return s
102
- }
103
-
104
54
func Definition (node ast.Node , params * protocol.DefinitionParams , vm * jsonnet.VM ) (* protocol.DefinitionLink , error ) {
105
55
responseDefLink , err := findDefinition (node , params , vm )
106
56
if err != nil {
@@ -127,27 +77,14 @@ func findDefinition(root ast.Node, params *protocol.DefinitionParams, vm *jsonne
127
77
foundLocRange = matchingBind .Body .Loc ()
128
78
}
129
79
responseDefLink = protocol.DefinitionLink {
130
- TargetURI : protocol .DocumentURI (foundLocRange .FileName ),
131
- TargetRange : protocol.Range {
132
- Start : protocol.Position {
133
- Line : uint32 (foundLocRange .Begin .Line - 1 ),
134
- Character : uint32 (foundLocRange .Begin .Column - 1 ),
135
- },
136
- End : protocol.Position {
137
- Line : uint32 (foundLocRange .End .Line - 1 ),
138
- Character : uint32 (foundLocRange .End .Column - 1 ),
139
- },
140
- },
141
- TargetSelectionRange : protocol.Range {
142
- Start : protocol.Position {
143
- Line : uint32 (foundLocRange .Begin .Line - 1 ),
144
- Character : uint32 (foundLocRange .Begin .Column - 1 ),
145
- },
146
- End : protocol.Position {
147
- Line : uint32 (foundLocRange .Begin .Line - 1 ),
148
- Character : uint32 (foundLocRange .Begin .Column - 1 + len (matchingBind .Variable )),
149
- },
150
- },
80
+ TargetURI : protocol .DocumentURI (foundLocRange .FileName ),
81
+ TargetRange : ASTRangeToProtocolRange (* foundLocRange ),
82
+ TargetSelectionRange : NewProtocolRange (
83
+ foundLocRange .Begin .Line - 1 ,
84
+ foundLocRange .Begin .Column - 1 ,
85
+ foundLocRange .Begin .Line - 1 ,
86
+ foundLocRange .Begin .Column - 1 + len (matchingBind .Variable ),
87
+ ),
151
88
}
152
89
case * ast.SuperIndex , * ast.Index :
153
90
indexSearchStack := NewNodeStack (deepestNode )
@@ -159,27 +96,14 @@ func findDefinition(root ast.Node, params *protocol.DefinitionParams, vm *jsonne
159
96
}
160
97
foundLocRange := & matchingField .LocRange
161
98
responseDefLink = protocol.DefinitionLink {
162
- TargetURI : protocol .DocumentURI (foundLocRange .FileName ),
163
- TargetRange : protocol.Range {
164
- Start : protocol.Position {
165
- Line : uint32 (foundLocRange .Begin .Line - 1 ),
166
- Character : uint32 (foundLocRange .Begin .Column - 1 ),
167
- },
168
- End : protocol.Position {
169
- Line : uint32 (foundLocRange .End .Line - 1 ),
170
- Character : uint32 (foundLocRange .End .Column - 1 ),
171
- },
172
- },
173
- TargetSelectionRange : protocol.Range {
174
- Start : protocol.Position {
175
- Line : uint32 (foundLocRange .Begin .Line - 1 ),
176
- Character : uint32 (foundLocRange .Begin .Column - 1 ),
177
- },
178
- End : protocol.Position {
179
- Line : uint32 (foundLocRange .Begin .Line - 1 ),
180
- Character : uint32 (foundLocRange .Begin .Column - 1 + len (matchingField .Name .(* ast.LiteralString ).Value )),
181
- },
182
- },
99
+ TargetURI : protocol .DocumentURI (foundLocRange .FileName ),
100
+ TargetRange : ASTRangeToProtocolRange (* foundLocRange ),
101
+ TargetSelectionRange : NewProtocolRange (
102
+ foundLocRange .Begin .Line - 1 ,
103
+ foundLocRange .Begin .Column - 1 ,
104
+ foundLocRange .Begin .Line - 1 ,
105
+ foundLocRange .Begin .Column - 1 + len (matchingField .Name .(* ast.LiteralString ).Value ),
106
+ ),
183
107
}
184
108
case * ast.Import :
185
109
filename := deepestNode .File .Value
0 commit comments