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

Don't do inference from end to start #143

Merged
merged 4 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 2 additions & 23 deletions src/inferFullTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,36 +290,16 @@ export function inferSingleNonListTarget(

function inferRangeStartSelectionType(
context: InferenceContext,
endTarget: PartialPrimitiveTarget,
prototypeTargets: Target[],
inferredMark: Mark
): SelectionType {
if (
endTarget.position !== "before" &&
endTarget.position !== "after" &&
endTarget.selectionType != null
) {
return endTarget.selectionType;
}

return getPrimitiveSelectionType(context, inferredMark, prototypeTargets);
}

function inferRangeStartModifier(
target: PartialPrimitiveTarget,
endTarget: PartialPrimitiveTarget,
prototypeTargets: Target[]
): Modifier {
if (
endTarget.position !== "before" &&
endTarget.position !== "after" &&
endTarget.modifier != null &&
target.mark == null &&
endTarget.modifier.type === "containingScope"
) {
return endTarget.modifier;
}

return (
extractAttributeFromList(prototypeTargets, "modifier") ?? {
type: "identity",
Expand Down Expand Up @@ -357,13 +337,12 @@ function inferRangeStartTarget(

const selectionType =
target.selectionType ??
inferRangeStartSelectionType(context, endTarget, prototypeTargets, mark);
inferRangeStartSelectionType(context, prototypeTargets, mark);

const position: Position = target.position ?? "contents";

const modifier =
target.modifier ??
inferRangeStartModifier(target, endTarget, prototypeTargets);
target.modifier ?? inferRangeStartModifier(target, prototypeTargets);

const insideOutsideType =
target.insideOutsideType ??
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
spokenForm: take after vest past air
languageId: typescript
command:
actionName: setSelection
partialTargets:
- type: range
start:
type: primitive
position: after
mark: {type: decoratedSymbol, symbolColor: default, character: v}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: a}
excludeStart: false
excludeEnd: false
extraArgs: []
marks:
default.v:
start: {line: 1, character: 6}
end: {line: 1, character: 11}
default.a:
start: {line: 3, character: 6}
end: {line: 3, character: 11}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 11}
active: {line: 3, character: 11}
thatMark:
- anchor: {line: 1, character: 11}
active: {line: 3, character: 11}
fullTargets: [{type: range, excludeStart: false, excludeEnd: false, start: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: v}, selectionType: token, position: after, modifier: {type: identity}, insideOutsideType: inside}, end: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, modifier: {type: identity}, insideOutsideType: inside}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
spokenForm: take after vest past before air
languageId: typescript
command:
actionName: setSelection
partialTargets:
- type: range
start:
type: primitive
position: after
mark: {type: decoratedSymbol, symbolColor: default, character: v}
end:
type: primitive
position: before
mark: {type: decoratedSymbol, symbolColor: default, character: a}
excludeStart: false
excludeEnd: false
extraArgs: []
marks:
default.v:
start: {line: 1, character: 6}
end: {line: 1, character: 11}
default.a:
start: {line: 3, character: 6}
end: {line: 3, character: 11}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 11}
active: {line: 3, character: 6}
thatMark:
- anchor: {line: 1, character: 11}
active: {line: 3, character: 6}
fullTargets: [{type: range, excludeStart: false, excludeEnd: false, start: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: v}, selectionType: token, position: after, modifier: {type: identity}, insideOutsideType: inside}, end: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: before, modifier: {type: identity}, insideOutsideType: inside}}]
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ command:
extraArgs: []
marks:
default.a:
start: {line: 1, character: 6}
end: {line: 1, character: 11}
start: {line: 3, character: 6}
end: {line: 3, character: 11}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 3, character: 6}
active: {line: 3, character: 6}
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 6}
active: {line: 1, character: 28}
- anchor: {line: 3, character: 6}
active: {line: 3, character: 28}
thatMark:
- anchor: {line: 1, character: 6}
active: {line: 1, character: 28}
- anchor: {line: 3, character: 6}
active: {line: 3, character: 28}
fullTargets: [{type: range, excludeStart: false, excludeEnd: false, start: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, modifier: {type: identity}, insideOutsideType: inside}, end: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: line, position: after, modifier: {type: identity}, insideOutsideType: inside}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
spokenForm: take harp and string each
languageId: typescript
command:
actionName: setSelection
partialTargets:
- type: list
elements:
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: h}
- type: primitive
modifier: {type: containingScope, scopeType: string}
mark: {type: decoratedSymbol, symbolColor: default, character: e}
extraArgs: []
marks:
default.h:
start: {line: 1, character: 15}
end: {line: 1, character: 20}
default.e:
start: {line: 3, character: 15}
end: {line: 3, character: 20}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 20}
- anchor: {line: 3, character: 14}
active: {line: 3, character: 27}
thatMark:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 20}
- anchor: {line: 3, character: 14}
active: {line: 3, character: 27}
fullTargets: [{type: list, elements: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, selectionType: token, position: contents, modifier: {type: identity}, insideOutsideType: inside}, {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: e}, selectionType: token, position: contents, modifier: {type: containingScope, scopeType: string}, insideOutsideType: inside}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
spokenForm: take harp past string each
languageId: typescript
command:
actionName: setSelection
partialTargets:
- type: range
start:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: h}
end:
type: primitive
modifier: {type: containingScope, scopeType: string}
mark: {type: decoratedSymbol, symbolColor: default, character: e}
excludeStart: false
excludeEnd: false
extraArgs: []
marks:
default.h:
start: {line: 1, character: 15}
end: {line: 1, character: 20}
default.e:
start: {line: 3, character: 15}
end: {line: 3, character: 20}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 15}
active: {line: 3, character: 27}
thatMark:
- anchor: {line: 1, character: 15}
active: {line: 3, character: 27}
fullTargets: [{type: range, excludeStart: false, excludeEnd: false, start: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, selectionType: token, position: contents, modifier: {type: identity}, insideOutsideType: inside}, end: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: e}, selectionType: token, position: contents, modifier: {type: containingScope, scopeType: string}, insideOutsideType: inside}}]
45 changes: 45 additions & 0 deletions src/test/suite/fixtures/recorded/inference/takeLineVestPastAir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
spokenForm: take line vest past air
languageId: typescript
command:
actionName: setSelection
partialTargets:
- type: range
start:
type: primitive
selectionType: line
mark: {type: decoratedSymbol, symbolColor: default, character: v}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: a}
excludeStart: false
excludeEnd: false
extraArgs: []
marks:
default.v:
start: {line: 1, character: 6}
end: {line: 1, character: 11}
default.a:
start: {line: 3, character: 6}
end: {line: 3, character: 11}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 0}
active: {line: 3, character: 28}
thatMark:
- anchor: {line: 1, character: 0}
active: {line: 3, character: 28}
fullTargets: [{type: range, excludeStart: false, excludeEnd: false, start: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: v}, selectionType: line, position: contents, modifier: {type: identity}, insideOutsideType: inside}, end: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: line, position: contents, modifier: {type: identity}, insideOutsideType: inside}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
spokenForm: take string harp past each
languageId: typescript
command:
actionName: setSelection
partialTargets:
- type: range
start:
type: primitive
modifier: {type: containingScope, scopeType: string}
mark: {type: decoratedSymbol, symbolColor: default, character: h}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: e}
excludeStart: false
excludeEnd: false
extraArgs: []
marks:
default.h:
start: {line: 1, character: 15}
end: {line: 1, character: 20}
default.e:
start: {line: 3, character: 15}
end: {line: 3, character: 20}
initialState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
finalState:
documentContents: |

const value = "Hello world";

const value = "Hello world";
selections:
- anchor: {line: 1, character: 14}
active: {line: 3, character: 27}
thatMark:
- anchor: {line: 1, character: 14}
active: {line: 3, character: 27}
fullTargets: [{type: range, excludeStart: false, excludeEnd: false, start: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, selectionType: token, position: contents, modifier: {type: containingScope, scopeType: string}, insideOutsideType: inside}, end: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: e}, selectionType: token, position: contents, modifier: {type: containingScope, scopeType: string}, insideOutsideType: inside}}]
Loading