Skip to content

Add extension side of "subject" scope type #1148

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 13 commits into from
Dec 15, 2022
Merged
1 change: 1 addition & 0 deletions schemas/cursorless-snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"regularExpression",
"statement",
"string",
"switchStatementSubject",
"type",
"value",
"condition",
Expand Down
1 change: 1 addition & 0 deletions src/core/commandRunner/typings/targetDescriptor.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export type SimpleScopeTypeType =
| "sectionLevelFive"
| "sectionLevelSix"
| "selector"
| "switchStatementSubject"
| "unit"
| "xmlBothTags"
| "xmlElement"
Expand Down
1 change: 1 addition & 0 deletions src/languages/cpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const nodeMatchers: Partial<
"function_definition[declarator][declarator][namespace]", // void ClassName::method() {}
],
ifStatement: "if_statement",
switchStatementSubject: "switch_statement[condition][value]",
string: "string_literal",
comment: "comment",
anonymousFunction: "lambda_expression",
Expand Down
4 changes: 4 additions & 0 deletions src/languages/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ const nodeMatchers: Partial<
conditionMatcher("*[condition]"),
patternMatcher("while_statement[0]"),
),
switchStatementSubject: [
"switch_statement.tuple_expression!",
"switch_statement[value]",
],
statement: STATEMENT_TYPES,
anonymousFunction: "lambda_expression",
functionCall: ["invocation_expression", "object_creation_expression"],
Expand Down
1 change: 1 addition & 0 deletions src/languages/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const nodeMatchers: Partial<
),
condition: conditionMatcher("*[condition]"),
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
switchStatementSubject: "switch_expression[condition][0]",
};

export default createPatternMatchers(nodeMatchers);
1 change: 1 addition & 0 deletions src/languages/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const nodeMatchers: Partial<
argumentMatcher("parameters", "argument_list"),
matcher(patternFinder("call.generator_expression!"), childRangeSelector()),
),
switchStatementSubject: "match_statement[subject]",
};

export default createPatternMatchers(nodeMatchers);
1 change: 1 addition & 0 deletions src/languages/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const nodeMatchers: Partial<
matcher(returnValueFinder),
),
attribute: trailingMatcher(["mutable_specifier", "attribute_item"]),
switchStatementSubject: "match_expression[value]",
};

export default createPatternMatchers(nodeMatchers);
1 change: 1 addition & 0 deletions src/languages/scala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const nodeMatchers: Partial<
"bindings",
),

switchStatementSubject: "match_expression[value]",
name: ["*[name]", "*[pattern]"],
functionName: "function_definition[name]",

Expand Down
5 changes: 5 additions & 0 deletions src/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
pairSelectionExtractor,
selectWithLeadingDelimiter,
simpleSelectionExtractor,
unwrapSelectionExtractor,
xmlElementExtractor,
} from "../util/nodeSelectors";

Expand Down Expand Up @@ -223,6 +224,10 @@ const nodeMatchers: Partial<
"do_statement[condition]",
),
),
switchStatementSubject: matcher(
patternFinder("switch_statement[value]"),
unwrapSelectionExtractor,
),
class: [
"export_statement?.class_declaration", // export class | class
"export_statement?.abstract_class_declaration", // export abstract class | abstract class
Expand Down
35 changes: 35 additions & 0 deletions src/test/suite/fixtures/recorded/languages/cpp/clearSubject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
languageId: cpp
command:
version: 3
spokenForm: clear subject
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
initialState:
documentContents: |
int main() {
switch (i) {
default:
break;
}
}
selections:
- anchor: {line: 3, character: 4}
active: {line: 3, character: 4}
marks: {}
finalState:
documentContents: |
int main() {
switch () {
default:
break;
}
}
selections:
- anchor: {line: 1, character: 10}
active: {line: 1, character: 10}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
languageId: cpp
command:
version: 3
spokenForm: clear subject
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: false
initialState:
documentContents: |
int main() {
switch (int i = rand() % 100; i) {
default:
break;
}
}
selections:
- anchor: {line: 3, character: 4}
active: {line: 3, character: 4}
marks: {}
finalState:
documentContents: |
int main() {
switch (int i = rand() % 100; ) {
default:
break;
}
}
selections:
- anchor: {line: 1, character: 32}
active: {line: 1, character: 32}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: csharp
command:
version: 3
spokenForm: clear subject
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
switch (aaa) {
default:
break;
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
marks: {}
finalState:
documentContents: |-
switch () {
default:
break;
}
selections:
- anchor: {line: 0, character: 8}
active: {line: 0, character: 8}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: csharp
command:
version: 3
spokenForm: clear subject
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: false
initialState:
documentContents: |-
switch (aaa + 1) {
default:
break;
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
marks: {}
finalState:
documentContents: |-
switch () {
default:
break;
}
selections:
- anchor: {line: 0, character: 8}
active: {line: 0, character: 8}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
languageId: java
command:
spokenForm: clear subject
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |
class Aaa {

static void bbb() {
switch ("0") {
case ("0"):
break;
}
}
}
selections:
- anchor: {line: 4, character: 17}
active: {line: 4, character: 17}
marks: {}
finalState:
documentContents: |
class Aaa {

static void bbb() {
switch () {
case ("0"):
break;
}
}
}
selections:
- anchor: {line: 3, character: 12}
active: {line: 3, character: 12}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
languageId: java
command:
spokenForm: clear subject
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |
class Aaa {

static void bbb() {
var s =
switch ("0") {
case "0" -> "zero";
};
}
}
selections:
- anchor: {line: 5, character: 22}
active: {line: 5, character: 22}
marks: {}
finalState:
documentContents: |
class Aaa {

static void bbb() {
var s =
switch () {
case "0" -> "zero";
};
}
}
selections:
- anchor: {line: 4, character: 14}
active: {line: 4, character: 14}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: python
command:
spokenForm: clear subject
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |
match 0:
case [0]:
pass
selections:
- anchor: {line: 2, character: 8}
active: {line: 2, character: 8}
marks: {}
finalState:
documentContents: |
match :
case [0]:
pass
selections:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: rust
command:
spokenForm: change subject
version: 2
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |
match user {
User { first_name: "John" } => {},
User { first_name } if first_name.starts_with("P") => {}
}
selections:
- anchor: {line: 2, character: 27}
active: {line: 2, character: 54}
marks: {}
finalState:
documentContents: |
match {
User { first_name: "John" } => {},
User { first_name } if first_name.starts_with("P") => {}
}
selections:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: scala
command:
spokenForm: clear subject
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: switchStatementSubject}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |
def matchTest(x: Int): String = x match {
case 0 => "zero"
}
selections:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 15}
marks: {}
finalState:
documentContents: |
def matchTest(x: Int): String = match {
case 0 => "zero"
}
selections:
- anchor: {line: 0, character: 32}
active: {line: 0, character: 32}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Loading