10
10
import cp = require( 'child_process' ) ;
11
11
import path = require( 'path' ) ;
12
12
import util = require( 'util' ) ;
13
- import fs = require( 'fs' ) ;
14
13
import vscode = require( 'vscode' ) ;
15
14
16
15
import { applyCodeCoverageToAllEditors } from './goCover' ;
@@ -150,8 +149,6 @@ export async function getTestFunctions(
150
149
token ?: vscode . CancellationToken
151
150
) : Promise < vscode . DocumentSymbol [ ] | undefined > {
152
151
const documentSymbolProvider = GoDocumentSymbolProvider ( goCtx , true ) ;
153
-
154
- const testify = await isPackageTestify ( documentSymbolProvider . provideDocumentSymbols , doc , token ) ;
155
152
const symbols = await documentSymbolProvider . provideDocumentSymbols ( doc , token ) ;
156
153
if ( ! symbols || symbols . length === 0 ) {
157
154
return ;
@@ -161,6 +158,10 @@ export async function getTestFunctions(
161
158
return ;
162
159
}
163
160
const children = symbol . children ;
161
+
162
+ // symbols got the imports of all the package.
163
+ const testify = importsTestify ( symbols ) ;
164
+
164
165
return children . filter (
165
166
( sym ) =>
166
167
( sym . kind === vscode . SymbolKind . Function || sym . kind === vscode . SymbolKind . Method ) &&
@@ -588,35 +589,6 @@ export function cancelRunningTests(): Thenable<boolean> {
588
589
} ) ;
589
590
}
590
591
591
- export type ProvideSymbols = (
592
- doc : vscode . TextDocument ,
593
- token ?: vscode . CancellationToken
594
- ) => Thenable < vscode . DocumentSymbol [ ] > ;
595
-
596
- /**
597
- * Returns whether a file in the package imports testify.
598
- */
599
- export async function isPackageTestify (
600
- symbolsProvier : ProvideSymbols ,
601
- doc : vscode . TextDocument ,
602
- token ?: vscode . CancellationToken | undefined
603
- ) {
604
- const fsReaddir = util . promisify ( fs . readdir ) ;
605
-
606
- // Get all the package documents.
607
- const packageDir = path . parse ( doc . fileName ) . dir ;
608
- const packageFilenames = await fsReaddir ( packageDir ) ;
609
- const packageDocs = await Promise . all (
610
- packageFilenames . map ( ( e ) => path . join ( packageDir , e ) ) . map ( vscode . workspace . openTextDocument )
611
- ) ;
612
-
613
- // Parse the symbols of each document.
614
- const docSymbols = await Promise . all ( packageDocs . map ( ( e ) => symbolsProvier ( e , token ) ) ) ;
615
-
616
- // One file is enough.
617
- return docSymbols . some ( importsTestify ) ;
618
- }
619
-
620
592
/**
621
593
* Get the test target arguments.
622
594
*
@@ -671,7 +643,7 @@ function removeRunFlag(flags: string[]): void {
671
643
}
672
644
}
673
645
674
- function importsTestify ( syms : vscode . DocumentSymbol [ ] ) : boolean {
646
+ export function importsTestify ( syms : vscode . DocumentSymbol [ ] ) : boolean {
675
647
if ( ! syms || syms . length === 0 || ! syms [ 0 ] ) {
676
648
return false ;
677
649
}
0 commit comments