@@ -520,43 +520,57 @@ module example.com
520520-- a/a.go --
521521package a
522522
523- func f() {
523+ func f(x int) int {
524524 println("hello")
525525 defer println("world")
526+ return x
526527}
527528
528529func g() {
529530 println("goodbye")
530531}
532+
533+ var v = [...]int{
534+ f(123),
535+ f(456),
536+ }
537+
538+ func init() {
539+ f(789)
540+ }
531541`
532542 Run (t , files , func (t * testing.T , env * Env ) {
533543 env .OpenFile ("a/a.go" )
534544
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+ }
545556
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 )
558573 }
559- t .Log ("showDocument(package doc) URL:" , doc .URI )
560574
561575 // Get the report and do some minimal checks for sensible results.
562576 //
@@ -567,23 +581,42 @@ func g() {
567581 // (e.g. uses JAL for CALL, or BL<cc> for RET).
568582 // We conservatively test only on the two most popular
569583 // 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` )
580602 }
581603
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+ }
584612
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+ }
587620 })
588621}
589622
0 commit comments