Skip to content

Commit

Permalink
update:identify gop test file
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Apr 10, 2024
1 parent db25e94 commit 3d1bb2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/goDocumentSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion src/goRunTestCodelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 [];
}
Expand All @@ -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, {
Expand Down

0 comments on commit 3d1bb2c

Please sign in to comment.