Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Nov 20, 2024
1 parent ed7591e commit 5a8d208
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ContainingScopeStage implements ModifierStage {
run(target: Target): Target[] {
const { scopeType, ancestorIndex = 0 } = this.modifier;

const scopeHandler = this.scopeHandlerFactory.create(
const scopeHandler = this.scopeHandlerFactory.tryCreate(
scopeType,
target.editor.document.languageId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class EveryScopeStage implements ModifierStage {
const { scopeType } = this.modifier;
const { editor, isReversed } = target;

const scopeHandler = this.scopeHandlerFactory.create(
const scopeHandler = this.scopeHandlerFactory.tryCreate(
scopeType,
editor.document.languageId,
);
Expand Down Expand Up @@ -108,7 +108,7 @@ export class EveryScopeStage implements ModifierStage {
scopeHandlerFactory: ScopeHandlerFactory,
target: Target,
): Range[] {
const iterationScopeHandler = scopeHandlerFactory.create(
const iterationScopeHandler = scopeHandlerFactory.tryCreate(
scopeHandler.iterationScopeType,
target.editor.document.languageId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class PreferredScopeStage implements ModifierStage {
}
}

const scopeHandler = this.scopeHandlerFactory.createWithAssert(
const scopeHandler = this.scopeHandlerFactory.create(
this.modifier.scopeType,
target.editor.document.languageId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class RelativeScopeStage implements ModifierStage {
) {}

run(target: Target): Target[] {
const scopeHandler = this.scopeHandlerFactory.create(
const scopeHandler = this.scopeHandlerFactory.tryCreate(
this.modifier.scopeType,
target.editor.document.languageId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ abstract class BoundedBaseScopeHandler extends BaseScopeHandler {
) {
super();

this.targetScopeHandler = this.scopeHandlerFactory.createWithAssert(
this.targetScopeHandler = this.scopeHandlerFactory.create(
this.targetScopeType,
this.languageId,
);
this.surroundingPairInteriorScopeHandler =
this.scopeHandlerFactory.createWithAssert(
{
type: "surroundingPairInterior",
delimiter: "any",
},
this.languageId,
);
this.surroundingPairInteriorScopeHandler = this.scopeHandlerFactory.create(
{
type: "surroundingPairInterior",
delimiter: "any",
},
this.languageId,
);
}

get iterationScopeType(): ScopeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export abstract class NestedScopeHandler extends BaseScopeHandler {

private get searchScopeHandler(): ScopeHandler {
if (this._searchScopeHandler == null) {
this._searchScopeHandler = this.scopeHandlerFactory.createWithAssert(
this._searchScopeHandler = this.scopeHandlerFactory.create(
this.searchScopeType,
this.languageId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ export class OneOfScopeHandler extends BaseScopeHandler {
languageId: string,
): ScopeHandler {
const scopeHandlers: ScopeHandler[] = scopeType.scopeTypes.map(
(scopeType) =>
scopeHandlerFactory.createWithAssert(scopeType, languageId),
(scopeType) => scopeHandlerFactory.create(scopeType, languageId),
);

const iterationScopeType = (): CustomScopeType => ({
type: "custom",
scopeHandler: new OneOfScopeHandler(
undefined,
scopeHandlers.map((scopeHandler) =>
scopeHandlerFactory.createWithAssert(
scopeHandlerFactory.create(
scopeHandler.iterationScopeType,
languageId,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { ScopeType } from "@cursorless/common";
import type { CustomScopeType, ScopeHandler } from "./scopeHandler.types";

export interface ScopeHandlerFactory {
create(
tryCreate(
scopeType: ScopeType | CustomScopeType,
languageId: string,
): ScopeHandler | undefined;

createWithAssert(
create(
scopeType: ScopeType | CustomScopeType,
languageId: string,
): ScopeHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ import type { CustomScopeType, ScopeHandler } from "./scopeHandler.types";
*/
export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
constructor(private languageDefinitions: LanguageDefinitions) {
this.create = this.create.bind(this);
this.tryCreate = this.tryCreate.bind(this);
}

create(
tryCreate(
scopeType: ScopeType | CustomScopeType,
languageId: string,
): ScopeHandler | undefined {
Expand Down Expand Up @@ -115,11 +115,11 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
}
}

createWithAssert(
create(
scopeType: ScopeType | CustomScopeType,
languageId: string,
): ScopeHandler {
const handler = this.create(scopeType, languageId);
const handler = this.tryCreate(scopeType, languageId);
if (handler == null) {
throw new Error(`Couldn't create scope handler for '${scopeType.type}'`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ export class SurroundingPairInteriorScopeHandler extends BaseScopeHandler {
) {
super();

this.surroundingPairScopeHandler =
this.scopeHandlerFactory.createWithAssert(
{
type: "surroundingPair",
delimiter: this.scopeType.delimiter,
requireStrongContainment: true,
},
this.languageId,
);
this.surroundingPairScopeHandler = this.scopeHandlerFactory.create(
{
type: "surroundingPair",
delimiter: this.scopeType.delimiter,
requireStrongContainment: true,
},
this.languageId,
);
}

get iterationScopeType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ScopeRangeProvider {
editor: TextEditor,
{ scopeType, visibleOnly }: ScopeRangeConfig,
): ScopeRanges[] {
const scopeHandler = this.scopeHandlerFactory.create(
const scopeHandler = this.scopeHandlerFactory.tryCreate(
scopeType,
editor.document.languageId,
);
Expand All @@ -50,13 +50,16 @@ export class ScopeRangeProvider {
{ scopeType, visibleOnly, includeNestedTargets }: IterationScopeRangeConfig,
): IterationScopeRanges[] {
const { languageId } = editor.document;
const scopeHandler = this.scopeHandlerFactory.create(scopeType, languageId);
const scopeHandler = this.scopeHandlerFactory.tryCreate(
scopeType,
languageId,
);

if (scopeHandler == null) {
return [];
}

const iterationScopeHandler = this.scopeHandlerFactory.create(
const iterationScopeHandler = this.scopeHandlerFactory.tryCreate(
scopeHandler.iterationScopeType,
languageId,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class ScopeSupportChecker {
*/
getScopeSupport(editor: TextEditor, scopeType: ScopeType): ScopeSupport {
const { languageId } = editor.document;
const scopeHandler = this.scopeHandlerFactory.create(scopeType, languageId);
const scopeHandler = this.scopeHandlerFactory.tryCreate(
scopeType,
languageId,
);

if (scopeHandler == null) {
return getLegacyScopeSupport(languageId, scopeType);
Expand All @@ -53,13 +56,16 @@ export class ScopeSupportChecker {
scopeType: ScopeType,
): ScopeSupport {
const { languageId } = editor.document;
const scopeHandler = this.scopeHandlerFactory.create(scopeType, languageId);
const scopeHandler = this.scopeHandlerFactory.tryCreate(
scopeType,
languageId,
);

if (scopeHandler == null) {
return getLegacyScopeSupport(languageId, scopeType);
}

const iterationScopeHandler = this.scopeHandlerFactory.create(
const iterationScopeHandler = this.scopeHandlerFactory.tryCreate(
scopeHandler.iterationScopeType,
languageId,
);
Expand Down

0 comments on commit 5a8d208

Please sign in to comment.