@@ -155,27 +155,46 @@ export async function getTestFunctions(
155155 doc : vscode . TextDocument ,
156156 token ?: vscode . CancellationToken
157157) : Promise < vscode . DocumentSymbol [ ] | undefined > {
158+ const result = await getTestFunctionsAndTestifyHint ( goCtx , doc , token ) ;
159+ return result . testFunctions ;
160+ }
161+
162+ export async function getTestFunctionsAndTestifyHint (
163+ goCtx : GoExtensionContext ,
164+ doc : vscode . TextDocument ,
165+ token ?: vscode . CancellationToken
166+ ) : Promise < { testFunctions ?: vscode . DocumentSymbol [ ] ; foundTestifyTestFunction ?: boolean } > {
158167 const documentSymbolProvider = GoDocumentSymbolProvider ( goCtx , true ) ;
159168 const symbols = await documentSymbolProvider . provideDocumentSymbols ( doc ) ;
160169 if ( ! symbols || symbols . length === 0 ) {
161- return ;
170+ return { } ;
162171 }
163172 const symbol = symbols [ 0 ] ;
164173 if ( ! symbol ) {
165- return ;
174+ return { } ;
166175 }
167176 const children = symbol . children ;
168177
169178 // With gopls symbol provider, the symbols have the imports of all
170179 // the package, so suite tests from all files will be found.
171180 const testify = importsTestify ( symbols ) ;
172- return children . filter (
181+
182+ const allTestFunctions = children . filter (
173183 ( sym ) =>
174- ( sym . kind === vscode . SymbolKind . Function || sym . kind === vscode . SymbolKind . Method ) &&
184+ sym . kind === vscode . SymbolKind . Function &&
175185 // Skip TestMain(*testing.M) - see https://github.com/golang/vscode-go/issues/482
176186 ! testMainRegex . test ( doc . lineAt ( sym . range . start . line ) . text ) &&
177- ( testFuncRegex . test ( sym . name ) || fuzzFuncRegx . test ( sym . name ) || ( testify && testMethodRegex . test ( sym . name ) ) )
187+ ( testFuncRegex . test ( sym . name ) || fuzzFuncRegx . test ( sym . name ) )
178188 ) ;
189+
190+ const allTestMethods = testify
191+ ? children . filter ( ( sym ) => sym . kind === vscode . SymbolKind . Method && testMethodRegex . test ( sym . name ) )
192+ : [ ] ;
193+
194+ return {
195+ testFunctions : allTestFunctions . concat ( allTestMethods ) ,
196+ foundTestifyTestFunction : allTestMethods . length > 0
197+ } ;
179198}
180199
181200/**
@@ -725,3 +744,23 @@ export function importsTestify(syms: vscode.DocumentSymbol[]): boolean {
725744 ( sym . name === '"github.com/stretchr/testify/suite"' || sym . name === 'github.com/stretchr/testify/suite' )
726745 ) ;
727746}
747+
748+ export async function getTestFunctionsAndTestSuite (
749+ isBenchmark : boolean ,
750+ goCtx : GoExtensionContext ,
751+ document : vscode . TextDocument
752+ ) : Promise < { testFunctions : vscode . DocumentSymbol [ ] ; suiteToTest : SuiteToTestMap } > {
753+ if ( isBenchmark ) {
754+ return {
755+ testFunctions : ( await getBenchmarkFunctions ( goCtx , document ) ) ?? [ ] ,
756+ suiteToTest : { }
757+ } ;
758+ }
759+
760+ const { testFunctions, foundTestifyTestFunction } = await getTestFunctionsAndTestifyHint ( goCtx , document ) ;
761+
762+ return {
763+ testFunctions : testFunctions ?? [ ] ,
764+ suiteToTest : foundTestifyTestFunction ? await getSuiteToTestMap ( goCtx , document ) : { }
765+ } ;
766+ }
0 commit comments