@@ -182,7 +182,11 @@ func gopToggleDetailsCodeLens(ctx context.Context, snapshot Snapshot, fh FileHan
182
182
183
183
func gopCommandCodeLens (ctx context.Context , snapshot Snapshot , fh FileHandle ) ([]protocol.CodeLens , error ) {
184
184
filename := fh .URI ().Filename ()
185
- if strings .HasSuffix (filename , "_test.go" ) || strings .HasSuffix (filename , "_test.gop" ) || strings .HasSuffix (filename , "test.gox" ) {
185
+ // TODO: Use parserutil.GetClassType Instead
186
+ if strings .HasSuffix (filename , "test.gox" ) {
187
+ return goxTestCodeLens (ctx , snapshot , fh )
188
+ }
189
+ if strings .HasSuffix (filename , "_test.go" ) || strings .HasSuffix (filename , "_test.gop" ) {
186
190
return nil , nil
187
191
}
188
192
pgf , err := snapshot .ParseGop (ctx , fh , parser .PackageClauseOnly )
@@ -206,3 +210,42 @@ func gopCommandCodeLens(ctx context.Context, snapshot Snapshot, fh FileHandle) (
206
210
}
207
211
return nil , nil
208
212
}
213
+
214
+ func goxTestCodeLens (ctx context.Context , snapshot Snapshot , fh FileHandle ) ([]protocol.CodeLens , error ) {
215
+ pgf , err := snapshot .ParseGop (ctx , fh , parser .PackageClauseOnly )
216
+ if err != nil {
217
+ return nil , err
218
+ }
219
+ if pgf .File .Name .Name == "main" {
220
+ classType , _ := parserutil .GetClassType (pgf .File , fh .URI ().Filename ())
221
+ rng , err := pgf .PosRange (pgf .File .Pos (), pgf .File .Pos ())
222
+ if err != nil {
223
+ return nil , err
224
+ }
225
+ pattern := regexp .MustCompile (`^case(?:_)?` ) //goxls: remove case or case_
226
+ if pattern .MatchString (classType ) {
227
+ classType = pattern .ReplaceAllString (classType , "" )
228
+ }
229
+ args , err := command .MarshalArgs (
230
+ map [string ]string {
231
+ "functionName" : "Test_" + classType ,
232
+ },
233
+ )
234
+ if err != nil {
235
+ return nil , err
236
+ }
237
+ codelens := []protocol.CodeLens {
238
+ {Range : rng , Command : & protocol.Command {
239
+ Title : "run test package" ,
240
+ Command : "gop.test.package" ,
241
+ }},
242
+ {Range : rng , Command : & protocol.Command { // goxls: add test cursor as test file
243
+ Title : "run file tests" ,
244
+ Command : "gop.test.cursor" ,
245
+ Arguments : args ,
246
+ }},
247
+ }
248
+ return codelens , nil
249
+ }
250
+ return nil , nil
251
+ }
0 commit comments