diff --git a/src/goDocumentSymbols.ts b/src/goDocumentSymbols.ts index 0faf0158c6..7e98392b30 100644 --- a/src/goDocumentSymbols.ts +++ b/src/goDocumentSymbols.ts @@ -60,7 +60,7 @@ export class GoplsDocumentSymbolProvider implements vscode.DocumentSymbolProvide const start = text.indexOf(packageDecl); pkgDeclRng = new vscode.Range(document.positionAt(start), document.positionAt(start + packageDecl.length)); pkgName = packageDecl[1]; - } else if (document.fileName.endsWith('_test.gop') || document.fileName.endsWith('_ytest.gox')) { + } else if (document.fileName.endsWith('_test.gop') || document.fileName.endsWith('test.gox')) { pkgName = 'main'; // goxls: default test pkg } const packageSymbol = new vscode.DocumentSymbol( diff --git a/src/goRunTestCodelens.ts b/src/goRunTestCodelens.ts index 7026cb0a95..67d8bab460 100644 --- a/src/goRunTestCodelens.ts +++ b/src/goRunTestCodelens.ts @@ -15,6 +15,7 @@ import { GoDocumentSymbolProvider } from './goDocumentSymbols'; import { getBenchmarkFunctions, getTestFunctions } from './testUtils'; import { GoExtensionContext } from './context'; import { GO_MODE, GOP_MODE } from './goMode'; +import path = require('path'); export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider { static activate(ctx: vscode.ExtensionContext, goCtx: GoExtensionContext) { @@ -51,7 +52,7 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider { !codelensEnabled || (!document.fileName.endsWith('_test.go') && !document.fileName.endsWith('_test.gop') && - !document.fileName.endsWith('_ytest.gox')) + !document.fileName.endsWith('test.gox')) ) { return []; } @@ -73,6 +74,19 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider { if (!pkg) { return []; } + const file = path.parse(document.fileName); + if (!document.fileName.endsWith('.go') && file.name.endsWith('test')) { + // get_test.gox -> classname:get + // get_ytest.gox -> classname:get + const classname = file.name.replace(/(_test|_ytest)$/, ''); + const testFuncSymbolName = `(*case_${classname}).Main`; // "(*case_get).Main" determine is test + const isTest = pkg.children.some((sym) => { + return sym.kind === vscode.SymbolKind.Method && sym.name === testFuncSymbolName; + }); + if (!isTest) { + return []; + } + } const range = pkg.range; const packageCodeLens = [ new CodeLens(range, {