Skip to content
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

Implemented strict here selection type #352

Merged
merged 7 commits into from
Dec 16, 2021
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
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"cSpell.words": [
"subword",
"Autoformatting",
"eqeqeq",
"nonlocal",
"pojo"
"pojo",
"subword"
]
}
8 changes: 6 additions & 2 deletions src/actions/BringMoveSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ class BringMoveSwap implements Action {
let text = source.selection.editor.document.getText(
source.selection.selection
);
return i > 0 && destination.selectionContext.containingListDelimiter
? destination.selectionContext.containingListDelimiter + text
const selectionContext = destination.selectionContext
.isRawSelection
? source.selectionContext
: destination.selectionContext;
return i > 0 && selectionContext.containingListDelimiter
? selectionContext.containingListDelimiter + text
: text;
})
.join("");
Expand Down
13 changes: 8 additions & 5 deletions src/core/inferFullTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ function inferPrimitiveTarget(
previousTargets: PartialTarget[],
actionPreferences: ActionPreferences
): PrimitiveTarget {
const previousTargetsForAttributes = hasContent(target)
? []
: previousTargets;
const doAttributeInference = !hasContent(target) && !target.isImplicit;

const previousTargetsForAttributes = doAttributeInference
? previousTargets
: [];

const maybeSelectionType =
target.selectionType ??
Expand All @@ -117,7 +119,7 @@ function inferPrimitiveTarget(

const selectionType =
maybeSelectionType ??
(target.modifier == null ? actionPreferences.selectionType : null) ??
(doAttributeInference ? actionPreferences.selectionType : null) ??
"token";

const insideOutsideType =
Expand All @@ -127,7 +129,7 @@ function inferPrimitiveTarget(

const modifier = target.modifier ??
getPreviousAttribute(previousTargetsForAttributes, "modifier") ??
(target.selectionType == null ? actionPreferences.modifier : null) ?? {
(doAttributeInference ? actionPreferences.modifier : null) ?? {
type: "identity",
};

Expand All @@ -138,6 +140,7 @@ function inferPrimitiveTarget(
position,
insideOutsideType,
modifier,
isImplicit: target.isImplicit ?? false,
};
}

Expand Down
8 changes: 7 additions & 1 deletion src/processTargets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import processMark from "./processMark";
import processModifier from "./modifiers/processModifier";
import processPosition from "./processPosition";
import processSelectionType from "./processSelectionType";
import { isForward as getIsForward } from "../util/selectionUtils";

export default function (
context: ProcessedTargetsContext,
Expand Down Expand Up @@ -275,6 +274,13 @@ function processPrimitiveTarget(
({ selection, context: selectionContext }) =>
processSelectionType(context, target, selection, selectionContext)
);

if (target.isImplicit) {
typedSelections.forEach((typedSelection) => {
typedSelection.selectionContext.isRawSelection = true;
});
}

return typedSelections.map((selection) =>
processPosition(context, target, selection)
);
Expand Down
22 changes: 22 additions & 0 deletions src/processTargets/modifiers/processModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NodeMatcher,
PrimitiveTarget,
ProcessedTargetsContext,
RawSelectionModifier,
SelectionContext,
SelectionWithEditor,
SubTokenModifier,
Expand Down Expand Up @@ -52,6 +53,14 @@ export default function (
case "surroundingPair":
result = processSurroundingPair(context, selection, modifier);
break;

case "toRawSelection":
result = processRawSelectionModifier(context, selection, modifier);
break;

default:
// Make sure we haven't missed any cases
const neverCheck: never = modifier;
}

if (result == null) {
Expand Down Expand Up @@ -233,3 +242,16 @@ export function findNearestContainingAncestorNode(

return null;
}

function processRawSelectionModifier(
context: ProcessedTargetsContext,
selection: SelectionWithEditor,
modifier: RawSelectionModifier
): SelectionWithEditorWithContext[] | null {
return [
{
selection,
context: { isRawSelection: true },
},
];
}
23 changes: 16 additions & 7 deletions src/processTargets/processSelectionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ function processToken(
selectionType,
position,
insideOutsideType,
selectionContext: getTokenSelectionContext(
selection,
modifier,
position,
insideOutsideType,
selectionContext
),
// NB: This is a hack to work around the fact that it's not currently
// possible to apply a modifier after processing the selection type. We
// would really prefer that the user be able to say "just" and have that be
// processed after we've processed the selection type, which would strip
// away the type information and turn it into a raw target. Until that's
// possible using the new pipelines, we instead just check for it here when
// we're doing the selection type and bail out if it is a raw target.
selectionContext: selectionContext.isRawSelection
? selectionContext
: getTokenSelectionContext(
selection,
modifier,
position,
insideOutsideType,
selectionContext
),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ command:
mark: {type: decoratedSymbol, symbolColor: default, character: b}
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: c}
- type: primitive
mark: {type: cursor}
selectionType: token
position: contents
modifier: {type: identity}
insideOutsideType: inside
- {type: primitive, isImplicit: true}
initialState:
documentContents: |+
a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
languageId: typescript
command:
version: 1
spokenForm: bring argue fine and zip
action: replaceWithTarget
targets:
- type: list
elements:
- type: primitive
modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}
mark: {type: decoratedSymbol, symbolColor: default, character: f}
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: z}
- {type: primitive, isImplicit: true}
initialState:
documentContents: |-
function helloWorld(foo: string, bar: number, baz: string) {

}

function bongo() {

}
selections:
- anchor: {line: 4, character: 15}
active: {line: 4, character: 15}
marks:
default.f:
start: {line: 0, character: 20}
end: {line: 0, character: 23}
default.z:
start: {line: 0, character: 46}
end: {line: 0, character: 49}
finalState:
documentContents: |-
function helloWorld(foo: string, bar: number, baz: string) {

}

function bongo(foo: string, baz: string) {

}
selections:
- anchor: {line: 4, character: 39}
active: {line: 4, character: 39}
thatMark:
- anchor: {line: 4, character: 15}
active: {line: 4, character: 39}
sourceMark:
- anchor: {line: 0, character: 20}
active: {line: 0, character: 31}
- anchor: {line: 0, character: 46}
active: {line: 0, character: 57}
fullTargets: [{type: list, elements: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}, {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: z}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}]}, {type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}, isImplicit: true}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
languageId: typescript
command:
version: 1
spokenForm: bring argue ox and zip to after just leper
action: replaceWithTarget
targets:
- type: list
elements:
- type: primitive
modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}
mark: {type: decoratedSymbol, symbolColor: default, character: o}
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: z}
- type: primitive
position: after
modifier: {type: toRawSelection}
mark: {type: decoratedSymbol, symbolColor: default, character: (}
initialState:
documentContents: |-
function helloWorld(foo: string, bar: number, baz: string) {

}

function bongo() {

}
selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
marks:
default.o:
start: {line: 0, character: 20}
end: {line: 0, character: 23}
default.z:
start: {line: 0, character: 46}
end: {line: 0, character: 49}
default.(:
start: {line: 4, character: 14}
end: {line: 4, character: 15}
finalState:
documentContents: |-
function helloWorld(foo: string, bar: number, baz: string) {

}

function bongo(foo: string, baz: string) {

}
selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
thatMark:
- anchor: {line: 4, character: 15}
active: {line: 4, character: 39}
sourceMark:
- anchor: {line: 0, character: 20}
active: {line: 0, character: 31}
- anchor: {line: 0, character: 46}
active: {line: 0, character: 57}
fullTargets: [{type: list, elements: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: o}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}, {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: z}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}]}, {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: (}, selectionType: token, position: after, insideOutsideType: null, modifier: {type: toRawSelection}, isImplicit: false}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
languageId: plaintext
command:
version: 1
spokenForm: bring line harp and whale
action: replaceWithTarget
targets:
- type: list
elements:
- type: primitive
selectionType: line
mark: {type: decoratedSymbol, symbolColor: default, character: h}
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: w}
- {type: primitive, isImplicit: true}
initialState:
documentContents: |+
hello
there
whatever

selections:
- anchor: {line: 4, character: 0}
active: {line: 4, character: 0}
marks:
default.h:
start: {line: 0, character: 0}
end: {line: 0, character: 5}
default.w:
start: {line: 2, character: 0}
end: {line: 2, character: 8}
finalState:
documentContents: |-
hello
there
whatever

hello
whatever
selections:
- anchor: {line: 5, character: 8}
active: {line: 5, character: 8}
thatMark:
- anchor: {line: 4, character: 0}
active: {line: 5, character: 8}
sourceMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 5}
- anchor: {line: 2, character: 0}
active: {line: 2, character: 8}
fullTargets: [{type: list, elements: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, selectionType: line, position: contents, insideOutsideType: null, modifier: {type: identity}, isImplicit: false}, {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: w}, selectionType: line, position: contents, insideOutsideType: null, modifier: {type: identity}, isImplicit: false}]}, {type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}, isImplicit: true}]
7 changes: 1 addition & 6 deletions src/test/suite/fixtures/recorded/actions/bringVest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ command:
targets:
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: v}
- type: primitive
mark: {type: cursor}
selectionType: token
position: contents
modifier: {type: identity}
insideOutsideType: inside
- {type: primitive, isImplicit: true}
initialState:
documentContents: |

Expand Down
7 changes: 1 addition & 6 deletions src/test/suite/fixtures/recorded/actions/callFine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ command:
targets:
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
- type: primitive
mark: {type: cursor}
selectionType: token
position: contents
modifier: {type: identity}
insideOutsideType: inside
- {type: primitive, isImplicit: true}
initialState:
documentContents: |-
foo;
Expand Down
7 changes: 1 addition & 6 deletions src/test/suite/fixtures/recorded/actions/callVest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ command:
targets:
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: v}
- type: primitive
mark: {type: cursor}
selectionType: token
position: contents
modifier: {type: identity}
insideOutsideType: inside
- {type: primitive, isImplicit: true}
initialState:
documentContents: |

Expand Down
7 changes: 1 addition & 6 deletions src/test/suite/fixtures/recorded/actions/moveVest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ command:
targets:
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: v}
- type: primitive
mark: {type: cursor}
selectionType: token
position: contents
modifier: {type: identity}
insideOutsideType: inside
- {type: primitive, isImplicit: true}
initialState:
documentContents: |

Expand Down
Loading