Skip to content

Commit 301b2d8

Browse files
Add item scope to java (#2674)
```java int[] values = {1, 2, 3}; ``` This example is problematic. Currently we test the language specific implementation before the text based one. This means that if your cursor is inside the curly brackets `item` is `values = {1, 2, 3}`. I don't think this can be solved until we have a better `oneOf` implementation of collection item. Same problem with JS #2675 ## 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 d98bf09 commit 301b2d8

File tree

6 files changed

+301
-5
lines changed

6 files changed

+301
-5
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public class MyClass {
2+
String foo, bar;
3+
}
4+
---
5+
6+
[#1 Range] = 1:4-1:20
7+
>----------------<
8+
1| String foo, bar;
9+
10+
[#1 Domain] = 0:22-2:0
11+
>
12+
0| public class MyClass {
13+
1| String foo, bar;
14+
2| }
15+
<
16+
17+
18+
[#2 Range] = 1:4-1:20
19+
>----------------<
20+
1| String foo, bar;
21+
22+
[#2 Domain] = 1:0-1:20
23+
>--------------------<
24+
1| String foo, bar;
25+
26+
27+
[#3 Range] = 1:11-1:19
28+
>--------<
29+
1| String foo, bar;
30+
31+
[#3 Domain] = 1:4-1:20
32+
>----------------<
33+
1| String foo, bar;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
public class MyClass {
2+
public void myFunk() {
3+
String foo, bar;
4+
}
5+
}
6+
---
7+
8+
[#1 Range] = 1:4-3:5
9+
>----------------------
10+
1| public void myFunk() {
11+
2| String foo, bar;
12+
3| }
13+
-----<
14+
15+
[#1 Domain] = 0:22-4:0
16+
>
17+
0| public class MyClass {
18+
1| public void myFunk() {
19+
2| String foo, bar;
20+
3| }
21+
4| }
22+
<
23+
24+
25+
[#2 Range] =
26+
[#2 Domain] = 1:23-1:23
27+
><
28+
1| public void myFunk() {
29+
30+
31+
[#3 Range] = 2:8-2:24
32+
>----------------<
33+
2| String foo, bar;
34+
35+
[#3 Domain] = 1:26-3:4
36+
>
37+
1| public void myFunk() {
38+
2| String foo, bar;
39+
3| }
40+
----<
41+
42+
43+
[#4 Range] = 2:8-2:24
44+
>----------------<
45+
2| String foo, bar;
46+
47+
[#4 Domain] = 2:0-2:24
48+
>------------------------<
49+
2| String foo, bar;
50+
51+
52+
[#5 Range] = 2:15-2:23
53+
>--------<
54+
2| String foo, bar;
55+
56+
[#5 Domain] = 2:8-2:24
57+
>----------------<
58+
2| String foo, bar;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
public class MyClass {
2+
String foo, bar;
3+
}
4+
---
5+
6+
[#1 Content] =
7+
[#1 Domain] = 1:4-1:14
8+
>----------<
9+
1| String foo, bar;
10+
11+
[#1 Removal] = 1:4-1:16
12+
>------------<
13+
1| String foo, bar;
14+
15+
[#1 Trailing delimiter] = 1:14-1:16
16+
>--<
17+
1| String foo, bar;
18+
19+
[#1 Insertion delimiter] = ",\n"
20+
21+
22+
[#2 Content] =
23+
[#2 Domain] = 1:11-1:14
24+
>---<
25+
1| String foo, bar;
26+
27+
[#2 Removal] = 1:11-1:16
28+
>-----<
29+
1| String foo, bar;
30+
31+
[#2 Trailing delimiter] = 1:14-1:16
32+
>--<
33+
1| String foo, bar;
34+
35+
[#2 Insertion delimiter] = ", "
36+
37+
38+
[#3 Content] =
39+
[#3 Domain] = 1:16-1:19
40+
>---<
41+
1| String foo, bar;
42+
43+
[#3 Removal] = 1:14-1:19
44+
>-----<
45+
1| String foo, bar;
46+
47+
[#3 Leading delimiter] = 1:14-1:16
48+
>--<
49+
1| String foo, bar;
50+
51+
[#3 Insertion delimiter] = ", "
52+
53+
54+
[#4 Content] =
55+
[#4 Domain] = 1:16-1:20
56+
>----<
57+
1| String foo, bar;
58+
59+
[#4 Removal] = 1:14-1:20
60+
>------<
61+
1| String foo, bar;
62+
63+
[#4 Leading delimiter] = 1:14-1:16
64+
>--<
65+
1| String foo, bar;
66+
67+
[#4 Insertion delimiter] = ",\n"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
public class MyClass {
2+
public void myFunk() {
3+
String foo, bar;
4+
}
5+
}
6+
---
7+
8+
[#1 Content] =
9+
[#1 Domain] = 1:4-3:5
10+
>----------------------
11+
1| public void myFunk() {
12+
2| String foo, bar;
13+
3| }
14+
-----<
15+
16+
[#1 Removal] = 1:0-3:5
17+
>--------------------------
18+
1| public void myFunk() {
19+
2| String foo, bar;
20+
3| }
21+
-----<
22+
23+
[#1 Leading delimiter] = 1:0-1:4
24+
>----<
25+
1| public void myFunk() {
26+
27+
[#1 Insertion delimiter] = ",\n"
28+
29+
30+
[#2 Content] =
31+
[#2 Domain] = 2:8-2:18
32+
>----------<
33+
2| String foo, bar;
34+
35+
[#2 Removal] = 2:8-2:20
36+
>------------<
37+
2| String foo, bar;
38+
39+
[#2 Trailing delimiter] = 2:18-2:20
40+
>--<
41+
2| String foo, bar;
42+
43+
[#2 Insertion delimiter] = ",\n"
44+
45+
46+
[#3 Content] =
47+
[#3 Domain] = 2:15-2:18
48+
>---<
49+
2| String foo, bar;
50+
51+
[#3 Removal] = 2:15-2:20
52+
>-----<
53+
2| String foo, bar;
54+
55+
[#3 Trailing delimiter] = 2:18-2:20
56+
>--<
57+
2| String foo, bar;
58+
59+
[#3 Insertion delimiter] = ", "
60+
61+
62+
[#4 Content] =
63+
[#4 Domain] = 2:20-2:23
64+
>---<
65+
2| String foo, bar;
66+
67+
[#4 Removal] = 2:18-2:23
68+
>-----<
69+
2| String foo, bar;
70+
71+
[#4 Leading delimiter] = 2:18-2:20
72+
>--<
73+
2| String foo, bar;
74+
75+
[#4 Insertion delimiter] = ", "
76+
77+
78+
[#5 Content] =
79+
[#5 Domain] = 2:20-2:24
80+
>----<
81+
2| String foo, bar;
82+
83+
[#5 Removal] = 2:18-2:24
84+
>------<
85+
2| String foo, bar;
86+
87+
[#5 Leading delimiter] = 2:18-2:20
88+
>--<
89+
2| String foo, bar;
90+
91+
[#5 Insertion delimiter] = ",\n"

packages/common/src/scopeSupportFacets/java.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = {
2121
"argument.actual": supported,
2222
"argument.actual.iteration": supported,
2323

24-
element: notApplicable,
25-
tags: notApplicable,
26-
attribute: notApplicable,
27-
"key.attribute": notApplicable,
28-
"value.attribute": notApplicable,
24+
"collectionItem.unenclosed": supported,
25+
"collectionItem.unenclosed.iteration": supported,
2926

3027
"branch.if": supported,
3128
"branch.if.iteration": supported,
3229
"branch.try": supported,
3330
"branch.try.iteration": supported,
31+
32+
element: notApplicable,
33+
tags: notApplicable,
34+
attribute: notApplicable,
35+
"key.attribute": notApplicable,
36+
"value.attribute": notApplicable,
3437
};

queries/java.scm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,57 @@
316316
value: (_)? @value @name.trailing.startOf
317317
)
318318
) @_.domain
319+
319320
(field_declaration
320321
(variable_declarator
321322
name: (_) @name @value.leading.endOf
322323
value: (_)? @value @name.trailing.startOf
323324
)
324325
) @_.domain
325326

327+
;;!! int foo, bar;
328+
;;! ^^^ ^^^
329+
(
330+
(local_variable_declaration
331+
type: (_)
332+
(variable_declarator)? @_.leading.endOf
333+
.
334+
(variable_declarator) @collectionItem
335+
.
336+
(variable_declarator)? @_.trailing.startOf
337+
)
338+
(#insertion-delimiter! @collectionItem ", ")
339+
)
340+
341+
(
342+
(field_declaration
343+
type: (_)
344+
(variable_declarator)? @_.leading.endOf
345+
.
346+
(variable_declarator) @collectionItem
347+
.
348+
(variable_declarator)? @_.trailing.startOf
349+
)
350+
(#insertion-delimiter! @collectionItem ", ")
351+
)
352+
353+
;;!! int foo, bar;
354+
;;! ^^^^^^^^
355+
;;! -------------
356+
(local_variable_declaration
357+
type: (_)
358+
.
359+
(_) @collectionItem.iteration.start.startOf
360+
";"? @collectionItem.iteration.end.startOf
361+
) @collectionItem.iteration.domain
362+
363+
(field_declaration
364+
type: (_)
365+
.
366+
(_) @collectionItem.iteration.start.startOf
367+
";"? @collectionItem.iteration.end.startOf
368+
) @collectionItem.iteration.domain
369+
326370
;;!! value = 1;
327371
;;! ^
328372
;;! xxxx

0 commit comments

Comments
 (0)