Skip to content

Commit cf862ea

Browse files
committed
more cleanup
1 parent 51f7bfc commit cf862ea

9 files changed

+60
-70
lines changed

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/VscodeFancyRangeHighlighter.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import { VscodeFancyRangeHighlighterRenderer } from "./VscodeFancyRangeHighlight
66
import { generateDecorationsForCharacterRange } from "./generateDecorationsForCharacterRange";
77
import { generateDecorationsForLineRange } from "./generateDecorationsForLineRange";
88
import { generateDifferentiatedRanges } from "./generateDifferentiatedRanges";
9-
import {
10-
DecorationStyle,
11-
DifferentiatedStyledRange,
12-
} from "./getDecorationRanges.types";
13-
import { groupDifferentiatedRanges } from "./groupDifferentiatedRanges";
9+
import { DifferentiatedStyledRange } from "./getDecorationRanges.types";
10+
import { groupDifferentiatedStyledRanges } from "./groupDifferentiatedStyledRanges";
1411

1512
/**
1613
* Manages VSCode decoration types for a highlight or flash style.
@@ -23,9 +20,7 @@ export class VscodeFancyRangeHighlighter {
2320
}
2421

2522
setRanges(editor: VscodeTextEditorImpl, ranges: GeneralizedRange[]) {
26-
const decoratedRanges: Iterable<
27-
DifferentiatedStyledRange<DecorationStyle>
28-
> = flatmap(
23+
const decoratedRanges: Iterable<DifferentiatedStyledRange> = flatmap(
2924
generateDifferentiatedRanges(ranges),
3025

3126
function* ({ range, differentiationIndex }) {
@@ -46,23 +41,10 @@ export class VscodeFancyRangeHighlighter {
4641
},
4742
);
4843

49-
this.renderer.setRanges(
50-
editor,
51-
groupDifferentiatedRanges(decoratedRanges, getStyleKey),
52-
);
44+
this.renderer.setRanges(editor, groupDifferentiatedStyledRanges(decoratedRanges));
5345
}
5446

5547
dispose() {
5648
this.renderer.dispose();
5749
}
5850
}
59-
60-
function getStyleKey({
61-
top,
62-
right,
63-
left,
64-
bottom,
65-
isWholeLine,
66-
}: DecorationStyle) {
67-
return [top, right, left, bottom, isWholeLine ?? false];
68-
}

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/VscodeFancyRangeHighlighterRenderer.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
export class VscodeFancyRangeHighlighterRenderer {
1919
private decorationTypes: CompositeKeyDefaultMap<
20-
DifferentiatedStyle<DecorationStyle>,
20+
DifferentiatedStyle,
2121
TextEditorDecorationType
2222
>;
2323

@@ -40,7 +40,7 @@ export class VscodeFancyRangeHighlighterRenderer {
4040

4141
setRanges(
4242
editor: VscodeTextEditorImpl,
43-
decoratedRanges: DifferentiatedStyledRangeList<DecorationStyle>[],
43+
decoratedRanges: DifferentiatedStyledRangeList[],
4444
) {
4545
const untouchedDecorationTypes = new Set(this.decorationTypes.values());
4646

@@ -50,16 +50,18 @@ export class VscodeFancyRangeHighlighterRenderer {
5050
b.differentiatedStyles.differentiationIndex,
5151
);
5252

53-
decoratedRanges.forEach(({ differentiatedStyles: styleParameters, ranges }) => {
54-
const decorationType = this.decorationTypes.get(styleParameters);
53+
decoratedRanges.forEach(
54+
({ differentiatedStyles: styleParameters, ranges }) => {
55+
const decorationType = this.decorationTypes.get(styleParameters);
5556

56-
editor.vscodeEditor.setDecorations(
57-
decorationType,
58-
ranges.map(toVscodeRange),
59-
);
57+
editor.vscodeEditor.setDecorations(
58+
decorationType,
59+
ranges.map(toVscodeRange),
60+
);
6061

61-
untouchedDecorationTypes.delete(decorationType);
62-
});
62+
untouchedDecorationTypes.delete(decorationType);
63+
},
64+
);
6365

6466
untouchedDecorationTypes.forEach((decorationType) => {
6567
editor.vscodeEditor.setDecorations(decorationType, []);

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/generateDecorationsForCharacterRange.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Range, TextEditor } from "@cursorless/common";
22
import { range } from "lodash";
3-
import { BorderStyle, DecoratedRange } from "./getDecorationRanges.types";
3+
import { BorderStyle, StyledRange } from "./getDecorationRanges.types";
44
import { handleMultipleLines } from "./handleMultipleLines";
55

66
export function* generateDecorationsForCharacterRange(
77
editor: TextEditor,
88
characterRange: Range,
9-
): Iterable<DecoratedRange> {
9+
): Iterable<StyledRange> {
1010
if (characterRange.isSingleLine) {
1111
yield {
1212
range: characterRange,

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/generateDecorationsForLineRange.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Range } from "@cursorless/common";
2-
import { BorderStyle, DecoratedRange } from "./getDecorationRanges.types";
2+
import { BorderStyle, StyledRange } from "./getDecorationRanges.types";
33

44
export function* generateDecorationsForLineRange(
55
startLine: number,
66
endLine: number,
7-
): Iterable<DecoratedRange> {
7+
): Iterable<StyledRange> {
88
const lineCount = endLine - startLine + 1;
99

1010
if (lineCount === 1) {

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/generateDifferentiatedRanges.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
} from "@cursorless/common";
66

77
import { max } from "lodash";
8-
import { DifferentiatedRange } from "./getDecorationRanges.types";
8+
import { DifferentiatedGeneralizedRange } from "./getDecorationRanges.types";
99

1010
export function* generateDifferentiatedRanges(
1111
ranges: GeneralizedRange[],
12-
): Iterable<DifferentiatedRange> {
12+
): Iterable<DifferentiatedGeneralizedRange> {
1313
ranges.sort(compareGeneralizedRangesByStart);
1414

15-
let currentRanges: DifferentiatedRange[] = [];
15+
let currentRanges: DifferentiatedGeneralizedRange[] = [];
1616

1717
for (const range of ranges) {
1818
currentRanges = [
@@ -25,7 +25,7 @@ export function* generateDifferentiatedRanges(
2525
const differentiatedRange = {
2626
range,
2727
differentiationIndex: getDifferentiationIndex(currentRanges, range),
28-
} as DifferentiatedRange;
28+
} as DifferentiatedGeneralizedRange;
2929

3030
yield differentiatedRange;
3131

@@ -34,7 +34,7 @@ export function* generateDifferentiatedRanges(
3434
}
3535

3636
function getDifferentiationIndex(
37-
currentRanges: DifferentiatedRange[],
37+
currentRanges: DifferentiatedGeneralizedRange[],
3838
range: GeneralizedRange,
3939
): number {
4040
const maxContainingDifferentiationIndex = max(

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/getDecorationRanges.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import assert = require("assert");
22
import { getDecorationRanges } from "./getDecorationRanges";
3-
import { DecorationStyle, DifferentiatedStyle } from "./getDecorationRanges.types";
3+
import {
4+
DecorationStyle,
5+
DifferentiatedStyle,
6+
} from "./getDecorationRanges.types";
47
import {
58
Range,
69
RangePlainObject,

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/getDecorationRanges.types.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@ export interface DecorationStyle {
1919
isWholeLine?: boolean;
2020
}
2121

22-
export interface StyledRange<T> {
23-
style: T;
24-
range: Range;
22+
export interface DifferentiatedStyle {
23+
style: DecorationStyle;
24+
differentiationIndex: number;
2525
}
2626

27-
export type DecoratedRange = StyledRange<DecorationStyle>;
28-
29-
export interface DifferentiatedStyle<T> {
30-
style: T;
31-
differentiationIndex: number;
27+
export interface StyledRange {
28+
style: DecorationStyle;
29+
range: Range;
3230
}
3331

34-
export interface DifferentiatedStyledRange<T> {
35-
differentiatedStyle: DifferentiatedStyle<T>;
32+
export interface DifferentiatedStyledRange {
33+
differentiatedStyle: DifferentiatedStyle;
3634
range: Range;
3735
}
3836

39-
export interface DifferentiatedStyledRangeList<T> {
40-
differentiatedStyles: DifferentiatedStyle<T>;
37+
export interface DifferentiatedStyledRangeList {
38+
differentiatedStyles: DifferentiatedStyle;
4139
ranges: Range[];
4240
}
4341

44-
export interface DifferentiatedRange {
42+
export interface DifferentiatedGeneralizedRange {
4543
range: GeneralizedRange;
4644
differentiationIndex: number;
4745
}
4846

49-
export interface DifferentiatedCharacterRange extends DifferentiatedRange {
47+
export interface DifferentiatedCharacterRange
48+
extends DifferentiatedGeneralizedRange {
5049
range: CharacterRange;
5150
}
5251

53-
export interface DifferentiatedLineRange extends DifferentiatedRange {
52+
export interface DifferentiatedLineRange
53+
extends DifferentiatedGeneralizedRange {
5454
range: LineRange;
5555
}
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ import {
55
DifferentiatedStyledRange,
66
} from "./getDecorationRanges.types";
77

8-
export function groupDifferentiatedRanges<T>(
9-
decoratedRanges: Iterable<DifferentiatedStyledRange<T>>,
10-
getKeyList: (style: T) => unknown[],
11-
): DifferentiatedStyledRangeList<T>[] {
8+
export function groupDifferentiatedStyledRanges(
9+
decoratedRanges: Iterable<DifferentiatedStyledRange>,
10+
): DifferentiatedStyledRangeList[] {
1211
const decorations: CompositeKeyDefaultMap<
13-
DifferentiatedStyle<T>,
14-
DifferentiatedStyledRangeList<T>
12+
DifferentiatedStyle,
13+
DifferentiatedStyledRangeList
1514
> = new CompositeKeyDefaultMap(
1615
(differentiatedStyles) => ({ differentiatedStyles, ranges: [] }),
17-
({ style, differentiationIndex }) => [
18-
...getKeyList(style),
19-
differentiationIndex,
20-
],
16+
getStyleKey,
2117
);
2218

2319
for (const { range, differentiatedStyle } of decoratedRanges) {
@@ -26,3 +22,10 @@ export function groupDifferentiatedRanges<T>(
2622

2723
return Array.from(decorations.values());
2824
}
25+
26+
function getStyleKey({
27+
style: { top, right, left, bottom, isWholeLine },
28+
differentiationIndex,
29+
}: DifferentiatedStyle) {
30+
return [top, right, left, bottom, isWholeLine ?? false, differentiationIndex];
31+
}

packages/cursorless-vscode/src/ide/vscode/VSCodeScopeVisualizer/VscodeFancyRangeHighlighter/handleMultipleLines.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { Range } from "@cursorless/common";
22
import {
33
BorderStyle,
44
DecorationStyle,
5-
DecoratedRange,
5+
StyledRange,
66
} from "./getDecorationRanges.types";
77
import { flatmap } from "itertools";
88

99
export function* handleMultipleLines(
1010
lineRanges: Range[],
11-
): Iterable<DecoratedRange> {
11+
): Iterable<StyledRange> {
1212
yield* flatmap(generateLineGroupings(lineRanges), handleLine);
1313
}
1414

@@ -71,7 +71,7 @@ function* handleLine({
7171
previousLine,
7272
currentLine,
7373
nextLine,
74-
}: LineGrouping): Iterable<DecoratedRange> {
74+
}: LineGrouping): Iterable<StyledRange> {
7575
const events: Event[] = [
7676
...(previousLine == null
7777
? []

0 commit comments

Comments
 (0)