From db25e94380f69e0d36133bbabb5454127c264b7c Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Tue, 9 Apr 2024 18:04:42 +0800 Subject: [PATCH 1/4] update:support yap test codelens --- src/goDocumentSymbols.ts | 2 +- src/goRunTestCodelens.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/goDocumentSymbols.ts b/src/goDocumentSymbols.ts index cb18669e92..0faf0158c6 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')) { + } else if (document.fileName.endsWith('_test.gop') || document.fileName.endsWith('_ytest.gox')) { pkgName = 'main'; // goxls: default test pkg } const packageSymbol = new vscode.DocumentSymbol( diff --git a/src/goRunTestCodelens.ts b/src/goRunTestCodelens.ts index 5bf9802daa..7026cb0a95 100644 --- a/src/goRunTestCodelens.ts +++ b/src/goRunTestCodelens.ts @@ -47,7 +47,12 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider { const config = getGoConfig(document.uri); const codeLensConfig = config.get<{ [key: string]: any }>('enableCodeLens'); const codelensEnabled = codeLensConfig ? codeLensConfig['runtest'] : false; - if (!codelensEnabled || (!document.fileName.endsWith('_test.go') && !document.fileName.endsWith('_test.gop'))) { + if ( + !codelensEnabled || + (!document.fileName.endsWith('_test.go') && + !document.fileName.endsWith('_test.gop') && + !document.fileName.endsWith('_ytest.gox')) + ) { return []; } From 3d1bb2c7fb6cc028e8797cca69acff8643e0ce67 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 10 Apr 2024 19:17:14 +0800 Subject: [PATCH 2/4] update:identify gop test file --- src/goDocumentSymbols.ts | 2 +- src/goRunTestCodelens.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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, { From 8fed75723d1868d9ddd1484a38250a544231aac6 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Fri, 12 Apr 2024 19:26:17 +0800 Subject: [PATCH 3/4] update:determine whether test.gox is a test with symbol --- src/goRunTestCodelens.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/goRunTestCodelens.ts b/src/goRunTestCodelens.ts index 67d8bab460..51f745824e 100644 --- a/src/goRunTestCodelens.ts +++ b/src/goRunTestCodelens.ts @@ -74,16 +74,15 @@ 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) { + if (document.fileName.endsWith('test.gox')) { + if ( + !pkg.children.some( + (sym) => + sym.kind === vscode.SymbolKind.Method && + sym.name.startsWith('(*case') && + sym.name.endsWith('TestMain') + ) + ) { return []; } } From 949daba95eb5153385d5dc48db09fe1d4fc4d189 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Tue, 16 Apr 2024 14:05:00 +0800 Subject: [PATCH 4/4] fix:gox use gop test --- src/goRunTestCodelens.ts | 20 +------------------- src/goTest.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/goRunTestCodelens.ts b/src/goRunTestCodelens.ts index 51f745824e..5bf9802daa 100644 --- a/src/goRunTestCodelens.ts +++ b/src/goRunTestCodelens.ts @@ -15,7 +15,6 @@ 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) { @@ -48,12 +47,7 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider { const config = getGoConfig(document.uri); const codeLensConfig = config.get<{ [key: string]: any }>('enableCodeLens'); const codelensEnabled = codeLensConfig ? codeLensConfig['runtest'] : false; - if ( - !codelensEnabled || - (!document.fileName.endsWith('_test.go') && - !document.fileName.endsWith('_test.gop') && - !document.fileName.endsWith('test.gox')) - ) { + if (!codelensEnabled || (!document.fileName.endsWith('_test.go') && !document.fileName.endsWith('_test.gop'))) { return []; } @@ -74,18 +68,6 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider { if (!pkg) { return []; } - if (document.fileName.endsWith('test.gox')) { - if ( - !pkg.children.some( - (sym) => - sym.kind === vscode.SymbolKind.Method && - sym.name.startsWith('(*case') && - sym.name.endsWith('TestMain') - ) - ) { - return []; - } - } const range = pkg.range; const packageCodeLens = [ new CodeLens(range, { diff --git a/src/goTest.ts b/src/goTest.ts index 9c3e624d47..d7438a7940 100644 --- a/src/goTest.ts +++ b/src/goTest.ts @@ -48,7 +48,11 @@ async function _testAtCursor( if (!editor) { throw new NotFoundError('No editor is active.'); } - if (!editor.document.fileName.endsWith('_test.go') && !editor.document.fileName.endsWith('_test.gop')) { + if ( + !editor.document.fileName.endsWith('_test.go') && + !editor.document.fileName.endsWith('_test.gop') && + !editor.document.fileName.endsWith('test.gox') + ) { throw new NotFoundError('No tests found. Current file is not a test file.'); } @@ -210,9 +214,8 @@ async function runTestAtCursor( if (cmd !== 'benchmark' && extractInstanceTestName(testFunctionName)) { testConfigFns.push(...findAllTestSuiteRuns(editor.document, testFunctions).map((t) => t.name)); } - const isMod = await isModSupported(editor.document.uri); - const isGop = editor.document.fileName.endsWith('.gop'); // goxls: isGop + const isGop = editor.document.fileName.endsWith('.gop') || editor.document.fileName.endsWith('.gox'); // goxls: isGop const testConfig: TestConfig = { goConfig, dir: path.dirname(editor.document.fileName), @@ -381,7 +384,11 @@ export function testCurrentFile(isBenchmark: boolean, getConfig = getGoConfig): vscode.window.showInformationMessage('No editor is active.'); return false; } - if (!editor.document.fileName.endsWith('_test.go') && !editor.document.fileName.endsWith('_test.gop')) { + if ( + !editor.document.fileName.endsWith('_test.go') && + !editor.document.fileName.endsWith('_test.gop') && + !editor.document.fileName.endsWith('test.gox') + ) { vscode.window.showInformationMessage('No tests found. Current file is not a test file.'); return false; }