diff --git a/src/vs/workbench/contrib/testing/browser/testExplorerActions.ts b/src/vs/workbench/contrib/testing/browser/testExplorerActions.ts index 9542ec33401..65900ea1e04 100644 --- a/src/vs/workbench/contrib/testing/browser/testExplorerActions.ts +++ b/src/vs/workbench/contrib/testing/browser/testExplorerActions.ts @@ -7,7 +7,7 @@ import { Codicon } from 'vs/base/common/codicons'; import { Iterable } from 'vs/base/common/iterator'; import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { isDefined } from 'vs/base/common/types'; -import { Range } from 'vs/editor/common/core/range'; +import { IRange, Range } from 'vs/editor/common/core/range'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { localize } from 'vs/nls'; import { Action2, IAction2Options, MenuId } from 'vs/platform/actions/common/actions'; @@ -730,21 +730,34 @@ abstract class ExecuteTestAtCursor extends Action2 { } const testService = accessor.get(ITestService); - let bestNode: InternalTestItem | undefined; + const profileService = accessor.get(ITestProfileService); + let bestNodes: InternalTestItem[] = []; + let bestRange: IRange | undefined; + + // testsInFile will descend in the test tree. We assume that as we go + // deeper, ranges get more specific. We'll want to run all tests whose + // range is equal to the most specific range we find (see #133519) await showDiscoveringWhile(accessor.get(IProgressService), (async () => { for await (const test of testsInFile(testService.collection, model.uri)) { - if (test.item.range && Range.containsPosition(test.item.range, position)) { - bestNode = test; + if (!test.item.range || !Range.containsPosition(test.item.range, position) || !(profileService.capabilitiesForTest(test) & this.group)) { + continue; + } + + if (bestRange && Range.equalsRange(test.item.range, bestRange)) { + bestNodes.push(test); + } else { + bestRange = test.item.range; + bestNodes = [test]; } } })()); - if (bestNode) { + if (bestNodes.length) { await testService.runTests({ group: this.group, - tests: [bestNode], + tests: bestNodes, }); } } diff --git a/src/vs/workbench/contrib/testing/browser/testingDecorations.ts b/src/vs/workbench/contrib/testing/browser/testingDecorations.ts index e0f816529d5..8169d597eb7 100644 --- a/src/vs/workbench/contrib/testing/browser/testingDecorations.ts +++ b/src/vs/workbench/contrib/testing/browser/testingDecorations.ts @@ -48,7 +48,6 @@ import { ITestProfileService } from 'vs/workbench/contrib/testing/common/testPro import { LiveTestResult } from 'vs/workbench/contrib/testing/common/testResult'; import { ITestResultService } from 'vs/workbench/contrib/testing/common/testResultService'; import { getContextForTestItem, ITestService, testsInFile } from 'vs/workbench/contrib/testing/common/testService'; -import { ITextEditorService } from 'vs/workbench/services/textfile/common/textEditorService'; function isOriginalInDiffEditor(codeEditorService: ICodeEditorService, codeEditor: ICodeEditor): boolean { const diffEditors = codeEditorService.listDiffEditors(); @@ -563,7 +562,7 @@ abstract class RunTestDecoration { }[], private visible: boolean, protected readonly model: ITextModel, - @ITextEditorService private readonly codeEditorService: ICodeEditorService, + @ICodeEditorService private readonly codeEditorService: ICodeEditorService, @ITestService protected readonly testService: ITestService, @IContextMenuService protected readonly contextMenuService: IContextMenuService, @ICommandService protected readonly commandService: ICommandService,