diff --git a/src/languages/java.ts b/src/languages/java.ts index 20c93c678c..be406a45c8 100644 --- a/src/languages/java.ts +++ b/src/languages/java.ts @@ -60,6 +60,8 @@ const nodeMatchers: Partial> = { name: ["*[declarator][name]", "*[name]", "formal_parameter.identifier!"], namedFunction: ["method_declaration", "constructor_declaration"], type: trailingMatcher([ + "generic_type.type_arguments.type_identifier", + "generic_type.type_identifier", "type_identifier", "local_variable_declaration[type]", "array_creation_expression[type]", diff --git a/src/languages/typescript.ts b/src/languages/typescript.ts index 102a9087ed..529eebe522 100644 --- a/src/languages/typescript.ts +++ b/src/languages/typescript.ts @@ -9,14 +9,18 @@ import { conditionMatcher, } from "../util/nodeMatchers"; import { + NodeMatcher, NodeMatcherAlternative, + NodeMatcherValue, ScopeType, SelectionWithEditor, } from "../typings/Types"; import { getNodeInternalRange, getNodeRange, + pairSelectionExtractor, selectWithLeadingDelimiter, + simpleSelectionExtractor, } from "../util/nodeSelectors"; import { patternFinder } from "../util/nodeFinders"; @@ -69,12 +73,60 @@ const getTags = (selection: SelectionWithEditor, node: SyntaxNode) => { return startTag != null && endTag != null ? startTag.concat(endTag) : null; }; -const findTypeNode = (node: SyntaxNode) => { - const typeAnnotationNode = node.children.find((child) => - ["type_annotation", "opting_type_annotation"].includes(child.type) - ); - return typeAnnotationNode?.lastChild ?? null; -}; +function typeMatcher(): NodeMatcher { + const delimiterSelector = selectWithLeadingDelimiter(":"); + return function (selection: SelectionWithEditor, node: SyntaxNode) { + if ( + node.parent?.type === "new_expression" && + node.type !== "new" && + node.type !== "arguments" + ) { + const identifierNode = node.parent.children.find( + (n) => n.type === "identifier" + ); + const argsNode = node.parent.children.find( + (n) => n.type === "type_arguments" + ); + if (identifierNode && argsNode) { + return [ + { + node, + selection: pairSelectionExtractor( + selection.editor, + identifierNode, + argsNode + ), + }, + ]; + } else if (identifierNode) { + return [ + { + node: identifierNode, + selection: simpleSelectionExtractor( + selection.editor, + identifierNode + ), + }, + ]; + } + } + + const typeAnnotationNode = node.children.find((child) => + ["type_annotation", "opting_type_annotation"].includes(child.type) + ); + const targetNode = typeAnnotationNode?.lastChild; + + if (targetNode) { + return [ + { + node: targetNode, + selection: delimiterSelector(selection.editor, targetNode), + }, + ]; + } + return null; + }; +} function valueMatcher() { const pFinder = patternFinder("assignment_expression[right]", "*[value]"); @@ -160,7 +212,8 @@ const nodeMatchers: Partial> = { ], type: cascadingMatcher( // Typed parameters, properties, and functions - matcher(findTypeNode, selectWithLeadingDelimiter(":")), + typeMatcher(), + // matcher(findTypeNode, selectWithLeadingDelimiter(":")), // Type alias/interface declarations patternMatcher( "export_statement?.type_alias_declaration", diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeBlueLook.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeBlueLook.yml new file mode 100644 index 0000000000..8295233de7 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeBlueLook.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type blue look + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: blue, character: l} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} + marks: + blue.l: + start: {line: 3, character: 8} + end: {line: 3, character: 12} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} + thatMark: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: blue, character: l}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeGust.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeGust.yml new file mode 100644 index 0000000000..6decc8a30b --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeGust.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type gust + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: g} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} + marks: + default.g: + start: {line: 3, character: 13} + end: {line: 3, character: 19} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} + thatMark: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: g}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeGust2.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeGust2.yml new file mode 100644 index 0000000000..e9b80be240 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeGust2.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type gust + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: g} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 32} + active: {line: 3, character: 49} + marks: + default.g: + start: {line: 3, character: 42} + end: {line: 3, character: 48} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 32} + active: {line: 3, character: 49} + thatMark: + - anchor: {line: 3, character: 32} + active: {line: 3, character: 49} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: g}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeHarp.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeHarp.yml new file mode 100644 index 0000000000..86a5902a55 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeHarp.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type harp + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: h} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} + marks: + default.h: + start: {line: 2, character: 38} + end: {line: 2, character: 45} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} + thatMark: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeLook.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeLook.yml new file mode 100644 index 0000000000..5d3ae49e42 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeLook.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type look + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: l} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 27} + active: {line: 2, character: 27} + marks: + default.l: + start: {line: 3, character: 21} + end: {line: 3, character: 25} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} + thatMark: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: l}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypePit.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypePit.yml new file mode 100644 index 0000000000..bf55f6f07d --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypePit.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type pit + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: p} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 52} + active: {line: 3, character: 52} + marks: + default.p: + start: {line: 2, character: 8} + end: {line: 2, character: 11} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} + thatMark: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: p}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeSoon.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeSoon.yml new file mode 100644 index 0000000000..306f5b92a0 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeSoon.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type soon + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: s} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} + marks: + default.s: + start: {line: 2, character: 12} + end: {line: 2, character: 18} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} + thatMark: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: s}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeSoon2.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeSoon2.yml new file mode 100644 index 0000000000..d18040e375 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeSoon2.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type soon + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: s} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} + marks: + default.s: + start: {line: 2, character: 54} + end: {line: 2, character: 60} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} + thatMark: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: s}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeTrap.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeTrap.yml new file mode 100644 index 0000000000..07ff1ad9ae --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeTrap.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type trap + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: t} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} + marks: + default.t: + start: {line: 2, character: 20} + end: {line: 2, character: 26} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} + thatMark: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 27} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: t}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeTrap2.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeTrap2.yml new file mode 100644 index 0000000000..1b5bb1f774 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeTrap2.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type trap + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: t} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} + marks: + default.t: + start: {line: 2, character: 46} + end: {line: 2, character: 52} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} + thatMark: + - anchor: {line: 2, character: 38} + active: {line: 2, character: 61} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: t}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/java/takeTypeYank.yml b/src/test/suite/fixtures/recorded/languages/java/takeTypeYank.yml new file mode 100644 index 0000000000..afd86d27d1 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/java/takeTypeYank.yml @@ -0,0 +1,39 @@ +languageId: java +command: + version: 1 + spokenForm: take type yank + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: 'y'} +initialState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 20} + marks: + default.y: + start: {line: 3, character: 32} + end: {line: 3, character: 41} +finalState: + documentContents: |- + public class MyClass { + private MyClass () { + Map map = new HashMap(); + List list = new ArrayList(); + } + } + selections: + - anchor: {line: 3, character: 32} + active: {line: 3, character: 49} + thatMark: + - anchor: {line: 3, character: 32} + active: {line: 3, character: 49} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: 'y'}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearType.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearType.yml new file mode 100644 index 0000000000..9df6f8aa17 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearType.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} +initialState: + documentContents: "function whatever(): string {}" + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} + marks: {} +finalState: + documentContents: "function whatever(): {}" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + thatMark: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} +fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearType2.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearType2.yml new file mode 100644 index 0000000000..649687023b --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearType2.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 0 + spokenForm: clear type + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} +initialState: + documentContents: "const foo: string = new Bar()" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + marks: {} +finalState: + documentContents: "const foo: string = new ()" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + thatMark: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} +fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeAir.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeAir.yml new file mode 100644 index 0000000000..9e6efee140 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeAir.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type air + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: a} +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.a: + start: {line: 0, character: 24} + end: {line: 0, character: 27} +finalState: + documentContents: "const foo: string = new (foo);" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + thatMark: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeBat.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeBat.yml new file mode 100644 index 0000000000..4ec7176f0e --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeBat.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type bat + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: b} +initialState: + documentContents: "const foo: Bar = bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.b: + start: {line: 0, character: 25} + end: {line: 0, character: 28} +finalState: + documentContents: "const foo: = bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeLangle.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeLangle.yml new file mode 100644 index 0000000000..af9f4c5529 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeLangle.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type langle + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: <} +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.<: + start: {line: 0, character: 27} + end: {line: 0, character: 28} +finalState: + documentContents: "const foo: string = new (foo);" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + thatMark: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: <, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml new file mode 100644 index 0000000000..95c88a3b30 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type near + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: 'n'} +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.n: + start: {line: 0, character: 28} + end: {line: 0, character: 34} +finalState: + documentContents: "const foo: string = new (foo);" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + thatMark: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: 'n', usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml new file mode 100644 index 0000000000..77cac47aba --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type near + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: 'n'} +initialState: + documentContents: "const foo: string = bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.n: + start: {line: 0, character: 24} + end: {line: 0, character: 30} +finalState: + documentContents: "const foo: = bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: 'n', usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeOx.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeOx.yml new file mode 100644 index 0000000000..44e7284074 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeOx.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type ox + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: o} +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.o: + start: {line: 0, character: 36} + end: {line: 0, character: 39} +finalState: + documentContents: "const foo: = new Bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: o, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeOx2.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeOx2.yml new file mode 100644 index 0000000000..f3ed985e1f --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeOx2.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type ox + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: o} +initialState: + documentContents: "const foo: string = bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.o: + start: {line: 0, character: 32} + end: {line: 0, character: 35} +finalState: + documentContents: "const foo: = bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: o, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml new file mode 100644 index 0000000000..7e9cef82b1 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type urge + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: u} +initialState: + documentContents: "const foo: Bar = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.u: + start: {line: 0, character: 15} + end: {line: 0, character: 21} +finalState: + documentContents: "const foo: = new Bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: u, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeWhale.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeWhale.yml new file mode 100644 index 0000000000..569a997857 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeWhale.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type whale + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: w} +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.w: + start: {line: 0, character: 20} + end: {line: 0, character: 23} +finalState: + documentContents: "const foo: = new Bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + thatMark: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: w, usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/languages/typescript/clearTypeWrangle.yml b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeWrangle.yml new file mode 100644 index 0000000000..e1efb6ab34 --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/typescript/clearTypeWrangle.yml @@ -0,0 +1,27 @@ +languageId: typescript +command: + version: 1 + spokenForm: clear type wrangle + action: clearAndSetSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: type, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: '>'} +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: + default.>: + start: {line: 0, character: 34} + end: {line: 0, character: 35} +finalState: + documentContents: "const foo: string = new (foo);" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + thatMark: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '>', usePrePhraseSnapshot: true}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}] diff --git a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair.yml b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair.yml index fa01055470..72ce62b3d8 100644 --- a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair.yml +++ b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair.yml @@ -1,6 +1,6 @@ languageId: json command: - version: 0 + version: 1 spokenForm: clear pair action: clearAndSetSelection targets: diff --git a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair2.yml b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair2.yml index 17d44ab65c..23195956fc 100644 --- a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair2.yml +++ b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearPair2.yml @@ -1,6 +1,6 @@ languageId: json command: - version: 0 + version: 1 spokenForm: clear pair action: clearAndSetSelection targets: diff --git a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound.yml b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound.yml index f9393dd33a..1043f739d1 100644 --- a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound.yml +++ b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound.yml @@ -1,6 +1,6 @@ languageId: json command: - version: 0 + version: 1 spokenForm: clear round action: clearAndSetSelection targets: diff --git a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound2.yml b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound2.yml index c7d2e5540d..273c6ab9cf 100644 --- a/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound2.yml +++ b/src/test/suite/fixtures/recorded/surroundingPair/parseTree/json/clearRound2.yml @@ -1,6 +1,6 @@ languageId: json command: - version: 0 + version: 1 spokenForm: clear round action: clearAndSetSelection targets: diff --git a/src/util/nodeSelectors.ts b/src/util/nodeSelectors.ts index 9293c6782b..5405d38c77 100644 --- a/src/util/nodeSelectors.ts +++ b/src/util/nodeSelectors.ts @@ -54,6 +54,27 @@ export function simpleSelectionExtractor( }; } +/** + * Extracts a selection from the first node to the second node. + * Both nodes are included in the selected nodes +*/ +export function pairSelectionExtractor( + editor: TextEditor, + node1: SyntaxNode, + node2: SyntaxNode +): SelectionWithContext { + const isForward = node1.startIndex < node2.startIndex; + const start = isForward ? node1 : node2; + const end = isForward ? node2 : node1; + return { + selection: new Selection( + new Position(start.startPosition.row, start.startPosition.column), + new Position(end.endPosition.row, end.endPosition.column) + ), + context: {}, + }; +} + export function argumentSelectionExtractor(): SelectionExtractor { return delimitedSelector( (node) =>