@@ -520,43 +520,57 @@ module example.com
520
520
-- a/a.go --
521
521
package a
522
522
523
- func f() {
523
+ func f(x int) int {
524
524
println("hello")
525
525
defer println("world")
526
+ return x
526
527
}
527
528
528
529
func g() {
529
530
println("goodbye")
530
531
}
532
+
533
+ var v = [...]int{
534
+ f(123),
535
+ f(456),
536
+ }
537
+
538
+ func init() {
539
+ f(789)
540
+ }
531
541
`
532
542
Run (t , files , func (t * testing.T , env * Env ) {
533
543
env .OpenFile ("a/a.go" )
534
544
535
- // Invoke the "Browse assembly" code action to start the server.
536
- loc := env .RegexpSearch ("a/a.go" , "println" )
537
- actions , err := env .Editor .CodeAction (env .Ctx , loc , nil , protocol .CodeActionUnknownTrigger )
538
- if err != nil {
539
- t .Fatalf ("CodeAction: %v" , err )
540
- }
541
- action , err := codeActionByKind (actions , settings .GoAssembly )
542
- if err != nil {
543
- t .Fatal (err )
544
- }
545
+ asmFor := func (pattern string ) []byte {
546
+ // Invoke the "Browse assembly" code action to start the server.
547
+ loc := env .RegexpSearch ("a/a.go" , pattern )
548
+ actions , err := env .Editor .CodeAction (env .Ctx , loc , nil , protocol .CodeActionUnknownTrigger )
549
+ if err != nil {
550
+ t .Fatalf ("CodeAction: %v" , err )
551
+ }
552
+ action , err := codeActionByKind (actions , settings .GoAssembly )
553
+ if err != nil {
554
+ t .Fatal (err )
555
+ }
545
556
546
- // Execute the command.
547
- // Its side effect should be a single showDocument request.
548
- params := & protocol.ExecuteCommandParams {
549
- Command : action .Command .Command ,
550
- Arguments : action .Command .Arguments ,
551
- }
552
- var result command.DebuggingResult
553
- collectDocs := env .Awaiter .ListenToShownDocuments ()
554
- env .ExecuteCommand (params , & result )
555
- doc := shownDocument (t , collectDocs (), "http:" )
556
- if doc == nil {
557
- t .Fatalf ("no showDocument call had 'file:' prefix" )
557
+ // Execute the command.
558
+ // Its side effect should be a single showDocument request.
559
+ params := & protocol.ExecuteCommandParams {
560
+ Command : action .Command .Command ,
561
+ Arguments : action .Command .Arguments ,
562
+ }
563
+ var result command.DebuggingResult
564
+ collectDocs := env .Awaiter .ListenToShownDocuments ()
565
+ env .ExecuteCommand (params , & result )
566
+ doc := shownDocument (t , collectDocs (), "http:" )
567
+ if doc == nil {
568
+ t .Fatalf ("no showDocument call had 'file:' prefix" )
569
+ }
570
+ t .Log ("showDocument(package doc) URL:" , doc .URI )
571
+
572
+ return get (t , doc .URI )
558
573
}
559
- t .Log ("showDocument(package doc) URL:" , doc .URI )
560
574
561
575
// Get the report and do some minimal checks for sensible results.
562
576
//
@@ -567,23 +581,42 @@ func g() {
567
581
// (e.g. uses JAL for CALL, or BL<cc> for RET).
568
582
// We conservatively test only on the two most popular
569
583
// architectures.
570
- report := get (t , doc .URI )
571
- checkMatch (t , true , report , `TEXT.*example.com/a.f` )
572
- switch runtime .GOARCH {
573
- case "amd64" , "arm64" :
574
- checkMatch (t , true , report , `CALL runtime.printlock` )
575
- checkMatch (t , true , report , `CALL runtime.printstring` )
576
- checkMatch (t , true , report , `CALL runtime.printunlock` )
577
- checkMatch (t , true , report , `CALL example.com/a.f.deferwrap1` )
578
- checkMatch (t , true , report , `RET` )
579
- checkMatch (t , true , report , `CALL runtime.morestack_noctxt` )
584
+ {
585
+ report := asmFor ("println" )
586
+ checkMatch (t , true , report , `TEXT.*example.com/a.f` )
587
+ switch runtime .GOARCH {
588
+ case "amd64" , "arm64" :
589
+ checkMatch (t , true , report , `CALL runtime.printlock` )
590
+ checkMatch (t , true , report , `CALL runtime.printstring` )
591
+ checkMatch (t , true , report , `CALL runtime.printunlock` )
592
+ checkMatch (t , true , report , `CALL example.com/a.f.deferwrap1` )
593
+ checkMatch (t , true , report , `RET` )
594
+ checkMatch (t , true , report , `CALL runtime.morestack_noctxt` )
595
+ }
596
+
597
+ // Nested functions are also shown.
598
+ checkMatch (t , true , report , `TEXT.*example.com/a.f.deferwrap1` )
599
+
600
+ // But other functions are not.
601
+ checkMatch (t , false , report , `TEXT.*example.com/a.g` )
580
602
}
581
603
582
- // Nested functions are also shown.
583
- checkMatch (t , true , report , `TEXT.*example.com/a.f.deferwrap1` )
604
+ // Check that code in a package-level var initializer is found too.
605
+ {
606
+ report := asmFor (`f\(123\)` )
607
+ checkMatch (t , true , report , `TEXT.*example.com/a.init` )
608
+ checkMatch (t , true , report , `MOV. \$123` )
609
+ checkMatch (t , true , report , `MOV. \$456` )
610
+ checkMatch (t , true , report , `CALL example.com/a.f` )
611
+ }
584
612
585
- // But other functions are not.
586
- checkMatch (t , false , report , `TEXT.*example.com/a.g` )
613
+ // And code in a source-level init function.
614
+ {
615
+ report := asmFor (`f\(789\)` )
616
+ checkMatch (t , true , report , `TEXT.*example.com/a.init` )
617
+ checkMatch (t , true , report , `MOV. \$789` )
618
+ checkMatch (t , true , report , `CALL example.com/a.f` )
619
+ }
587
620
})
588
621
}
589
622
0 commit comments