Skip to content

Commit b200d8f

Browse files
committed
Add ScopeVisualizer tests
1 parent c56a29a commit b200d8f

File tree

8 files changed

+272
-8
lines changed

8 files changed

+272
-8
lines changed

packages/common/src/ide/fake/FakeIDE.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default class FakeIDE implements IDE {
4747
): Promise<void> {
4848
// empty
4949
}
50+
5051
async setScopeVisualizationRanges(
5152
_scopeRanges: EditorScopeRanges[],
5253
): Promise<void> {

packages/common/src/ide/spy/SpyIDE.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,35 @@ import { GeneralizedRange } from "../../types/GeneralizedRange";
33
import { TextEditor } from "../../types/TextEditor";
44
import PassthroughIDEBase from "../PassthroughIDEBase";
55
import { FlashDescriptor } from "../types/FlashDescriptor";
6-
import type { HighlightId, IDE } from "../types/ide.types";
6+
import type {
7+
HighlightId,
8+
IDE,
9+
EditorScopeRanges,
10+
ScopeRanges,
11+
} from "../types/ide.types";
712
import SpyMessages, { Message } from "./SpyMessages";
813

914
interface Highlight {
1015
highlightId: HighlightId | undefined;
1116
ranges: GeneralizedRange[];
1217
}
1318

19+
interface ScopeVisualization {
20+
scopeRanges: ScopeRanges[];
21+
}
22+
1423
export interface SpyIDERecordedValues {
1524
messages?: Message[];
1625
flashes?: FlashDescriptor[];
1726
highlights?: Highlight[];
27+
scopeVisualizations?: ScopeVisualization[];
1828
}
1929

2030
export default class SpyIDE extends PassthroughIDEBase {
2131
messages: SpyMessages;
2232
private flashes: FlashDescriptor[] = [];
2333
private highlights: Highlight[] = [];
34+
private scopeVisualizations: ScopeVisualization[] = [];
2435

2536
constructor(original: IDE) {
2637
super(original);
@@ -32,6 +43,10 @@ export default class SpyIDE extends PassthroughIDEBase {
3243
messages: this.messages.getSpyValues(),
3344
flashes: isFlashTest ? this.flashes : undefined,
3445
highlights: this.highlights.length === 0 ? undefined : this.highlights,
46+
scopeVisualizations:
47+
this.scopeVisualizations.length === 0
48+
? undefined
49+
: this.scopeVisualizations,
3550
};
3651

3752
return values(ret).every((value) => value == null)
@@ -55,4 +70,14 @@ export default class SpyIDE extends PassthroughIDEBase {
5570
});
5671
return super.setHighlightRanges(highlightId, editor, ranges);
5772
}
73+
74+
async setScopeVisualizationRanges(
75+
scopeRanges: EditorScopeRanges[],
76+
): Promise<void> {
77+
this.scopeVisualizations.push(
78+
...scopeRanges.map(({ scopeRanges }) => ({
79+
scopeRanges,
80+
})),
81+
);
82+
}
5883
}

packages/common/src/testUtil/runTestSubset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* configuration.
55
* See https://mochajs.org/#-grep-regexp-g-regexp for supported syntax
66
*/
7-
export const TEST_SUBSET_GREP_STRING = "snippets";
7+
export const TEST_SUBSET_GREP_STRING = "visualizer";
88

99
/**
1010
* Determine whether we should run just the subset of the tests specified by

packages/common/src/testUtil/toPlainObject.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
GeneralizedRange,
44
LineRange,
55
Message,
6+
ScopeType,
67
SpyIDERecordedValues,
78
} from "..";
89
import { FlashStyle, isLineRange } from "..";
@@ -39,10 +40,22 @@ interface PlainHighlight {
3940
ranges: GeneralizedRangePlainObject[];
4041
}
4142

43+
interface PlainScopeRanges {
44+
scopeType: ScopeType;
45+
domain: GeneralizedRangePlainObject;
46+
contentRanges?: GeneralizedRangePlainObject[];
47+
removalRanges?: GeneralizedRangePlainObject[];
48+
}
49+
50+
export interface PlainScopeVisualization {
51+
scopeRanges: PlainScopeRanges[];
52+
}
53+
4254
export interface PlainSpyIDERecordedValues {
4355
messages: Message[] | undefined;
4456
flashes: PlainFlashDescriptor[] | undefined;
4557
highlights: PlainHighlight[] | undefined;
58+
scopeVisualizations: PlainScopeVisualization[] | undefined;
4659
}
4760

4861
export type SelectionPlainObject = {
@@ -150,5 +163,17 @@ export function spyIDERecordedValuesToPlainObject(
150163
generalizedRangeToPlainObject(range),
151164
),
152165
})),
166+
scopeVisualizations: input.scopeVisualizations?.map(({ scopeRanges }) => ({
167+
scopeRanges: scopeRanges.map((scopeRange) => ({
168+
scopeType: scopeRange.scopeType,
169+
domain: generalizedRangeToPlainObject(scopeRange.domain),
170+
contentRanges: scopeRange.contentRanges?.map((range) =>
171+
generalizedRangeToPlainObject(range),
172+
),
173+
removalRanges: scopeRange.removalRanges?.map((range) =>
174+
generalizedRangeToPlainObject(range),
175+
),
176+
})),
177+
})),
153178
};
154179
}

packages/cursorless-engine/src/ScopeVisualizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ScopeVisualizer implements Disposable {
3131
// be better to have this happen in VSCode-specific impl, but that's tricky
3232
// because the VSCode impl doesn't know about the visualization type.
3333
await this.clearHighlights();
34-
this.debouncer.run();
34+
await this.highlightScopes();
3535
}
3636

3737
private disposables: Disposable[] = [];

packages/cursorless-engine/src/cursorlessEngine.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
ScopeType,
77
} from "@cursorless/common";
88
import { StoredTargetMap, TestCaseRecorder, TreeSitter } from ".";
9-
import { ScopeVisualizer as ScopeVisualizerImpl } from "./ScopeVisualizer";
109
import { VisualizationType } from "./VisualizationType";
1110
import { Debug } from "./core/Debug";
1211
import { HatTokenMapImpl } from "./core/HatTokenMapImpl";
@@ -18,6 +17,7 @@ import { ScopeHandlerFactoryImpl } from "./processTargets/modifiers/scopeHandler
1817
import { runCommand } from "./runCommand";
1918
import { runIntegrationTests } from "./runIntegrationTests";
2019
import { injectIde } from "./singletons/ide.singleton";
20+
import { ScopeVisualizer as ScopeVisualizerImpl } from "./ScopeVisualizer";
2121

2222
export function createCursorlessEngine(
2323
treeSitter: TreeSitter,
@@ -83,13 +83,13 @@ export function createCursorlessEngine(
8383
},
8484
scopeVisualizer: {
8585
start(scopeType: ScopeType, visualizationType: string) {
86-
scopeVisualizer.setScopeType({
86+
return scopeVisualizer.setScopeType({
8787
scopeType,
8888
visualizationType: visualizationType as VisualizationType,
8989
});
9090
},
9191
stop() {
92-
scopeVisualizer.setScopeType(undefined);
92+
return scopeVisualizer.setScopeType(undefined);
9393
},
9494
},
9595
testCaseRecorder,
@@ -117,8 +117,8 @@ export interface CommandApi {
117117
}
118118

119119
export interface ScopeVisualizer {
120-
start(scopeType: ScopeType, visualizationType: string): void;
121-
stop(): void;
120+
start(scopeType: ScopeType, visualizationType: string): Promise<void>;
121+
stop(): Promise<void>;
122122
}
123123

124124
export interface CursorlessEngine {

packages/cursorless-engine/src/scripts/transformRecordedTests/upgradeDecorations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const upgradeDecorations: FixtureTransformation = (
6262
range: extractHighlightRange(flash),
6363
style: extractHighlightName(flash.name) as keyof typeof FlashStyle,
6464
})),
65+
scopeVisualizations: undefined,
6566
};
6667

6768
return reorderFields(fixture as TestCaseFixture);

0 commit comments

Comments
 (0)