mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
testing: fix title for show/hide inline coverage (#213946)
Fixes #213830
This commit is contained in:
parent
98b6706768
commit
e2e6f63477
|
@ -16,7 +16,7 @@ import { IMarkdownString, MarkdownString } from 'vs/base/common/htmlContent';
|
|||
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { Lazy } from 'vs/base/common/lazy';
|
||||
import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { autorun, derived, observableFromEvent, observableValue } from 'vs/base/common/observable';
|
||||
import { autorun, derived, observableFromEvent } from 'vs/base/common/observable';
|
||||
import { ThemeIcon } from 'vs/base/common/themables';
|
||||
import { isUriComponents, URI } from 'vs/base/common/uri';
|
||||
import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, MouseTargetType, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser';
|
||||
|
@ -59,7 +59,6 @@ const TOGGLE_INLINE_COMMAND_ID = 'testing.toggleInlineCoverage';
|
|||
const BRANCH_MISS_INDICATOR_CHARS = 4;
|
||||
|
||||
export class CodeCoverageDecorations extends Disposable implements IEditorContribution {
|
||||
public static showInline = observableValue('inlineCoverage', false);
|
||||
private static readonly fileCoverageDecorations = new WeakMap<FileCoverage, CoverageDetailsModel>();
|
||||
|
||||
private loadingCancellation?: CancellationTokenSource;
|
||||
|
@ -77,7 +76,7 @@ export class CodeCoverageDecorations extends Disposable implements IEditorContri
|
|||
constructor(
|
||||
private readonly editor: ICodeEditor,
|
||||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@ITestCoverageService coverage: ITestCoverageService,
|
||||
@ITestCoverageService private readonly coverage: ITestCoverageService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@ILogService private readonly log: ILogService,
|
||||
) {
|
||||
|
@ -116,7 +115,7 @@ export class CodeCoverageDecorations extends Disposable implements IEditorContri
|
|||
this._register(autorun(reader => {
|
||||
const c = fileCoverage.read(reader);
|
||||
if (c) {
|
||||
this.apply(editor.getModel()!, c, CodeCoverageDecorations.showInline.read(reader));
|
||||
this.apply(editor.getModel()!, c, coverage.showInline.read(reader));
|
||||
} else {
|
||||
this.clear();
|
||||
}
|
||||
|
@ -146,7 +145,7 @@ export class CodeCoverageDecorations extends Disposable implements IEditorContri
|
|||
const model = editor.getModel();
|
||||
if (e.target.type === MouseTargetType.GUTTER_LINE_NUMBERS && model) {
|
||||
this.hoverLineNumber(editor.getModel()!, e.target.position.lineNumber);
|
||||
} else if (CodeCoverageDecorations.showInline.get() && e.target.type === MouseTargetType.CONTENT_TEXT && model) {
|
||||
} else if (coverage.showInline.get() && e.target.type === MouseTargetType.CONTENT_TEXT && model) {
|
||||
this.hoverInlineDecoration(model, e.target.position);
|
||||
} else {
|
||||
this.hoveredStore.clear();
|
||||
|
@ -214,7 +213,7 @@ export class CodeCoverageDecorations extends Disposable implements IEditorContri
|
|||
|
||||
const todo = [{ line: lineNumber, dir: 0 }];
|
||||
const toEnable = new Set<string>();
|
||||
if (!CodeCoverageDecorations.showInline.get()) {
|
||||
if (!this.coverage.showInline.get()) {
|
||||
for (let i = 0; i < todo.length && i < MAX_HOVERED_LINES; i++) {
|
||||
const { line, dir } = todo[i];
|
||||
let found = false;
|
||||
|
@ -556,6 +555,7 @@ class CoverageToolbarWidget extends Disposable implements IOverlayWidget {
|
|||
@ITestService private readonly testService: ITestService,
|
||||
@IKeybindingService private readonly keybindingService: IKeybindingService,
|
||||
@ICommandService private readonly commandService: ICommandService,
|
||||
@ITestCoverageService private readonly coverage: ITestCoverageService,
|
||||
@IInstantiationService instaService: IInstantiationService,
|
||||
) {
|
||||
super();
|
||||
|
@ -579,7 +579,7 @@ class CoverageToolbarWidget extends Disposable implements IOverlayWidget {
|
|||
|
||||
|
||||
this._register(autorun(reader => {
|
||||
CodeCoverageDecorations.showInline.read(reader);
|
||||
coverage.showInline.read(reader);
|
||||
this.setActions();
|
||||
}));
|
||||
|
||||
|
@ -630,12 +630,12 @@ class CoverageToolbarWidget extends Disposable implements IOverlayWidget {
|
|||
|
||||
const toggleAction = new ActionWithIcon(
|
||||
'toggleInline',
|
||||
CodeCoverageDecorations.showInline.get()
|
||||
this.coverage.showInline.get()
|
||||
? localize('testing.hideInlineCoverage', 'Hide Inline Coverage')
|
||||
: localize('testing.showInlineCoverage', 'Show Inline Coverage'),
|
||||
testingCoverageReport,
|
||||
undefined,
|
||||
() => CodeCoverageDecorations.showInline.set(!CodeCoverageDecorations.showInline.get(), undefined),
|
||||
() => this.coverage.showInline.set(!this.coverage.showInline.get(), undefined),
|
||||
);
|
||||
|
||||
const kb = this.keybindingService.lookupKeybinding(TOGGLE_INLINE_COMMAND_ID);
|
||||
|
@ -728,12 +728,18 @@ registerAction2(class ToggleInlineCoverage extends Action2 {
|
|||
constructor() {
|
||||
super({
|
||||
id: TOGGLE_INLINE_COMMAND_ID,
|
||||
title: localize2('coverage.toggleInline', "Show Inline Coverage"),
|
||||
// note: ideally this would be "show inline", but the command palette does
|
||||
// not use the 'toggled' titles, so we need to make this generic.
|
||||
title: localize2('coverage.toggleInline', "Toggle Inline Coverage"),
|
||||
category: Categories.Test,
|
||||
keybinding: {
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.Semicolon, KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyI),
|
||||
},
|
||||
toggled: {
|
||||
condition: TestingContextKeys.inlineCoverageEnabled,
|
||||
title: localize('coverage.hideInline', "Hide Inline Coverage"),
|
||||
},
|
||||
icon: testingCoverageReport,
|
||||
menu: [
|
||||
{ id: MenuId.CommandPalette, when: TestingContextKeys.isTestCoverageOpen },
|
||||
|
@ -742,8 +748,9 @@ registerAction2(class ToggleInlineCoverage extends Action2 {
|
|||
});
|
||||
}
|
||||
|
||||
public run() {
|
||||
CodeCoverageDecorations.showInline.set(!CodeCoverageDecorations.showInline.get(), undefined);
|
||||
public run(accessor: ServicesAccessor): void {
|
||||
const coverage = accessor.get(ITestCoverageService);
|
||||
coverage.showInline.set(!coverage.showInline.get(), undefined);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -35,6 +35,11 @@ export interface ITestCoverageService {
|
|||
*/
|
||||
readonly filterToTest: ISettableObservable<TestId | undefined>;
|
||||
|
||||
/**
|
||||
* Whether inline coverage is shown.
|
||||
*/
|
||||
readonly showInline: ISettableObservable<boolean>;
|
||||
|
||||
/**
|
||||
* Opens a test coverage report from a task, optionally focusing it in the editor.
|
||||
*/
|
||||
|
@ -52,6 +57,7 @@ export class TestCoverageService extends Disposable implements ITestCoverageServ
|
|||
|
||||
public readonly selected = observableValue<TestCoverage | undefined>('testCoverage', undefined);
|
||||
public readonly filterToTest = observableValue<TestId | undefined>('filterToTest', undefined);
|
||||
public readonly showInline = observableValue('inlineCoverage', false);
|
||||
|
||||
constructor(
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
|
@ -68,6 +74,12 @@ export class TestCoverageService extends Disposable implements ITestCoverageServ
|
|||
reader => toolbarConfig.read(reader),
|
||||
));
|
||||
|
||||
this._register(bindContextKey(
|
||||
TestingContextKeys.inlineCoverageEnabled,
|
||||
contextKeyService,
|
||||
reader => this.showInline.read(reader),
|
||||
));
|
||||
|
||||
this._register(bindContextKey(
|
||||
TestingContextKeys.isTestCoverageOpen,
|
||||
contextKeyService,
|
||||
|
|
|
@ -25,6 +25,7 @@ export namespace TestingContextKeys {
|
|||
export const hasPerTestCoverage = new RawContextKey('testing.hasPerTestCoverage', false, { type: 'boolean', description: localize('testing.hasPerTestCoverage', 'Indicates whether per-test coverage is available') });
|
||||
export const isCoverageFilteredToTest = new RawContextKey('testing.isCoverageFilteredToTest', false, { type: 'boolean', description: localize('testing.isCoverageFilteredToTest', 'Indicates whether coverage has been filterd to a single test') });
|
||||
export const coverageToolbarEnabled = new RawContextKey('testing.coverageToolbarEnabled', true, { type: 'boolean', description: localize('testing.coverageToolbarEnabled', 'Indicates whether the coverage toolbar is enabled') });
|
||||
export const inlineCoverageEnabled = new RawContextKey('testing.inlineCoverageEnabled', false, { type: 'boolean', description: localize('testing.inlineCoverageEnabled', 'Indicates whether inline coverage is shown') });
|
||||
|
||||
export const capabilityToContextKey: { [K in TestRunProfileBitset]: RawContextKey<boolean> } = {
|
||||
[TestRunProfileBitset.Run]: hasRunnableTests,
|
||||
|
|
Loading…
Reference in a new issue