Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to show all test messages. #185197

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 47 additions & 42 deletions src/vs/workbench/contrib/testing/browser/testingDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { DefaultGutterClickAction, TestingConfigKeys, getTestingConfiguration }
import { Testing, labelForTestInState } from 'vs/workbench/contrib/testing/common/constants';
import { TestId } from 'vs/workbench/contrib/testing/common/testId';
import { ITestProfileService } from 'vs/workbench/contrib/testing/common/testProfileService';
import { LiveTestResult } from 'vs/workbench/contrib/testing/common/testResult';
import { ITestResult, LiveTestResult } from 'vs/workbench/contrib/testing/common/testResult';
import { ITestResultService } from 'vs/workbench/contrib/testing/common/testResultService';
import { ITestService, getContextForTestItem, testsInFile } from 'vs/workbench/contrib/testing/common/testService';
import { IRichLocation, ITestMessage, ITestRunProfile, IncrementalTestCollectionItem, InternalTestItem, TestDiffOpType, TestMessageType, TestResultItem, TestResultState, TestRunProfileBitset } from 'vs/workbench/contrib/testing/common/testTypes';
Expand Down Expand Up @@ -318,47 +318,11 @@ export class TestingDecorationService extends Disposable implements ITestingDeco
}
}

const lastResult = this.results.results[0];
if (this.testService.showInlineOutput.value && lastResult instanceof LiveTestResult) {
for (const task of lastResult.tasks) {
for (const m of task.otherMessages) {
if (!this.invalidatedMessages.has(m) && m.location?.uri.toString() === uriStr) {
const decoration = lastDecorations.getMessage(m) || this.instantiationService.createInstance(TestMessageDecoration, m, undefined, model);
newDecorations.addMessage(decoration);
}
}
}

const messageLines = new Map</* line number */ number, /* last test message */ ITestMessage>();
for (const test of lastResult.tests) {
for (let taskId = 0; taskId < test.tasks.length; taskId++) {
const state = test.tasks[taskId];
for (let i = 0; i < state.messages.length; i++) {
const m = state.messages[i];
if (this.invalidatedMessages.has(m) || m.location?.uri.toString() !== uriStr) {
continue;
}

// Only add one message per line number. Overlapping messages
// don't appear well, and the peek will show all of them (#134129)
const line = m.location.range.startLineNumber;
if (messageLines.has(line)) {
newDecorations.removeMessage(messageLines.get(line)!);
}

const decoration = lastDecorations.getMessage(m) || this.instantiationService.createInstance(TestMessageDecoration, m, buildTestUri({
type: TestUriType.ResultActualOutput,
messageIndex: i,
taskIndex: taskId,
resultId: lastResult.id,
testExtId: test.item.extId,
}), model);

newDecorations.addMessage(decoration);
messageLines.set(line, decoration.testMessage);
}
}
}
const messageLines = new Set<number>();
if (getTestingConfiguration(this.configurationService, TestingConfigKeys.ShowAllMessages)) {
this.results.results.forEach(lastResult => this.applyDecorationsFromResult(lastResult, messageLines, uriStr, lastDecorations, model, newDecorations));
} else {
this.applyDecorationsFromResult(this.results.results[0], messageLines, uriStr, lastDecorations, model, newDecorations);
}

const saveFromRemoval = new Set<string>();
Expand Down Expand Up @@ -387,6 +351,47 @@ export class TestingDecorationService extends Disposable implements ITestingDeco

return newDecorations || lastDecorations;
}

private applyDecorationsFromResult(lastResult: ITestResult, messageLines: Set<Number>, uriStr: string, lastDecorations: CachedDecorations, model: ITextModel, newDecorations: CachedDecorations) {
if (this.testService.showInlineOutput.value && lastResult instanceof LiveTestResult) {
for (const task of lastResult.tasks) {
for (const m of task.otherMessages) {
if (!this.invalidatedMessages.has(m) && m.location?.uri.toString() === uriStr) {
const decoration = lastDecorations.getMessage(m) || this.instantiationService.createInstance(TestMessageDecoration, m, undefined, model);
newDecorations.addMessage(decoration);
}
}
}

for (const test of lastResult.tests) {
for (let taskId = 0; taskId < test.tasks.length; taskId++) {
const state = test.tasks[taskId];
for (let i = 0; i < state.messages.length; i++) {
const m = state.messages[i];
if (this.invalidatedMessages.has(m) || m.location?.uri.toString() !== uriStr) {
continue;
}

// Only add one message per line number. Overlapping messages
// don't appear well, and the peek will show all of them (#134129)
const line = m.location.range.startLineNumber;
if (!messageLines.has(line)) {
const decoration = lastDecorations.getMessage(m) || this.instantiationService.createInstance(TestMessageDecoration, m, buildTestUri({
type: TestUriType.ResultActualOutput,
messageIndex: i,
taskIndex: taskId,
resultId: lastResult.id,
testExtId: test.item.extId,
}), model);

newDecorations.addMessage(decoration);
messageLines.add(line);
}
}
}
}
}
}
}

export class TestingDecorations extends Disposable implements IEditorContribution {
Expand Down
9 changes: 8 additions & 1 deletion src/vs/workbench/contrib/testing/common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const enum TestingConfigKeys {
GutterEnabled = 'testing.gutterEnabled',
SaveBeforeTest = 'testing.saveBeforeTest',
AlwaysRevealTestOnStateChange = 'testing.alwaysRevealTestOnStateChange',
CountBadge = 'testing.countBadge'
CountBadge = 'testing.countBadge',
ShowAllMessages = 'testing.showAllMessages',
}

export const enum AutoOpenTesting {
Expand Down Expand Up @@ -71,6 +72,11 @@ export const testingConfiguration: IConfigurationNode = {
localize('testing.automaticallyOpenPeekView.never', "Never automatically open."),
],
},
[TestingConfigKeys.ShowAllMessages]: {
description: localize('testing.showAllMessages', "Controls whether to show messages from all test runs."),
type: 'boolean',
default: true,
},
[TestingConfigKeys.AutoOpenPeekViewDuringContinuousRun]: {
description: localize('testing.automaticallyOpenPeekViewDuringContinuousRun', "Controls whether to automatically open the Peek view during continuous run mode."),
type: 'boolean',
Expand Down Expand Up @@ -154,6 +160,7 @@ export interface ITestingConfiguration {
[TestingConfigKeys.SaveBeforeTest]: boolean;
[TestingConfigKeys.OpenTesting]: AutoOpenTesting;
[TestingConfigKeys.AlwaysRevealTestOnStateChange]: boolean;
[TestingConfigKeys.ShowAllMessages]: boolean;
}

export const getTestingConfiguration = <K extends TestingConfigKeys>(config: IConfigurationService, key: K) => config.getValue<ITestingConfiguration[K]>(key);