Skip to content

Commit 5b22a22

Browse files
Migrate java scopes (#2038)
#Fixes #1926 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet
1 parent 08cd7a1 commit 5b22a22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1382
-172
lines changed

packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ const textFragmentExtractors: Record<
132132
"html",
133133
htmlStringTextFragmentExtractor,
134134
),
135-
java: constructDefaultTextFragmentExtractor(
136-
"java",
137-
constructHackedStringTextFragmentExtractor("java"),
138-
),
139135
javascript: constructDefaultTextFragmentExtractor(
140136
"javascript",
141137
typescriptStringTextFragmentExtractor,
Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,12 @@
1-
import {
2-
createPatternMatchers,
3-
argumentMatcher,
4-
leadingMatcher,
5-
conditionMatcher,
6-
trailingMatcher,
7-
matcher,
8-
cascadingMatcher,
9-
} from "../util/nodeMatchers";
10-
import { childRangeSelector } from "../util/nodeSelectors";
11-
import { patternFinder } from "../util/nodeFinders";
1+
import { argumentMatcher, createPatternMatchers } from "../util/nodeMatchers";
122

13-
import { NodeMatcherAlternative } from "../typings/Types";
143
import { SimpleScopeTypeType } from "@cursorless/common";
15-
16-
// Generated by the following command:
17-
// > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-java/master/src/node-types.json | jq '[.[] | select(.type == "statement" or .type == "declaration") | .subtypes[].type]'
18-
const STATEMENT_TYPES = [
19-
"annotation_type_declaration",
20-
"class_declaration",
21-
"enum_declaration",
22-
"import_declaration",
23-
"interface_declaration",
24-
"module_declaration",
25-
"package_declaration",
26-
"assert_statement",
27-
"break_statement",
28-
"continue_statement",
29-
"declaration",
30-
"do_statement",
31-
"enhanced_for_statement",
32-
"expression_statement",
33-
"for_statement",
34-
"if_statement",
35-
"labeled_statement",
36-
"local_variable_declaration",
37-
"return_statement",
38-
"switch_expression",
39-
"synchronized_statement",
40-
"throw_statement",
41-
"try_statement",
42-
"try_with_resources_statement",
43-
"while_statement",
44-
"yield_statement",
45-
46-
// exceptions
47-
// ";",
48-
// "block",
49-
"switch_statement",
50-
"method_declaration",
51-
"constructor_declaration",
52-
"field_declaration",
53-
];
4+
import { NodeMatcherAlternative } from "../typings/Types";
545

556
const nodeMatchers: Partial<
567
Record<SimpleScopeTypeType, NodeMatcherAlternative>
578
> = {
58-
statement: STATEMENT_TYPES,
59-
class: "class_declaration",
60-
className: "class_declaration[name]",
61-
ifStatement: "if_statement",
62-
string: "string_literal",
63-
comment: ["line_comment", "block_comment", "comment"],
64-
anonymousFunction: "lambda_expression",
65-
list: "array_initializer",
66-
functionCall: [
67-
"method_invocation",
68-
"object_creation_expression",
69-
"explicit_constructor_invocation",
70-
],
71-
functionCallee: cascadingMatcher(
72-
matcher(
73-
patternFinder("method_invocation"),
74-
childRangeSelector(["argument_list"], []),
75-
),
76-
matcher(
77-
patternFinder("object_creation_expression"),
78-
childRangeSelector(["argument_list"], []),
79-
),
80-
matcher(
81-
patternFinder("explicit_constructor_invocation"),
82-
childRangeSelector(["argument_list", ";"], []),
83-
),
84-
),
85-
map: "block",
86-
name: [
87-
"*[declarator][name]",
88-
"assignment_expression[left]",
89-
"*[name]",
90-
"formal_parameter.identifier!",
91-
],
92-
namedFunction: ["method_declaration", "constructor_declaration"],
93-
type: trailingMatcher([
94-
"generic_type.type_arguments.type_identifier",
95-
"generic_type.type_identifier",
96-
"generic_type.scoped_type_identifier.type_identifier",
97-
"type_identifier",
98-
"local_variable_declaration[type]",
99-
"array_creation_expression[type]",
100-
"formal_parameter[type]",
101-
"method_declaration[type]",
102-
]),
103-
functionName: [
104-
"method_declaration.identifier!",
105-
"constructor_declaration.identifier!",
106-
],
107-
value: leadingMatcher(
108-
[
109-
"*[declarator][value]",
110-
"assignment_expression[right]",
111-
"return_statement[0]",
112-
"*[value]",
113-
],
114-
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="],
115-
),
116-
condition: conditionMatcher("*[condition]"),
1179
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
118-
branch: ["switch_block_statement_group", "switch_rule"],
119-
["private.switchStatementSubject"]: "switch_expression[condition][0]",
12010
};
12111

12212
export default createPatternMatchers(nodeMatchers);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: java
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
public class MyClass {
16+
public void myFunk() {
17+
if (true) {
18+
}
19+
else if (false) {
20+
}
21+
else {
22+
}
23+
}
24+
}
25+
selections:
26+
- anchor: {line: 2, character: 4}
27+
active: {line: 2, character: 4}
28+
marks: {}
29+
finalState:
30+
documentContents: |
31+
public class MyClass {
32+
public void myFunk() {
33+
34+
else if (false) {
35+
}
36+
else {
37+
}
38+
}
39+
}
40+
selections:
41+
- anchor: {line: 2, character: 4}
42+
active: {line: 2, character: 4}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: java
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
public class MyClass {
16+
public void myFunk() {
17+
if (true) {
18+
}
19+
else if (false) {
20+
}
21+
else {
22+
}
23+
}
24+
}
25+
selections:
26+
- anchor: {line: 4, character: 4}
27+
active: {line: 4, character: 4}
28+
marks: {}
29+
finalState:
30+
documentContents: |
31+
public class MyClass {
32+
public void myFunk() {
33+
if (true) {
34+
}
35+
36+
else {
37+
}
38+
}
39+
}
40+
selections:
41+
- anchor: {line: 4, character: 4}
42+
active: {line: 4, character: 4}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: java
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
public class MyClass {
16+
public void myFunk() {
17+
if (true) {
18+
}
19+
else if (false) {
20+
}
21+
else {
22+
}
23+
}
24+
}
25+
selections:
26+
- anchor: {line: 6, character: 4}
27+
active: {line: 6, character: 4}
28+
marks: {}
29+
finalState:
30+
documentContents: |
31+
public class MyClass {
32+
public void myFunk() {
33+
if (true) {
34+
}
35+
else if (false) {
36+
}
37+
38+
}
39+
}
40+
selections:
41+
- anchor: {line: 6, character: 4}
42+
active: {line: 6, character: 4}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: java
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
public class MyClass {
16+
public void myFunk() {
17+
true ? 1 : 2
18+
}
19+
}
20+
selections:
21+
- anchor: {line: 2, character: 15}
22+
active: {line: 2, character: 15}
23+
marks: {}
24+
finalState:
25+
documentContents: |-
26+
public class MyClass {
27+
public void myFunk() {
28+
true ? : 2
29+
}
30+
}
31+
selections:
32+
- anchor: {line: 2, character: 15}
33+
active: {line: 2, character: 15}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: java
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
public class MyClass {
16+
public void myFunk() {
17+
true ? 1 : 2
18+
}
19+
}
20+
selections:
21+
- anchor: {line: 2, character: 19}
22+
active: {line: 2, character: 19}
23+
marks: {}
24+
finalState:
25+
documentContents: |-
26+
public class MyClass {
27+
public void myFunk() {
28+
true ? 1 :
29+
}
30+
}
31+
selections:
32+
- anchor: {line: 2, character: 19}
33+
active: {line: 2, character: 19}

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/java/changeCallee.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ initialState:
1313
active: {line: 0, character: 9}
1414
marks: {}
1515
finalState:
16-
documentContents: new ().bar();
16+
documentContents: ().bar();
1717
selections:
18-
- anchor: {line: 0, character: 4}
19-
active: {line: 0, character: 4}
18+
- anchor: {line: 0, character: 0}
19+
active: {line: 0, character: 0}

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/java/changeCallee3.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ initialState:
1313
active: {line: 0, character: 12}
1414
marks: {}
1515
finalState:
16-
documentContents: new ();
16+
documentContents: ();
1717
selections:
18-
- anchor: {line: 0, character: 4}
19-
active: {line: 0, character: 4}
18+
- anchor: {line: 0, character: 0}
19+
active: {line: 0, character: 0}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
languageId: java
2+
command:
3+
version: 6
4+
spokenForm: change condition
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: condition}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
public class MyClass {
16+
public void myFunk() {
17+
if (true) {
18+
}
19+
else if (false) {
20+
}
21+
else {
22+
}
23+
}
24+
}
25+
selections:
26+
- anchor: {line: 2, character: 4}
27+
active: {line: 2, character: 4}
28+
marks: {}
29+
finalState:
30+
documentContents: |
31+
public class MyClass {
32+
public void myFunk() {
33+
if () {
34+
}
35+
else if (false) {
36+
}
37+
else {
38+
}
39+
}
40+
}
41+
selections:
42+
- anchor: {line: 2, character: 8}
43+
active: {line: 2, character: 8}

0 commit comments

Comments
 (0)