Skip to content

Destinations as first-class objects #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 107 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
03761b2
Started working on destination migration
AndreasArvidsson Jul 8, 2023
397a80c
stuff
AndreasArvidsson Jul 8, 2023
5793b28
more work
AndreasArvidsson Jul 8, 2023
09be83f
Test passes
AndreasArvidsson Jul 8, 2023
40e5301
Is not a token
AndreasArvidsson Jul 8, 2023
e370a28
Merge branch 'main' into destination
AndreasArvidsson Jul 9, 2023
4803508
Add destination during command version upgrade dependent on action name
AndreasArvidsson Jul 9, 2023
38b85ed
cleanup
AndreasArvidsson Jul 9, 2023
e52df85
Removed position target and implemented destination
AndreasArvidsson Jul 9, 2023
3c6bb5d
cleanup
AndreasArvidsson Jul 10, 2023
170c2cc
Merge branch 'main' into destination
AndreasArvidsson Jul 10, 2023
6c530de
Added new action types
AndreasArvidsson Jul 10, 2023
a42ab5c
cleanup
AndreasArvidsson Jul 10, 2023
a9215ef
clean up validation
AndreasArvidsson Jul 10, 2023
a855bec
stuff
AndreasArvidsson Jul 10, 2023
b09d599
Merge branch 'main' into destination
AndreasArvidsson Jul 10, 2023
c0b72e5
tidy tidy
AndreasArvidsson Jul 10, 2023
558baf7
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jul 10, 2023
e8cbd25
stuff
AndreasArvidsson Jul 10, 2023
5dc4ff0
Merge branches 'destination' and 'destination' of github.com:cursorle…
AndreasArvidsson Jul 10, 2023
8881b0f
Merge branch 'main' into destination
AndreasArvidsson Jul 10, 2023
648a12c
stuff2
AndreasArvidsson Jul 10, 2023
3800c91
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jul 10, 2023
42fa23a
clean
AndreasArvidsson Jul 10, 2023
65c2b52
Merge branch 'destination' of github.com:cursorless-dev/cursorless in…
AndreasArvidsson Jul 10, 2023
a414407
Rough draft of inference on destinations
pokey Jul 10, 2023
dbbae33
bring move swap is working
AndreasArvidsson Jul 10, 2023
e6877db
update
AndreasArvidsson Jul 10, 2023
04206de
Started migrating actions
AndreasArvidsson Jul 10, 2023
6d18160
more changes
AndreasArvidsson Jul 10, 2023
9fffc11
bug fixes
AndreasArvidsson Jul 10, 2023
cf85117
stuff
AndreasArvidsson Jul 11, 2023
4f55a0a
update snippet
AndreasArvidsson Jul 11, 2023
10743c9
fix
AndreasArvidsson Jul 11, 2023
c2e1ea3
update
AndreasArvidsson Jul 11, 2023
69ccb77
remove tests
AndreasArvidsson Jul 11, 2023
c43be25
stuff
AndreasArvidsson Jul 11, 2023
86d4de4
stuff
AndreasArvidsson Jul 11, 2023
1134171
Added vertical range target
AndreasArvidsson Jul 11, 2023
3f7b40d
stuff
AndreasArvidsson Jul 11, 2023
3b8917b
remove
AndreasArvidsson Jul 11, 2023
bbf01f3
blob
AndreasArvidsson Jul 11, 2023
ea300bc
Update the test case recorder tests
AndreasArvidsson Jul 11, 2023
5accb88
Updated type destination to primitive destination
AndreasArvidsson Jul 11, 2023
6c95c6d
fix
AndreasArvidsson Jul 11, 2023
2bef7b3
cleanup
AndreasArvidsson Jul 11, 2023
379736a
updated test
AndreasArvidsson Jul 11, 2023
2d3c828
fix
AndreasArvidsson Jul 11, 2023
1fbb31c
fix
AndreasArvidsson Jul 11, 2023
41f25d6
cleanup
AndreasArvidsson Jul 11, 2023
b165299
renamed file
AndreasArvidsson Jul 11, 2023
6d6ee1b
jsdocs / renames
pokey Jul 11, 2023
c55d1dc
tweak jsdocs
pokey Jul 11, 2023
38c6fa3
cleanup
pokey Jul 11, 2023
edd5f2a
inline arguments in `CommandRunnerImpl`
pokey Jul 11, 2023
dde3247
Resurrect post-inference debugging
pokey Jul 11, 2023
9c3366a
Update packages/cursorless-engine/src/actions/EditNew/runNotebookCell…
AndreasArvidsson Jul 11, 2023
63b945b
Ked fixed bug
AndreasArvidsson Jul 11, 2023
701d974
Rename
AndreasArvidsson Jul 11, 2023
0c6498b
cleanup
AndreasArvidsson Jul 11, 2023
fc6f649
rename
pokey Jul 11, 2023
f45aa36
tweak view
pokey Jul 11, 2023
75063ce
remove comment
pokey Jul 11, 2023
5a95c65
always use raw target for position stage
AndreasArvidsson Jul 11, 2023
b4043a9
Added implicit destination
AndreasArvidsson Jul 11, 2023
4f9618d
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jul 11, 2023
fb87903
clean
AndreasArvidsson Jul 11, 2023
d9d3514
Merge branch 'destination' of github.com:cursorless-dev/cursorless in…
AndreasArvidsson Jul 11, 2023
f9e5628
Cleanup
pokey Jul 11, 2023
da816eb
whoops
pokey Jul 11, 2023
94c2ecd
more tweaks
pokey Jul 11, 2023
bd02d1b
Removed the word partial from action descriptors
AndreasArvidsson Jul 11, 2023
0f5818c
Remove one more `Partial`
pokey Jul 11, 2023
157b0fd
More cleanup
pokey Jul 12, 2023
31c789f
More simplification
pokey Jul 12, 2023
c899a61
more cleanup
pokey Jul 12, 2023
467315e
Improve typing; cleanup `editNew`
pokey Jul 12, 2023
8c886b6
Cleanup typing and make validate avoid mutation
pokey Jul 12, 2023
c693062
Js doc
pokey Jul 12, 2023
afaff47
Js doc
pokey Jul 12, 2023
8bff62c
Ja stock
pokey Jul 12, 2023
02747e0
move edit new stuff to new file
pokey Jul 12, 2023
aef20eb
Continues splitting up bring move swap
pokey Jul 12, 2023
d360790
Comments
pokey Jul 12, 2023
41b72e8
Add comments
pokey Jul 12, 2023
416db50
Make upgrade code more closely match Talon
pokey Jul 12, 2023
ea7b2fe
more cleanup
pokey Jul 12, 2023
b059c7e
cleanup inference comments
pokey Jul 12, 2023
4d252fd
Added type for get text action
AndreasArvidsson Jul 13, 2023
e481710
Added get text test
AndreasArvidsson Jul 13, 2023
a387d97
Updated get text test
AndreasArvidsson Jul 13, 2023
62c4b95
cleanup
pokey Jul 13, 2023
53ecf4c
cleanup
pokey Jul 13, 2023
5acd577
rename
pokey Jul 13, 2023
a9ac2da
cleanup
pokey Jul 13, 2023
794c164
cleanup
pokey Jul 13, 2023
eb327e4
cleanup
pokey Jul 13, 2023
5c4debf
cleanup
pokey Jul 13, 2023
822c07b
more
pokey Jul 13, 2023
a26aac4
Cleanup
pokey Jul 13, 2023
12044c4
More cleanup
pokey Jul 13, 2023
71d6f56
Remove `VerticalRangeTarget`
pokey Jul 13, 2023
43ee76d
Remove some default imports
pokey Jul 13, 2023
c53d1bd
clean up tests
pokey Jul 13, 2023
db052bd
whoops
pokey Jul 13, 2023
081d5df
Re-add removed tests
pokey Jul 13, 2023
6a41a7e
Merge branch 'main' into destination
pokey Jul 13, 2023
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
8 changes: 6 additions & 2 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ export * from "./util/CompositeKeyMap";
export * from "./ide/normalized/NormalizedIDE";
export * from "./types/command/command.types";
export * from "./types/command/PartialTargetDescriptor.types";
export * from "./types/command/ActionCommand";
export * from "./types/command/DestinationDescriptor.types";
export * from "./types/command/ActionDescriptor";
export * from "./types/command/legacy/CommandV0V1.types";
export * from "./types/command/legacy/CommandV2.types";
export * from "./types/command/legacy/CommandV3.types";
export * from "./types/command/legacy/CommandV4.types";
export * from "./types/command/legacy/targetDescriptorV2.types";
export * from "./types/command/CommandV5.types";
export * from "./types/command/legacy/ActionCommandV5";
export * from "./types/command/legacy/CommandV5.types";
export * from "./types/command/legacy/PartialTargetDescriptorV5.types";
export * from "./types/command/CommandV6.types";
export * from "./types/command/legacy/PartialTargetDescriptorV3.types";
export * from "./types/command/legacy/PartialTargetDescriptorV4.types";
export * from "./types/CommandServerApi";
Expand Down
228 changes: 228 additions & 0 deletions packages/common/src/types/command/ActionDescriptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import {
PartialTargetDescriptor,
ScopeType,
} from "./PartialTargetDescriptor.types";
import { DestinationDescriptor } from "./DestinationDescriptor.types";

/**
* A simple action takes only a single target and no other arguments.
*/
const simpleActionNames = [
"clearAndSetSelection",
"copyToClipboard",
"cutToClipboard",
"deselect",
"editNewLineAfter",
"editNewLineBefore",
"experimental.setInstanceReference",
"extractVariable",
"findInWorkspace",
"foldRegion",
"followLink",
"indentLine",
"insertCopyAfter",
"insertCopyBefore",
"insertEmptyLineAfter",
"insertEmptyLineBefore",
"insertEmptyLinesAround",
"outdentLine",
"randomizeTargets",
"remove",
"rename",
"revealDefinition",
"revealTypeDefinition",
"reverseTargets",
"scrollToBottom",
"scrollToCenter",
"scrollToTop",
"setSelection",
"setSelectionAfter",
"setSelectionBefore",
"showDebugHover",
"showHover",
"showQuickFix",
"showReferences",
"sortTargets",
"toggleLineBreakpoint",
"toggleLineComment",
"unfoldRegion",
] as const;

const complexActionNames = [
"callAsFunction",
"editNew",
"executeCommand",
"generateSnippet",
"getText",
"highlight",
"insertSnippet",
"moveToTarget",
"pasteFromClipboard",
"replace",
"replaceWithTarget",
"rewrapWithPairedDelimiter",
"swapTargets",
"wrapWithPairedDelimiter",
"wrapWithSnippet",
] as const;

export const actionNames = [
...simpleActionNames,
...complexActionNames,
] as const;

export type SimpleActionName = (typeof simpleActionNames)[number];
export type ActionType = (typeof actionNames)[number];

/**
* A simple action takes only a single target and no other arguments.
*/
export interface SimpleActionDescriptor {
name: SimpleActionName;
target: PartialTargetDescriptor;
}

export interface BringMoveActionDescriptor {
name: "replaceWithTarget" | "moveToTarget";
source: PartialTargetDescriptor;
destination: DestinationDescriptor;
}

export interface CallActionDescriptor {
name: "callAsFunction";

/**
* The target to use as the function to be called.
*/
callee: PartialTargetDescriptor;

/**
* The target to wrap in a function call.
*/
argument: PartialTargetDescriptor;
}

export interface SwapActionDescriptor {
name: "swapTargets";
target1: PartialTargetDescriptor;
target2: PartialTargetDescriptor;
}

export interface WrapWithPairedDelimiterActionDescriptor {
name: "wrapWithPairedDelimiter" | "rewrapWithPairedDelimiter";
left: string;
right: string;
target: PartialTargetDescriptor;
}

export interface PasteActionDescriptor {
name: "pasteFromClipboard";
destination: DestinationDescriptor;
}

export interface GenerateSnippetActionDescriptor {
name: "generateSnippet";
snippetName?: string;
target: PartialTargetDescriptor;
}

interface NamedInsertSnippetArg {
type: "named";
name: string;
substitutions?: Record<string, string>;
}
interface CustomInsertSnippetArg {
type: "custom";
body: string;
scopeType?: ScopeType;
substitutions?: Record<string, string>;
}
export type InsertSnippetArg = NamedInsertSnippetArg | CustomInsertSnippetArg;

export interface InsertSnippetActionDescriptor {
name: "insertSnippet";
snippetDescription: InsertSnippetArg;
destination: DestinationDescriptor;
}

interface NamedWrapWithSnippetArg {
type: "named";
name: string;
variableName: string;
}
interface CustomWrapWithSnippetArg {
type: "custom";
body: string;
variableName?: string;
scopeType?: ScopeType;
}
export type WrapWithSnippetArg =
| NamedWrapWithSnippetArg
| CustomWrapWithSnippetArg;

export interface WrapWithSnippetActionDescriptor {
name: "wrapWithSnippet";
snippetDescription: WrapWithSnippetArg;
target: PartialTargetDescriptor;
}

export interface ExecuteCommandOptions {
commandArgs?: any[];
ensureSingleEditor?: boolean;
ensureSingleTarget?: boolean;
restoreSelection?: boolean;
showDecorations?: boolean;
}

export interface ExecuteCommandActionDescriptor {
name: "executeCommand";
commandId: string;
options?: ExecuteCommandOptions;
target: PartialTargetDescriptor;
}

export type ReplaceWith = string[] | { start: number };

export interface ReplaceActionDescriptor {
name: "replace";
replaceWith: ReplaceWith;
destination: DestinationDescriptor;
}

export interface HighlightActionDescriptor {
name: "highlight";
highlightId?: string;
target: PartialTargetDescriptor;
}

export interface EditNewActionDescriptor {
name: "editNew";
destination: DestinationDescriptor;
}

export interface GetTextActionOptions {
showDecorations?: boolean;
ensureSingleTarget?: boolean;
}

export interface GetTextActionDescriptor {
name: "getText";
options?: GetTextActionOptions;
target: PartialTargetDescriptor;
}

export type ActionDescriptor =
| SimpleActionDescriptor
| BringMoveActionDescriptor
| SwapActionDescriptor
| CallActionDescriptor
| PasteActionDescriptor
| ExecuteCommandActionDescriptor
| ReplaceActionDescriptor
| HighlightActionDescriptor
| GenerateSnippetActionDescriptor
| InsertSnippetActionDescriptor
| WrapWithSnippetActionDescriptor
| WrapWithPairedDelimiterActionDescriptor
| EditNewActionDescriptor
| GetTextActionDescriptor;
27 changes: 27 additions & 0 deletions packages/common/src/types/command/CommandV6.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { ActionDescriptor } from "./ActionDescriptor";

export interface CommandV6 {
/**
* The version number of the command API
*/
version: 6;

/**
* The spoken form of the command if issued from a voice command system
*/
spokenForm?: string;

/**
* If the command is issued from a voice command system, this boolean indicates
* whether we should use the pre phrase snapshot. Only set this to true if the
* voice command system issues a pre phrase signal at the start of every
* phrase.
*/
usePrePhraseSnapshot: boolean;

/**
* The action to perform. This field contains everything necessary to actually
* perform the action. The other fields are just metadata.
*/
action: ActionDescriptor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
PartialListTargetDescriptor,
PartialPrimitiveTargetDescriptor,
PartialRangeTargetDescriptor,
} from "./PartialTargetDescriptor.types";

/**
* The insertion mode to use when inserting relative to a target.
* - `before` inserts before the target. Depending on the target, a delimiter
* may be inserted after the inserted text.
* - `after` inserts after the target. Depending on the target, a delimiter may
* be inserted before the inserted text.
* - `to` replaces the target. However, this insertion mode may also be used
* when the target is really only a pseudo-target. For example, you could say
* `"bring type air to bat"` even if `bat` doesn't already have a type. In
* that case, `"take type bat"` wouldn't work, so `"type bat"` is really just
* a pseudo-target in that situation.
*/
export type InsertionMode = "before" | "after" | "to";

export interface PrimitiveDestinationDescriptor {
type: "primitive";

/**
* The insertion mode to use when inserting relative to {@link target}.
*/
insertionMode: InsertionMode;

target:
| PartialPrimitiveTargetDescriptor
| PartialRangeTargetDescriptor
| PartialListTargetDescriptor;
}

/**
* A list of destinations. This is used when the user uses more than one insertion mode
* in a single command. For example, `"bring air after bat and before cap"`.
*/
export interface ListDestinationDescriptor {
type: "list";
destinations: PrimitiveDestinationDescriptor[];
}

/**
* An implicit destination. This is used for e.g. `"bring air"` (note the user
* doesn't explicitly specify the destination), or `"snip funk"`.
*/
export interface ImplicitDestinationDescriptor {
type: "implicit";
}

export type DestinationDescriptor =
| ListDestinationDescriptor
| PrimitiveDestinationDescriptor
| ImplicitDestinationDescriptor;
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,21 @@ export interface InferPreviousMarkModifier {
type: "inferPreviousMark";
}

export type TargetPosition = "before" | "after" | "start" | "end";
export interface StartOfModifier {
type: "startOf";
}

export interface PositionModifier {
type: "position";
position: TargetPosition;
export interface EndOfModifier {
type: "endOf";
}

export interface PartialPrimitiveTargetDescriptor {
type: "primitive";
mark?: PartialMark;
export interface HeadModifier {
type: "extendThroughStartOf";
modifiers?: Modifier[];
}

export interface HeadTailModifier {
type: "extendThroughStartOf" | "extendThroughEndOf";
export interface TailModifier {
type: "extendThroughEndOf";
modifiers?: Modifier[];
}

Expand Down Expand Up @@ -326,14 +326,16 @@ export interface RangeModifier {
}

export type Modifier =
| PositionModifier
| StartOfModifier
| EndOfModifier
| InteriorOnlyModifier
| ExcludeInteriorModifier
| ContainingScopeModifier
| EveryScopeModifier
| OrdinalScopeModifier
| RelativeScopeModifier
| HeadTailModifier
| HeadModifier
| TailModifier
| LeadingModifier
| TrailingModifier
| RawSelectionModifier
Expand All @@ -348,6 +350,12 @@ export type Modifier =
// vertical puts a selection on each line vertically between the two targets
export type PartialRangeType = "continuous" | "vertical";

export interface PartialPrimitiveTargetDescriptor {
type: "primitive";
mark?: PartialMark;
modifiers?: Modifier[];
}

export interface PartialRangeTargetDescriptor {
type: "range";
anchor: PartialPrimitiveTargetDescriptor | ImplicitTargetDescriptor;
Expand Down
Loading