@@ -29,7 +29,6 @@ suite('GoPackageOutlineProvider', function () {
2929 } ) ;
3030
3131 setup ( async ( ) => {
32- await vscode . commands . executeCommand ( 'go.packageOutline.disableFollowCursor' ) ;
3332 await vscode . commands . executeCommand ( 'go.packageOutline.sortByPosition' ) ;
3433 } ) ;
3534
@@ -42,7 +41,7 @@ suite('GoPackageOutlineProvider', function () {
4241 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_1.go' ) )
4342 ) ;
4443 await window . showTextDocument ( document ) ;
45- await sleep ( 500 ) ; // wait for gopls response
44+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
4645 const res = provider . result ;
4746 assert . strictEqual ( res ?. PackageName , 'package_outline_test' ) ;
4847 assert . strictEqual ( res ?. Files . length , 2 ) ;
@@ -56,7 +55,7 @@ suite('GoPackageOutlineProvider', function () {
5655 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_1.go' ) )
5756 ) ;
5857 await window . showTextDocument ( document ) ;
59- await sleep ( 500 ) ; // wait for gopls response
58+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
6059 await vscode . commands . executeCommand ( 'setContext' , 'go.showPackageOutline' ) ;
6160 const children = await provider . getChildren ( ) ;
6261 const receiver = children ?. find ( ( symbol ) => symbol . label === 'TestReceiver' ) ;
@@ -75,7 +74,7 @@ suite('GoPackageOutlineProvider', function () {
7574 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_1.go' ) )
7675 ) ;
7776 await window . showTextDocument ( document ) ;
78- await sleep ( 500 ) ; // wait for gopls response
77+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
7978 await vscode . commands . executeCommand ( 'setContext' , 'go.showPackageOutline' ) ;
8079 const children = await provider . getChildren ( ) ;
8180 const receiver = children ?. find ( ( symbol ) => symbol . label === 'TestReceiver' ) ;
@@ -97,7 +96,7 @@ suite('GoPackageOutlineProvider', function () {
9796 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_1.go' ) )
9897 ) ;
9998 await window . showTextDocument ( document ) ;
100- await sleep ( 500 ) ; // wait for gopls response
99+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
101100 await vscode . commands . executeCommand ( 'go.packageOutline.sortByName' ) ;
102101 const children = await provider . getChildren ( ) ;
103102 assert . deepStrictEqual (
@@ -118,21 +117,20 @@ suite('GoPackageOutlineProvider', function () {
118117 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_1.go' ) )
119118 ) ;
120119 await window . showTextDocument ( document ) ;
121- await sleep ( 500 ) ; // wait for gopls response
120+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
122121 const children = await provider . getChildren ( ) ;
123122 assert . deepStrictEqual (
124123 ( children ?? [ ] ) . slice ( 1 ) . map ( ( symbol ) => symbol . label ) ,
125124 [ 'print' , 'main' , 'TestReceiver' ]
126125 ) ;
127126 } ) ;
128127
129- test ( 'follow cursor selects the active symbol' , async ( ) => {
128+ test ( 'cursor changes reveal the active symbol' , async ( ) => {
130129 const document1 = await vscode . workspace . openTextDocument (
131130 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_1.go' ) )
132131 ) ;
133132 await window . showTextDocument ( document1 ) ;
134- await sleep ( 500 ) ; // wait for gopls response
135- await vscode . commands . executeCommand ( 'go.packageOutline.enableFollowCursor' ) ;
133+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
136134 await moveCursor ( document1 , 19 ) ;
137135 await sleep ( 500 ) ; // wait for tree view reveal
138136 assert . strictEqual (
@@ -144,7 +142,7 @@ suite('GoPackageOutlineProvider', function () {
144142 vscode . Uri . file ( path . join ( fixtureDir , 'symbols_2.go' ) )
145143 ) ;
146144 await window . showTextDocument ( document2 ) ;
147- await sleep ( 500 ) ; // wait for gopls response
145+ await waitForOutlineResult ( provider , 'package_outline_test' ) ;
148146 await moveCursor ( document2 , 2 ) ;
149147 await sleep ( 500 ) ; // wait for tree view reveal
150148 assert . strictEqual (
@@ -167,6 +165,17 @@ function sleep(ms: number) {
167165 return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
168166}
169167
168+ async function waitForOutlineResult ( provider : GoPackageOutlineProvider , packageName : string ) {
169+ const deadline = Date . now ( ) + 5000 ;
170+ while ( Date . now ( ) < deadline ) {
171+ if ( provider . result ?. PackageName === packageName ) {
172+ return ;
173+ }
174+ await sleep ( 100 ) ;
175+ }
176+ assert . fail ( `timed out waiting for outline result for ${ packageName } ` ) ;
177+ }
178+
170179async function moveCursor ( document : vscode . TextDocument , line : number , character = 0 ) {
171180 const editor = await window . showTextDocument ( document ) ;
172181 const position = new vscode . Position ( line , character ) ;
0 commit comments