@@ -182,27 +182,53 @@ 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
+ if strings .HasSuffix (filename , "_test.go" ) || strings .HasSuffix (filename , "_test.gop" ) {
186
186
return nil , nil
187
187
}
188
+
188
189
pgf , err := snapshot .ParseGop (ctx , fh , parser .PackageClauseOnly )
189
190
if err != nil {
190
191
return nil , err
191
192
}
192
193
if pgf .File .Name .Name == "main" {
194
+ isTest := strings .HasSuffix (filename , "test.gox" )
195
+ classType , _ := parserutil .GetClassType (pgf .File , fh .URI ().Filename ())
196
+ codelens := []protocol.CodeLens {}
193
197
rng , err := pgf .PosRange (pgf .File .Pos (), pgf .File .Pos ())
194
198
if err != nil {
195
199
return nil , err
196
200
}
197
201
dir := protocol .URIFromSpanURI (span .URIFromPath (filepath .Dir (fh .URI ().Filename ())))
198
- args := command.RunGopCommandArgs {URI : dir , Command : "run" }
199
- cmd , err := command .NewRunGopCommandCommand ("run main package" , args )
200
- if err != nil {
201
- return nil , err
202
+ if ! isTest {
203
+ args := command.RunGopCommandArgs {URI : dir , Command : "run" }
204
+ cmd , err := command .NewRunGopCommandCommand ("run main package" , args )
205
+ if err != nil {
206
+ return nil , err
207
+ }
208
+ codelens = append (codelens , protocol.CodeLens {Range : rng , Command : & cmd })
209
+ } else {
210
+ pattern := regexp .MustCompile (`^case(?:_)?` ) //goxls: remove case or case_
211
+ if regexp .MustCompile (`^case(?:_)?` ).MatchString (classType ) {
212
+ classType = pattern .ReplaceAllString (classType , "" )
213
+ }
214
+ args , err := command .MarshalArgs (
215
+ map [string ]string {
216
+ "functionName" : "Test_" + classType ,
217
+ },
218
+ )
219
+ if err != nil {
220
+ return nil , err
221
+ }
222
+ codelens = append (codelens , protocol.CodeLens {Range : rng , Command : & protocol.Command {
223
+ Title : "run test package" ,
224
+ Command : "gop.test.package" ,
225
+ }}, protocol.CodeLens {Range : rng , Command : & protocol.Command { // goxls: add test cursor as test file
226
+ Title : "run file tests" ,
227
+ Command : "gop.test.cursor" ,
228
+ Arguments : args ,
229
+ }})
202
230
}
203
- return []protocol.CodeLens {
204
- {Range : rng , Command : & cmd },
205
- }, nil
231
+ return codelens , nil
206
232
}
207
233
return nil , nil
208
234
}
0 commit comments