Skip to content

Commit

Permalink
Remove more cyclic import dependencies (#2076)
Browse files Browse the repository at this point in the history
* Changes many imports from index files to direct source.
* Removes cycle from notebook.ts and notebookLegacy.ts.
* Moves processTargets/targetUtil to processTargets/targets/util so that
those files can import from direct source without breaking the barrel
boundary.
* Moves tryConstructPlainTarget and tryConstructLineTarget to
PlainTarget and LineTarget, respectively.

The Position/Range/Selection cycle is not touched. There are still some
other cycles remaining as well, but this gets a lot of them.

---------

Co-authored-by: Barry Jaspan <[email protected]>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Pokey Rule <[email protected]>
  • Loading branch information
4 people authored Dec 1, 2023
1 parent 4a22005 commit 420973a
Show file tree
Hide file tree
Showing 41 changed files with 156 additions and 152 deletions.
9 changes: 7 additions & 2 deletions packages/common/src/util/toPlainObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { CharacterRange, GeneralizedRange, LineRange } from "..";
import { FlashStyle, isLineRange } from "..";
import type {
CharacterRange,
GeneralizedRange,
LineRange,
} from "../types/GeneralizedRange";
import { isLineRange } from "../types/GeneralizedRange";
import { FlashStyle } from "../ide/types/FlashDescriptor";
import { Token } from "../types/Token";
import { Selection } from "../types/Selection";

Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/actions/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TreeSitter } from "..";
import { TreeSitter } from "../typings/TreeSitter";
import { Snippets } from "../core/Snippets";
import { RangeUpdater } from "../core/updateSelections/RangeUpdater";
import { ModifierStageFactory } from "../processTargets/ModifierStageFactory";
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/actions/ShowParseTree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FlashStyle, Range, TextDocument } from "@cursorless/common";
import * as path from "node:path";
import type { Tree, TreeCursor } from "web-tree-sitter";
import type { TreeSitter } from "..";
import type { TreeSitter } from "../typings/TreeSitter";
import { ide } from "../singletons/ide.singleton";
import type { Target } from "../typings/target.types";
import { flashTargets } from "../util/targetUtils";
Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
IDE,
ScopeProvider,
} from "@cursorless/common";
import { StoredTargetMap, TreeSitter } from ".";
import { StoredTargetMap } from "./core/StoredTargets";
import { TreeSitter } from "./typings/TreeSitter";
import {
CommandRunnerDecorator,
CursorlessEngine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
Listener,
ScopeType,
} from "@cursorless/common";
import { SpokenFormGenerator } from ".";
import { CustomSpokenFormGenerator } from "..";
import { SpokenFormGenerator } from "./generateSpokenForm";
import { CustomSpokenFormGenerator } from "../api/CursorlessEngineApi";
import { CustomSpokenForms } from "../spokenForms/CustomSpokenForms";
import { TalonSpokenForms } from "../scopeProviders/TalonSpokenForms";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@cursorless/common";
import { join } from "path";
import { SyntaxNode } from "web-tree-sitter";
import { TreeSitter } from "..";
import { TreeSitter } from "../typings/TreeSitter";
import { ide } from "../singletons/ide.singleton";
import { LanguageDefinition } from "./LanguageDefinition";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Modifier,
SurroundingPairModifier,
} from "@cursorless/common";
import { StoredTargetMap } from "..";
import { StoredTargetMap } from "../core/StoredTargets";
import { LanguageDefinitions } from "../languages/LanguageDefinitions";
import { ModifierStageFactory } from "./ModifierStageFactory";
import { ModifierStage } from "./PipelineStages.types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isSameType } from "../util/typeUtils";
import {
createContinuousLineRange,
createContinuousRange,
} from "./targetUtil/createContinuousRange";
} from "./targets/util/createContinuousRange";
import { LineTarget, UntypedTarget } from "./targets";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TargetPipelineRunner } from "..";
import { TargetPipelineRunner } from "../TargetPipelineRunner";
import { TargetMark } from "../../typings/TargetDescriptor";
import { Target } from "../../typings/target.types";
import { MarkStage } from "../PipelineStages.types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Direction, ScopeType } from "@cursorless/common";
import { imap } from "itertools";
import { NestedScopeHandler } from ".";
import { NestedScopeHandler } from "./NestedScopeHandler";
import { getMatcher } from "../../../tokenizer";
import { generateMatchesInRange } from "../../../util/getMatchesInRange";
import { PlainTarget } from "../../targets";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { imap } from "itertools";
import { NestedScopeHandler } from ".";
import { NestedScopeHandler } from "./NestedScopeHandler";
import { getMatcher } from "../../../tokenizer";
import { Direction } from "@cursorless/common";
import { generateMatchesInRange } from "../../../util/getMatchesInRange";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CustomRegexScopeType, Direction, ScopeType } from "@cursorless/common";
import { imap } from "itertools";
import { NestedScopeHandler, ScopeHandlerFactory } from ".";
import { NestedScopeHandler } from "./NestedScopeHandler";
import { ScopeHandlerFactory } from "./ScopeHandlerFactory";
import { generateMatchesInRange } from "../../../util/getMatchesInRange";
import { TokenTarget } from "../../targets";
import { TargetScope } from "./scope.types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import type { ScopeType } from "@cursorless/common";
import {
CharacterScopeHandler,
CustomRegexScopeHandler,
DocumentScopeHandler,
IdentifierScopeHandler,
LineScopeHandler,
NonWhitespaceSequenceScopeHandler,
OneOfScopeHandler,
ParagraphScopeHandler,
ScopeHandlerFactory,
SentenceScopeHandler,
TokenScopeHandler,
UrlScopeHandler,
WordScopeHandler,
} from ".";
import { CharacterScopeHandler } from "./CharacterScopeHandler";
import { CustomRegexScopeHandler } from "./RegexScopeHandler";
import { DocumentScopeHandler } from "./DocumentScopeHandler";
import { IdentifierScopeHandler } from "./IdentifierScopeHandler";
import { LineScopeHandler } from "./LineScopeHandler";
import { NonWhitespaceSequenceScopeHandler } from "./RegexScopeHandler";
import { OneOfScopeHandler } from "./OneOfScopeHandler";
import { ParagraphScopeHandler } from "./ParagraphScopeHandler";
import { ScopeHandlerFactory } from "./ScopeHandlerFactory";
import { SentenceScopeHandler } from "./SentenceScopeHandler/SentenceScopeHandler";
import { TokenScopeHandler } from "./TokenScopeHandler";
import { UrlScopeHandler } from "./RegexScopeHandler";
import { WordScopeHandler } from "./WordScopeHandler/WordScopeHandler";
import { LanguageDefinitions } from "../../../languages/LanguageDefinitions";
import type { CustomScopeType, ScopeHandler } from "./scopeHandler.types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Direction, Range } from "@cursorless/common";
import { imap } from "itertools";
import { NestedScopeHandler } from "..";
import { NestedScopeHandler } from "../NestedScopeHandler";
import { TokenTarget } from "../../../targets";
import type { TargetScope } from "../scope.types";
import { SentenceSegmenter } from "./SentenceSegmenter";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Direction } from "@cursorless/common";
import { imap } from "itertools";
import { NestedScopeHandler } from ".";
import { NestedScopeHandler } from "./NestedScopeHandler";
import { getMatcher } from "../../../tokenizer";
import { generateMatchesInRange } from "../../../util/getMatchesInRange";
import { TokenTarget } from "../../targets";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Range, TextEditor } from "@cursorless/common";
import { NestedScopeHandler } from "..";
import { NestedScopeHandler } from "../NestedScopeHandler";
import { WordTokenizer } from "./WordTokenizer";
import { Direction } from "@cursorless/common";
import { SubTokenWordTarget } from "../../../targets";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { isEqual } from "lodash";
import type { EditWithRangeUpdater } from "../../typings/Types";
import type { Destination, Target } from "../../typings/target.types";
import { DestinationImpl } from "./DestinationImpl";
import { createContinuousRange } from "../targetUtil/createContinuousRange";
import { createContinuousRange } from "./util/createContinuousRange";

/** Parameters supported by all target classes */
export interface MinimumTargetParameters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Range } from "@cursorless/common";
import { shrinkRangeToFitContent } from "../../util/selectionUtils";
import { BaseTarget, CommonTargetParameters, PlainTarget } from "./";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { PlainTarget } from "./PlainTarget";

export class DocumentTarget extends BaseTarget<CommonTargetParameters> {
type = "DocumentTarget";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseTarget, CommonTargetParameters } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";

/**
* A target that was not explicitly spoken by the user. For example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Range } from "@cursorless/common";
import { BaseTarget, MinimumTargetParameters } from ".";
import { BaseTarget, MinimumTargetParameters } from "./BaseTarget";
import { shrinkRangeToFitContent } from "../../util/selectionUtils";
import { createContinuousRangeFromRanges } from "../targetUtil/createContinuousRange";
import { createContinuousRangeFromRanges } from "./util/createContinuousRange";

export interface InteriorTargetParameters extends MinimumTargetParameters {
readonly fullInteriorRange: Range;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Position, Range, TextEditor } from "@cursorless/common";
import { BaseTarget, CommonTargetParameters } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { expandToFullLine } from "../../util/rangeUtils";
import { tryConstructPlainTarget } from "../../util/tryConstructTarget";
import { createContinuousLineRange } from "../targetUtil/createContinuousRange";
import { tryConstructPlainTarget } from "./PlainTarget";
import { createContinuousLineRange } from "./util/createContinuousRange";
import { tryConstructTarget } from "../../util/tryConstructTarget";

export class LineTarget extends BaseTarget<CommonTargetParameters> {
type = "LineTarget";
Expand Down Expand Up @@ -70,3 +71,21 @@ function getTrailingDelimiterRange(editor: TextEditor, range: Range) {
? new Range(range.end, new Position(end.line + 1, 0))
: undefined;
}

/**
* Constructs a {@link LineTarget} from the given range, or returns undefined
* if the range is undefined
* @param editor The editor containing the range
* @param range The range to convert into a target
* @param isReversed Whether the rain should be backward
* @returns A new {@link LineTarget} constructed from the given range, or null
* if the range is undefined
*/

export function constructLineTarget(
editor: TextEditor,
range: Range | undefined,
isReversed: boolean,
): LineTarget | undefined {
return tryConstructTarget(LineTarget, editor, range, isReversed);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InsertionMode } from "@cursorless/common";
import { BaseTarget, CommonTargetParameters } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { Destination } from "../../typings/target.types";
import { NotebookCellDestination } from "./NotebookCellDestination";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {
TextEditor,
TextLine,
} from "@cursorless/common";
import { BaseTarget, CommonTargetParameters, LineTarget } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { LineTarget } from "./LineTarget";
import { expandToFullLine } from "../../util/rangeUtils";
import { constructLineTarget } from "../../util/tryConstructTarget";
import { createContinuousLineRange } from "../targetUtil/createContinuousRange";
import { constructLineTarget } from "./LineTarget";
import { createContinuousLineRange } from "./util/createContinuousRange";

export class ParagraphTarget extends BaseTarget<CommonTargetParameters> {
type = "ParagraphTarget";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { BaseTarget, CommonTargetParameters } from ".";
import { tryConstructTarget } from "../../util/tryConstructTarget";
import { TextEditor, Range } from "@cursorless/common";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";

interface PlainTargetParameters extends CommonTargetParameters {
readonly isToken?: boolean;
Expand Down Expand Up @@ -32,3 +34,20 @@ export class PlainTarget extends BaseTarget<PlainTargetParameters> {
};
}
}

/**
* Constructs a {@link PlainTarget} from the given range, or returns undefined
* if the range is undefined
* @param editor The editor containing the range
* @param range The range to convert into a target
* @param isReversed Whether the rain should be backward
* @returns A new {@link PlainTarget} constructed from the given range, or null
* if the range is undefined
*/
export function tryConstructPlainTarget(
editor: TextEditor,
range: Range | undefined,
isReversed: boolean,
): PlainTarget | undefined {
return tryConstructTarget(PlainTarget, editor, range, isReversed);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseTarget, CommonTargetParameters } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";

/**
* A target that has no leading or trailing delimiters so it's removal range
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { Range, SimpleScopeTypeType } from "@cursorless/common";
import {
BaseTarget,
CommonTargetParameters,
InteriorTarget,
PlainTarget,
} from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { InteriorTarget } from "./InteriorTarget";
import { PlainTarget } from "./PlainTarget";
import { Target } from "../../typings/target.types";
import {
createContinuousRange,
createContinuousRangeFromRanges,
} from "../targetUtil/createContinuousRange";
import { getDelimitedSequenceRemovalRange } from "../targetUtil/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior";
} from "./util/createContinuousRange";
import { getDelimitedSequenceRemovalRange } from "./util/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior";
import {
getTokenLeadingDelimiterTarget,
getTokenRemovalRange,
getTokenTrailingDelimiterTarget,
} from "../targetUtil/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";
} from "./util/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";

export interface ScopeTypeTargetParameters extends CommonTargetParameters {
readonly scopeTypeType: SimpleScopeTypeType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Range } from "@cursorless/common";
import { BaseTarget, CommonTargetParameters } from ".";
import { tryConstructPlainTarget } from "../../util/tryConstructTarget";
import { createContinuousRange } from "../targetUtil/createContinuousRange";
import { getDelimitedSequenceRemovalRange } from "../targetUtil/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { tryConstructPlainTarget } from "./PlainTarget";
import { createContinuousRange } from "./util/createContinuousRange";
import { getDelimitedSequenceRemovalRange } from "./util/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior";

export interface SubTokenTargetParameters extends CommonTargetParameters {
readonly insertionDelimiter: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Range } from "@cursorless/common";
import {
BaseTarget,
CommonTargetParameters,
InteriorTarget,
TokenTarget,
} from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { InteriorTarget } from "./InteriorTarget";
import { TokenTarget } from "./TokenTarget";
import { Target } from "../../typings/target.types";
import {
getTokenLeadingDelimiterTarget,
getTokenRemovalRange,
getTokenTrailingDelimiterTarget,
} from "../targetUtil/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";
} from "./util/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";

interface SurroundingPairTargetParameters extends CommonTargetParameters {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Range } from "@cursorless/common";
import { BaseTarget, CommonTargetParameters } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import { Target } from "../../typings/target.types";
import {
getTokenLeadingDelimiterTarget,
getTokenRemovalRange,
getTokenTrailingDelimiterTarget,
} from "../targetUtil/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";
} from "./util/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";

export class TokenTarget extends BaseTarget<CommonTargetParameters> {
type = "TokenTarget";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Range } from "@cursorless/common";
import { BaseTarget, CommonTargetParameters } from ".";
import { BaseTarget, CommonTargetParameters } from "./BaseTarget";
import type { Target } from "../../typings/target.types";
import {
getTokenLeadingDelimiterTarget,
getTokenRemovalRange,
getTokenTrailingDelimiterTarget,
} from "../targetUtil/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";
} from "./util/insertionRemovalBehaviors/TokenInsertionRemovalBehavior";

interface UntypedTargetParameters extends CommonTargetParameters {
readonly hasExplicitRange: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Position, Range } from "@cursorless/common";
import type { Target } from "../../typings/target.types";
import type { Target } from "../../../typings/target.types";

export function createContinuousRange(
startTarget: Target,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Range } from "@cursorless/common";
import { Target } from "../../../typings/target.types";
import { Target } from "../../../../typings/target.types";

/**
* Constructs a removal range for the given target that includes either the
Expand Down
Loading

0 comments on commit 420973a

Please sign in to comment.