Skip to content

Allow using "this" to refer to current token with empty selection #1094

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 64 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f28ceac
Modify untyped, weak and empty target into token
AndreasArvidsson Oct 26, 2022
c191a8a
Added option to suppress errors
AndreasArvidsson Oct 26, 2022
a3e8ed9
Don't update for range targets
AndreasArvidsson Oct 26, 2022
d87998f
Updated tests
AndreasArvidsson Oct 26, 2022
1e8bfab
Merge branch 'main' into expand_empty_selection_to_token
AndreasArvidsson Oct 30, 2022
a1bd86f
Clean up
AndreasArvidsson Oct 30, 2022
799a1ce
clean up
AndreasArvidsson Oct 30, 2022
a901224
Typo
AndreasArvidsson Oct 30, 2022
c800b55
Merge branch 'main' into expand_empty_selection_to_token
AndreasArvidsson Oct 31, 2022
7b01987
added tests
AndreasArvidsson Oct 31, 2022
4fe42d8
cleanup
AndreasArvidsson Oct 31, 2022
b05f607
updated test
AndreasArvidsson Oct 31, 2022
0e19786
updated test
AndreasArvidsson Oct 31, 2022
aa4bb4d
updated test
AndreasArvidsson Oct 31, 2022
3398372
cleanup
AndreasArvidsson Oct 31, 2022
518dda8
Merge branch 'main' into expand_empty_selection_to_token
pokey Nov 8, 2022
f863b5c
Merge branch 'main' into expand_empty_selection_to_token
AndreasArvidsson Nov 8, 2022
af19525
Merge branch 'main' into expand_empty_selection_to_token
AndreasArvidsson Nov 15, 2022
ec31abc
Threat range targets the same
AndreasArvidsson Nov 15, 2022
52ce2a6
Merge branch 'main' into expand_empty_selection_to_token
AndreasArvidsson Nov 16, 2022
78bde51
Use implicit target for single target range
AndreasArvidsson Nov 16, 2022
bc37c52
updated tests
AndreasArvidsson Nov 16, 2022
4fcc83f
updated tests
AndreasArvidsson Nov 16, 2022
15ea297
Merge branch 'main' into expand_empty_selection_to_token
AndreasArvidsson Nov 16, 2022
dd1e68c
Merge branch 'main' into expand_empty_selection_to_token
pokey Dec 13, 2022
39986bd
Add comment
pokey Dec 13, 2022
e24f4d0
More comment
pokey Dec 13, 2022
cac3220
Merge branch 'main' into expand_empty_selection_to_token
pokey Dec 15, 2022
cb8af70
Migration for V3 to V4
pokey Dec 14, 2022
35e82c6
Merge branch 'main' into expand_empty_selection_to_token
pokey Dec 16, 2022
7ca4dc0
More api surface type cleanup
pokey Dec 16, 2022
72870f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 16, 2022
da627ae
Split TargetDescriptor from PartialTargetDescriptor
pokey Dec 16, 2022
fd51adf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 16, 2022
6a8a6ba
Merge branch 'pokey/more-api-surface-type-cleanup' into HEAD
pokey Dec 16, 2022
dc06707
Fix lint
pokey Dec 16, 2022
766ef00
Merge branch 'pokey/more-api-surface-type-cleanup' into HEAD
pokey Dec 16, 2022
ca04b21
Cleanup V3 types
pokey Dec 16, 2022
572f419
Add eslint rule
pokey Dec 16, 2022
02b45ab
Merge branch 'pokey/more-api-surface-type-cleanup' into expand_empty_…
pokey Dec 16, 2022
c2c9ae6
More lint
pokey Dec 16, 2022
9485cab
Merge branch 'pokey/more-api-surface-type-cleanup' into expand_empty_…
pokey Dec 16, 2022
f57583d
Make implicit target its own type (fixes #1141)
pokey Dec 16, 2022
9b7f5cb
Fix imports
pokey Dec 16, 2022
aa295af
Fixes to capturing V3 types
pokey Dec 16, 2022
0bc4182
Modify upgrade path for #1141
pokey Dec 16, 2022
1dfc717
bump command version Python side
pokey Dec 16, 2022
ccaa079
roll back containing token test
pokey Dec 16, 2022
5c4f013
More migration typing
pokey Dec 16, 2022
e9dd4a2
Tests for v4 command
pokey Dec 16, 2022
4112526
Update docs
pokey Dec 16, 2022
c2db99b
More tests
pokey Dec 16, 2022
7d1e890
Another test
pokey Dec 16, 2022
bd27f8e
More upgrade fixes
pokey Dec 17, 2022
7e57054
Empty commit
pokey Dec 17, 2022
f6c3d6e
Passing tests
pokey Dec 19, 2022
b13a9e5
Mirror implicit targets through
pokey Dec 19, 2022
13f6600
Merge branch 'main' into pokey/more-api-surface-type-cleanup
pokey Dec 19, 2022
f01cd4f
Merge branch 'pokey/more-api-surface-type-cleanup' into expand_empty_…
pokey Dec 19, 2022
e8c2094
Merge branch 'main' into expand_empty_selection_to_token
pokey Dec 20, 2022
60b2e7e
Cleanup
pokey Dec 20, 2022
abeaa97
Doc strings
pokey Dec 20, 2022
9439a7d
Merge branch 'main' into expand_empty_selection_to_token
pokey Dec 22, 2022
ecd0bb0
Fixed types
pokey Dec 22, 2022
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
3 changes: 2 additions & 1 deletion cursorless-talon/src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
mod = Module()

CURSORLESS_COMMAND_ID = "cursorless.command"
CURSORLESS_COMMAND_VERSION = 4
last_phrase = None


Expand Down Expand Up @@ -136,7 +137,7 @@ def construct_cursorless_command_argument(
use_pre_phrase_snapshot = False

return {
"version": 3,
"version": CURSORLESS_COMMAND_VERSION,
"spokenForm": get_spoken_form(),
"action": {
"name": action,
Expand Down
4 changes: 2 additions & 2 deletions cursorless-talon/src/compound_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from talon import Module

from .connective import default_range_connective
from .primitive_target import BASE_TARGET
from .primitive_target import IMPLICIT_TARGET

mod = Module()

Expand Down Expand Up @@ -46,7 +46,7 @@ def cursorless_range(m) -> dict[str, Any]:
return primitive_targets[0]

if len(primitive_targets) == 1:
anchor = BASE_TARGET.copy()
anchor = IMPLICIT_TARGET.copy()
else:
anchor = primitive_targets[0]

Expand Down
2 changes: 1 addition & 1 deletion cursorless-talon/src/primitive_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
mod = Module()

BASE_TARGET: dict[str, Any] = {"type": "primitive"}
IMPLICIT_TARGET = {"type": "primitive", "isImplicit": True}
IMPLICIT_TARGET = {"type": "implicit"}


@mod.capture(
Expand Down
2 changes: 2 additions & 0 deletions docs/user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ The word `"this"` can be used as a mark to refer to the current cursor(s) or sel
- `"pre funk"`
- `"chuck line"`

Note that if you say `"this"` with an empty selection, it refers to the token containing your cursor.

##### `"that"`

The word `"that"` can be used as a mark to refer to the target of the previous cursorless command.
Expand Down
21 changes: 9 additions & 12 deletions src/actions/InsertSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getSelectionInfo,
} from "../core/updateSelections/updateSelections";
import ide from "../libs/cursorless-engine/singletons/ide.singleton";
import ModifyIfUntypedStage from "../processTargets/modifiers/ModifyIfUntypedStage";
import { ModifyIfUntypedExplicitStage } from "../processTargets/modifiers/ConditionalModifierStages";
import { Snippet, SnippetDefinition } from "../typings/snippet";
import { Target } from "../typings/target.types";
import { Graph } from "../typings/Types";
Expand All @@ -30,17 +30,14 @@ export default class InsertSnippet implements Action {
}

return [
new ModifyIfUntypedStage({
type: "modifyIfUntyped",
modifier: {
type: "cascading",
modifiers: defaultScopeTypes.map((scopeType) => ({
type: "containingScope",
scopeType: {
type: scopeType,
},
})),
},
new ModifyIfUntypedExplicitStage({
type: "cascading",
modifiers: defaultScopeTypes.map((scopeType) => ({
type: "containingScope",
scopeType: {
type: scopeType,
},
})),
}),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/WrapWithSnippet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { callFunctionAndUpdateSelections } from "../core/updateSelections/updateSelections";
import ide from "../libs/cursorless-engine/singletons/ide.singleton";
import ModifyIfUntypedStage from "../processTargets/modifiers/ModifyIfUntypedStage";
import { ModifyIfUntypedStage } from "../processTargets/modifiers/ConditionalModifierStages";
import { Target } from "../typings/target.types";
import { Graph } from "../typings/Types";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { PartialTargetDescriptor } from "./PartialTargetDescriptor.types";
import type { ActionCommand } from "./ActionCommand";

export interface CommandV3 {
export interface CommandV4 {
/**
* The version number of the command API
*/
version: 3;
version: 4;

/**
* The spoken form of the command if issued from a voice command system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export interface PartialPrimitiveTargetDescriptor {
type: "primitive";
mark?: Mark;
modifiers?: Modifier[];
isImplicit?: boolean;
}

export interface HeadTailModifier {
Expand Down Expand Up @@ -350,7 +349,7 @@ export type RangeType = "continuous" | "vertical";

export interface PartialRangeTargetDescriptor {
type: "range";
anchor: PartialPrimitiveTargetDescriptor;
anchor: PartialPrimitiveTargetDescriptor | ImplicitTargetDescriptor;
active: PartialPrimitiveTargetDescriptor;
excludeAnchor: boolean;
excludeActive: boolean;
Expand All @@ -362,7 +361,12 @@ export interface PartialListTargetDescriptor {
elements: (PartialPrimitiveTargetDescriptor | PartialRangeTargetDescriptor)[];
}

export interface ImplicitTargetDescriptor {
type: "implicit";
}

export type PartialTargetDescriptor =
| PartialPrimitiveTargetDescriptor
| PartialRangeTargetDescriptor
| PartialListTargetDescriptor;
| PartialListTargetDescriptor
| ImplicitTargetDescriptor;
7 changes: 4 additions & 3 deletions src/core/commandRunner/typings/command.types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { ActionCommand } from "./ActionCommand";
import type { CommandV0, CommandV1 } from "./legacy/CommandV0V1.types";
import type { CommandV2 } from "./legacy/CommandV2.types";
import type { CommandV3 } from "./CommandV3.types";
import type { CommandV3 } from "./legacy/CommandV3.types";
import type { CommandV4 } from "./CommandV4.types";

export type CommandComplete = Required<Omit<CommandLatest, "spokenForm">> &
Pick<CommandLatest, "spokenForm"> & { action: Required<ActionCommand> };

export const LATEST_VERSION = 3 as const;
export const LATEST_VERSION = 4 as const;

export type CommandLatest = Command & {
version: typeof LATEST_VERSION;
};

export type Command = CommandV0 | CommandV1 | CommandV2 | CommandV3;
export type Command = CommandV0 | CommandV1 | CommandV2 | CommandV3 | CommandV4;
95 changes: 95 additions & 0 deletions src/core/commandRunner/typings/legacy/CommandV3.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { PartialTargetDescriptorV3 } from "./PartialTargetDescriptorV3.types";

type ActionType =
| "callAsFunction"
| "clearAndSetSelection"
| "copyToClipboard"
| "cutToClipboard"
| "deselect"
| "editNew"
| "editNewLineAfter"
| "editNewLineBefore"
| "executeCommand"
| "extractVariable"
| "findInWorkspace"
| "foldRegion"
| "followLink"
| "generateSnippet"
| "getText"
| "highlight"
| "indentLine"
| "insertCopyAfter"
| "insertCopyBefore"
| "insertEmptyLineAfter"
| "insertEmptyLineBefore"
| "insertEmptyLinesAround"
| "insertSnippet"
| "moveToTarget"
| "outdentLine"
| "pasteFromClipboard"
| "randomizeTargets"
| "remove"
| "rename"
| "replace"
| "replaceWithTarget"
| "revealDefinition"
| "revealTypeDefinition"
| "reverseTargets"
| "rewrapWithPairedDelimiter"
| "scrollToBottom"
| "scrollToCenter"
| "scrollToTop"
| "setSelection"
| "setSelectionAfter"
| "setSelectionBefore"
| "showDebugHover"
| "showHover"
| "showQuickFix"
| "showReferences"
| "sortTargets"
| "swapTargets"
| "toggleLineBreakpoint"
| "toggleLineComment"
| "unfoldRegion"
| "wrapWithPairedDelimiter"
| "wrapWithSnippet";

interface ActionCommand {
/**
* The action to run
*/
name: ActionType;

/**
* A list of arguments expected by the given action.
*/
args?: unknown[];
}

export interface CommandV3 {
/**
* The version number of the command API
*/
version: 3;

/**
* 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;

action: ActionCommand;

/**
* A list of targets expected by the action. Inference will be run on the
* targets
*/
targets: PartialTargetDescriptorV3[];
}
Loading