Skip to content

Commit 0a591a6

Browse files
Added complex modifier type
1 parent f4a966a commit 0a591a6

15 files changed

Lines changed: 46 additions & 49 deletions

packages/lib-engine/src/generateSpokenForm/primitiveTargetToSpokenForm.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export class PrimitiveTargetSpokenFormGenerator {
226226

227227
handleScopeType(scopeType: ScopeType): SpokenFormComponent {
228228
switch (scopeType.type) {
229-
case "oneOf":
230229
case "surroundingPairInterior":
231230
throw new NoSpokenFormError(`Scope type '${scopeType.type}'`);
232231
case "glyph":
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Modifier } from "@cursorless/lib-common";
22
import type { ModifierStage } from "./PipelineStages.types";
3+
import type { ComplexModifier } from "./modifiers/modifier.types";
34

45
export interface ModifierStageFactory {
5-
create(modifier: Modifier): ModifierStage;
6+
create(modifier: Modifier | ComplexModifier): ModifierStage;
67
}

packages/lib-engine/src/processTargets/ModifierStageFactoryImpl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { RangeModifierStage } from "./modifiers/RangeModifierStage";
2424
import { RawSelectionStage } from "./modifiers/RawSelectionStage";
2525
import { RelativeScopeStage } from "./modifiers/RelativeScopeStage";
2626
import { VisibleStage } from "./modifiers/VisibleStage";
27+
import type { ComplexModifier } from "./modifiers/modifier.types";
2728
import type { ScopeHandlerFactory } from "./modifiers/scopeHandlers/ScopeHandlerFactory";
2829

2930
export class ModifierStageFactoryImpl implements ModifierStageFactory {
@@ -35,7 +36,7 @@ export class ModifierStageFactoryImpl implements ModifierStageFactory {
3536
this.create = this.create.bind(this);
3637
}
3738

38-
create(modifier: Modifier): ModifierStage {
39+
create(modifier: Modifier | ComplexModifier): ModifierStage {
3940
switch (modifier.type) {
4041
case "startOf":
4142
return new StartOfStage();
@@ -62,11 +63,10 @@ export class ModifierStageFactoryImpl implements ModifierStageFactory {
6263
if (ClassFunctionNameStage.use(modifier.scopeType)) {
6364
return new ClassFunctionNameStage(this, modifier);
6465
}
65-
return new ContainingScopeStage(
66-
this,
67-
this.scopeHandlerFactory,
68-
modifier,
69-
);
66+
return new ContainingScopeStage(this.scopeHandlerFactory, modifier);
67+
68+
case "complexContainingScope":
69+
return new ContainingScopeStage(this.scopeHandlerFactory, modifier);
7070

7171
case "preferredScope":
7272
if (ClassFunctionNameStage.use(modifier.scopeType)) {

packages/lib-engine/src/processTargets/modifiers/ContainingScopeStage.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ContainingScopeModifier } from "@cursorless/lib-common";
22
import { NoContainingScopeError } from "@cursorless/lib-common";
33
import type { Target } from "../../typings/target.types";
4-
import type { ModifierStageFactory } from "../ModifierStageFactory";
54
import type { ModifierStage } from "../PipelineStages.types";
65
import { getContainingScopeTarget } from "./getContainingScopeTarget";
6+
import type { ComplexContainingScopeModifier } from "./modifier.types";
77
import type { ScopeHandlerFactory } from "./scopeHandlers/ScopeHandlerFactory";
88

99
/**
@@ -26,9 +26,8 @@ import type { ScopeHandlerFactory } from "./scopeHandlers/ScopeHandlerFactory";
2626
*/
2727
export class ContainingScopeStage implements ModifierStage {
2828
constructor(
29-
private modifierStageFactory: ModifierStageFactory,
3029
private scopeHandlerFactory: ScopeHandlerFactory,
31-
private modifier: ContainingScopeModifier,
30+
private modifier: ContainingScopeModifier | ComplexContainingScopeModifier,
3231
) {}
3332

3433
run(target: Target): Target[] {

packages/lib-engine/src/processTargets/modifiers/HeadTailStage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class BoundedLineStage implements ModifierStage {
101101
try {
102102
return this.modifierStageFactory
103103
.create({
104-
type: "containingScope",
104+
type: "complexContainingScope",
105105
scopeType: compoundInteriorScopeType,
106106
})
107107
.run(target, options)[0];

packages/lib-engine/src/processTargets/modifiers/InteriorStage.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { InteriorOnlyModifier, ScopeType } from "@cursorless/lib-common";
1+
import type { InteriorOnlyModifier } from "@cursorless/lib-common";
22
import {
33
NoContainingScopeError,
44
UnsupportedScopeError,
@@ -9,6 +9,7 @@ import type {
99
ModifierStage,
1010
ModifierStateOptions,
1111
} from "../PipelineStages.types";
12+
import type { SortedScopeType } from "./scopeHandlers/scopeHandler.types";
1213

1314
export class InteriorOnlyStage implements ModifierStage {
1415
constructor(
@@ -56,7 +57,7 @@ export class InteriorOnlyStage implements ModifierStage {
5657
try {
5758
return this.modifierStageFactory
5859
.create({
59-
type: "containingScope",
60+
type: "complexContainingScope",
6061
scopeType: compoundInteriorScopeType,
6162
})
6263
.run(target, options);
@@ -69,8 +70,8 @@ export class InteriorOnlyStage implements ModifierStage {
6970
}
7071
}
7172

72-
export const compoundInteriorScopeType: ScopeType = {
73-
type: "oneOf",
73+
export const compoundInteriorScopeType: SortedScopeType = {
74+
type: "sorted",
7475
scopeTypes: [
7576
{
7677
type: "interior",

packages/lib-engine/src/processTargets/modifiers/PreferredScopeStage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class PreferredScopeStage implements ModifierStage {
2424
const { scopeType } = this.modifier;
2525

2626
const containingScopeStage = new ContainingScopeStage(
27-
this.modifierStageFactory,
2827
this.scopeHandlerFactory,
2928
{ type: "containingScope", scopeType },
3029
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { ScopeType } from "packages/lib-common/src";
2+
import type { ComplexScopeType } from "./scopeHandlers/scopeHandler.types";
3+
4+
export interface ComplexContainingScopeModifier {
5+
type: "complexContainingScope";
6+
scopeType: ScopeType | ComplexScopeType;
7+
ancestorIndex?: number;
8+
}
9+
10+
export type ComplexModifier = ComplexContainingScopeModifier;

packages/lib-engine/src/processTargets/modifiers/scopeHandlers/BoundedScopeHandler.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { BaseScopeHandler } from "./BaseScopeHandler";
1515
import { compareTargetScopes } from "./compareTargetScopes";
1616
import type { TargetScope } from "./scope.types";
1717
import type {
18+
ComplexScopeType,
1819
ScopeHandler,
1920
ScopeIteratorRequirements,
2021
} from "./scopeHandler.types";
@@ -46,17 +47,9 @@ abstract class BoundedBaseScopeHandler extends BaseScopeHandler {
4647
);
4748
}
4849

49-
get iterationScopeType(): ScopeType {
50-
switch (this.targetScopeHandler.iterationScopeType.type) {
51-
case "custom":
52-
case "fallback":
53-
case "conditional":
54-
throw Error(
55-
`Iteration scope type can't be '${this.targetScopeHandler.iterationScopeType.type}' for BoundedBaseScopeHandler`,
56-
);
57-
}
50+
get iterationScopeType(): ComplexScopeType {
5851
return {
59-
type: "oneOf",
52+
type: "sorted",
6053
scopeTypes: [
6154
this.targetScopeHandler.iterationScopeType,
6255
{

packages/lib-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/CollectionItemScopeHandler.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ export class CollectionItemScopeHandler extends BaseScopeHandler {
4646
return textualScopeHandler;
4747
}
4848

49-
return SortedScopeHandler.createFromScopeHandlers(
50-
scopeHandlerFactory,
51-
languageId,
52-
[languageScopeHandler, textualScopeHandler],
53-
);
49+
return SortedScopeHandler.createFromScopeHandlers([
50+
languageScopeHandler,
51+
textualScopeHandler,
52+
]);
5453
})();
5554
}
5655

0 commit comments

Comments
 (0)