Skip to content

Commit 91892fb

Browse files
authored
fix: don't duplicate test gutter icons when ranges expand (microsoft#181279)
Fixes microsoft#176951
1 parent 6f9bd01 commit 91892fb

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/vs/workbench/contrib/testing/browser/testing.contribution.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ CommandsRegistry.registerCommand({
176176
const fileService = accessor.get(IFileService);
177177
const openerService = accessor.get(IOpenerService);
178178

179-
let { range, uri } = test.item;
179+
const { range, uri } = test.item;
180180
if (!uri) {
181181
return;
182182
}
183183

184184
// If an editor has the file open, there are decorations. Try to adjust the
185185
// revealed range to those decorations (#133441).
186-
range = accessor.get(ITestingDecorationsService).getDecoratedRangeForTest(uri, extId) || range;
186+
const position = accessor.get(ITestingDecorationsService).getDecoratedTestPosition(uri, extId) || range?.getStartPosition();
187187

188188
accessor.get(ITestExplorerFilterState).reveal.value = extId;
189189
accessor.get(ITestingPeekOpener).closeAllPeeks();
@@ -202,8 +202,8 @@ CommandsRegistry.registerCommand({
202202
return;
203203
}
204204

205-
await openerService.open(range
206-
? uri.with({ fragment: `L${range.startLineNumber}:${range.startColumn}` })
205+
await openerService.open(position
206+
? uri.with({ fragment: `L${position.lineNumber}:${position.column}` })
207207
: uri
208208
);
209209
}

src/vs/workbench/contrib/testing/browser/testingDecorations.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class TestingDecorationService extends Disposable implements ITestingDeco
254254
}
255255

256256
/** @inheritdoc */
257-
public getDecoratedRangeForTest(resource: URI, testId: string) {
257+
public getDecoratedTestPosition(resource: URI, testId: string) {
258258
const model = this.modelService.getModel(resource);
259259
if (!model) {
260260
return undefined;
@@ -265,7 +265,8 @@ export class TestingDecorationService extends Disposable implements ITestingDeco
265265
return undefined;
266266
}
267267

268-
return model.getDecorationRange(decoration.id) || undefined;
268+
// decoration is collapsed, so the range is meaningless; only position matters.
269+
return model.getDecorationRange(decoration.id)?.getStartPosition();
269270
}
270271

271272
private invalidate() {
@@ -512,11 +513,11 @@ export class TestingDecorations extends Disposable implements IEditorContributio
512513
}
513514
}
514515

515-
const firstLineRange = (originalRange: IRange) => ({
516+
const collapseRange = (originalRange: IRange) => ({
516517
startLineNumber: originalRange.startLineNumber,
517518
endLineNumber: originalRange.startLineNumber,
518-
startColumn: 0,
519-
endColumn: Number.MAX_SAFE_INTEGER,
519+
startColumn: originalRange.startColumn,
520+
endColumn: originalRange.startColumn,
520521
});
521522

522523
const createRunTestDecoration = (tests: readonly IncrementalTestCollectionItem[], states: readonly (TestResultItem | undefined)[], visible: boolean): IModelDeltaDecoration => {
@@ -526,7 +527,7 @@ const createRunTestDecoration = (tests: readonly IncrementalTestCollectionItem[]
526527
}
527528

528529
if (!visible) {
529-
return { range: firstLineRange(range), options: { isWholeLine: true, description: 'run-test-decoration' } };
530+
return { range: collapseRange(range), options: { isWholeLine: true, description: 'run-test-decoration' } };
530531
}
531532

532533
let computedState = TestResultState.Unset;
@@ -560,10 +561,10 @@ const createRunTestDecoration = (tests: readonly IncrementalTestCollectionItem[]
560561
}
561562

562563
return {
563-
range: firstLineRange(range),
564+
range: collapseRange(range),
564565
options: {
565566
description: 'run-test-decoration',
566-
isWholeLine: true,
567+
showIfCollapsed: true,
567568
get hoverMessage() {
568569
if (!hoverMessage) {
569570
const building = hoverMessage = new MarkdownString('', true).appendText(hoverMessageParts.join(', ') + '.');

src/vs/workbench/contrib/testing/common/testingDecorations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IAction } from 'vs/base/common/actions';
77
import { binarySearch } from 'vs/base/common/arrays';
88
import { Event } from 'vs/base/common/event';
99
import { URI } from 'vs/base/common/uri';
10-
import { Range } from 'vs/editor/common/core/range';
10+
import { Position } from 'vs/editor/common/core/position';
1111
import { IModelDeltaDecoration } from 'vs/editor/common/model';
1212
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1313
import { ITestMessage } from 'vs/workbench/contrib/testing/common/testTypes';
@@ -40,7 +40,7 @@ export interface ITestingDecorationsService {
4040
* Gets the range where a test ID is displayed, in the given URI.
4141
* Returns undefined if there's no such decoration.
4242
*/
43-
getDecoratedRangeForTest(resource: URI, testId: string): Range | undefined;
43+
getDecoratedTestPosition(resource: URI, testId: string): Position | undefined;
4444
}
4545

4646
export interface ITestDecoration {

0 commit comments

Comments
 (0)