@@ -155,27 +155,46 @@ export async function getTestFunctions(
155
155
doc : vscode . TextDocument ,
156
156
token ?: vscode . CancellationToken
157
157
) : 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 } > {
158
167
const documentSymbolProvider = GoDocumentSymbolProvider ( goCtx , true ) ;
159
168
const symbols = await documentSymbolProvider . provideDocumentSymbols ( doc ) ;
160
169
if ( ! symbols || symbols . length === 0 ) {
161
- return ;
170
+ return { } ;
162
171
}
163
172
const symbol = symbols [ 0 ] ;
164
173
if ( ! symbol ) {
165
- return ;
174
+ return { } ;
166
175
}
167
176
const children = symbol . children ;
168
177
169
178
// With gopls symbol provider, the symbols have the imports of all
170
179
// the package, so suite tests from all files will be found.
171
180
const testify = importsTestify ( symbols ) ;
172
- return children . filter (
181
+
182
+ const allTestFunctions = children . filter (
173
183
( sym ) =>
174
- ( sym . kind === vscode . SymbolKind . Function || sym . kind === vscode . SymbolKind . Method ) &&
184
+ sym . kind === vscode . SymbolKind . Function &&
175
185
// Skip TestMain(*testing.M) - see https://github.com/golang/vscode-go/issues/482
176
186
! 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 ) )
178
188
) ;
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
+ } ;
179
198
}
180
199
181
200
/**
@@ -725,3 +744,23 @@ export function importsTestify(syms: vscode.DocumentSymbol[]): boolean {
725
744
( sym . name === '"github.com/stretchr/testify/suite"' || sym . name === 'github.com/stretchr/testify/suite' )
726
745
) ;
727
746
}
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