Skip to content

Commit b8565a7

Browse files
More cleanup
1 parent 0fb7d86 commit b8565a7

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/FallbackScopeHandler.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,11 @@ export class FallbackScopeHandler extends BaseScopeHandler {
2424
);
2525
}
2626

27-
static create(
28-
scopeHandlerFactory: ScopeHandlerFactory,
29-
scopeType: FallbackScopeType,
30-
languageId: string,
31-
): ScopeHandler {
32-
const scopeHandlers: ScopeHandler[] = scopeType.scopeTypes.map(
33-
(scopeType) => scopeHandlerFactory.create(scopeType, languageId),
34-
);
35-
36-
return this.createFromScopeHandlers(scopeHandlers);
37-
}
38-
39-
static createFromScopeHandlers(scopeHandlers: ScopeHandler[]): ScopeHandler {
40-
return new FallbackScopeHandler(scopeHandlers);
41-
}
42-
43-
private constructor(private scopeHandlers: ScopeHandler[]) {
27+
constructor(
28+
public scopeHandlerFactory: ScopeHandlerFactory,
29+
private fallbackScopeType: FallbackScopeType,
30+
private languageId: string,
31+
) {
4432
super();
4533
}
4634

@@ -50,7 +38,12 @@ export class FallbackScopeHandler extends BaseScopeHandler {
5038
direction: Direction,
5139
hints: ScopeIteratorRequirements,
5240
): Iterable<TargetScope> {
53-
for (const scopeHandler of this.scopeHandlers) {
41+
const scopeHandlers: ScopeHandler[] = this.fallbackScopeType.scopeTypes.map(
42+
(scopeType) =>
43+
this.scopeHandlerFactory.create(scopeType, this.languageId),
44+
);
45+
46+
for (const scopeHandler of scopeHandlers) {
5447
yield* scopeHandler.generateScopes(editor, position, direction, hints);
5548
}
5649
}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/ScopeHandlerFactoryImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
132132
case "oneOf":
133133
return OneOfScopeHandler.create(this, scopeType, languageId);
134134
case "fallback":
135-
return FallbackScopeHandler.create(this, scopeType, languageId);
135+
return new FallbackScopeHandler(this, scopeType, languageId);
136136
case "conditional":
137137
return new ConditionalScopeHandler(this, scopeType, languageId);
138138
case "instance":

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
NoContainingScopeError,
23
Range,
34
type Direction,
45
type InteriorScopeType,
@@ -8,7 +9,6 @@ import {
89
} from "@cursorless/common";
910
import type { LanguageDefinitions } from "../../../../languages/LanguageDefinitions";
1011
import { BaseScopeHandler } from "../BaseScopeHandler";
11-
import { FallbackScopeHandler } from "../FallbackScopeHandler";
1212
import { OneOfScopeHandler } from "../OneOfScopeHandler";
1313
import type { TargetScope } from "../scope.types";
1414
import type {
@@ -20,10 +20,10 @@ import type { ScopeHandlerFactory } from "../ScopeHandlerFactory";
2020

2121
export class InteriorScopeHandler extends BaseScopeHandler {
2222
protected isHierarchical = true;
23-
private scopeHandler: ScopeHandler;
23+
private scopeHandler: ScopeHandler | undefined;
2424

2525
get iterationScopeType(): ScopeType | ComplexScopeType {
26-
return this.scopeHandler.iterationScopeType;
26+
throw new NoContainingScopeError("Iteration scope for interior");
2727
}
2828

2929
constructor(
@@ -45,7 +45,7 @@ export class InteriorScopeHandler extends BaseScopeHandler {
4545
// yield the interior of the `<div>` pair.
4646
if (scopeType.explicitScopeType) {
4747
if (languageScopeHandler == null) {
48-
return FallbackScopeHandler.createFromScopeHandlers([]);
48+
return undefined;
4949
}
5050
return languageScopeHandler;
5151
}
@@ -84,6 +84,10 @@ export class InteriorScopeHandler extends BaseScopeHandler {
8484
direction: Direction,
8585
hints: ScopeIteratorRequirements,
8686
): Iterable<TargetScope> {
87+
if (this.scopeHandler == null) {
88+
return;
89+
}
90+
8791
const scopes = this.scopeHandler.generateScopes(
8892
editor,
8993
position,

0 commit comments

Comments
 (0)