Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export class UnsupportedLanguageError extends Error {
}
}

export class UnsupportedError extends Error {
constructor(message: string) {
super(message);
this.name = "UnsupportedError";
export class UnsupportedScopeError extends Error {
constructor(scopeType: string) {
super(
`Scope '${scopeType}' is not implemented yet; See ${DOCS_URL}/contributing/adding-a-new-scope`,
);
this.name = "UnsupportedScopeError";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ export class ContainingScopeStage implements ModifierStage {
run(target: Target): Target[] {
const { scopeType, ancestorIndex = 0 } = this.modifier;

const scopeHandler = this.scopeHandlerFactory.maybeCreate(
const scopeHandler = this.scopeHandlerFactory.create(
scopeType,
target.editor.document.languageId,
);

if (scopeHandler == null) {
throw new NoContainingScopeError(scopeType.type);
}

const containingScopes = getContainingScopeTarget(
target,
scopeHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,11 @@ export class EveryScopeStage implements ModifierStage {
const { scopeType } = this.modifier;
const { editor, isReversed } = target;

const scopeHandler = this.scopeHandlerFactory.maybeCreate(
const scopeHandler = this.scopeHandlerFactory.create(
scopeType,
editor.document.languageId,
);

if (scopeHandler == null) {
throw new NoContainingScopeError(scopeType.type);
}

let scopes: TargetScope[] | undefined;

if (target.hasExplicitRange) {
Expand Down Expand Up @@ -97,15 +93,11 @@ export class EveryScopeStage implements ModifierStage {
scopeHandlerFactory: ScopeHandlerFactory,
target: Target,
): Range[] {
const iterationScopeHandler = scopeHandlerFactory.maybeCreate(
const iterationScopeHandler = scopeHandlerFactory.create(
scopeHandler.iterationScopeType,
target.editor.document.languageId,
);

if (iterationScopeHandler == null) {
throw Error("Could not find iteration scope handler");
}

const iterationScopeTarget = getContainingScopeTarget(
target,
iterationScopeHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { pseudoScopes, type ScopeType } from "@cursorless/common";
import {
pseudoScopes,
UnsupportedScopeError,
type ScopeType,
} from "@cursorless/common";
import type { LanguageDefinitions } from "../../../languages/LanguageDefinitions";
import {
BoundedNonWhitespaceSequenceScopeHandler,
Expand Down Expand Up @@ -145,7 +149,7 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
): ScopeHandler {
const handler = this.maybeCreate(scopeType, languageId);
if (handler == null) {
throw new Error(`Couldn't create scope handler for '${scopeType.type}'`);
throw new UnsupportedScopeError(scopeType.type);
}
return handler;
}
Expand Down
Loading