Skip to content

Commit

Permalink
Add item scope to java (#2674)
Browse files Browse the repository at this point in the history
```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
  • Loading branch information
AndreasArvidsson authored Jan 14, 2025
1 parent d98bf09 commit 301b2d8
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class MyClass {
String foo, bar;
}
---

[#1 Range] = 1:4-1:20
>----------------<
1| String foo, bar;

[#1 Domain] = 0:22-2:0
>
0| public class MyClass {
1| String foo, bar;
2| }
<


[#2 Range] = 1:4-1:20
>----------------<
1| String foo, bar;

[#2 Domain] = 1:0-1:20
>--------------------<
1| String foo, bar;


[#3 Range] = 1:11-1:19
>--------<
1| String foo, bar;

[#3 Domain] = 1:4-1:20
>----------------<
1| String foo, bar;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
public class MyClass {
public void myFunk() {
String foo, bar;
}
}
---

[#1 Range] = 1:4-3:5
>----------------------
1| public void myFunk() {
2| String foo, bar;
3| }
-----<

[#1 Domain] = 0:22-4:0
>
0| public class MyClass {
1| public void myFunk() {
2| String foo, bar;
3| }
4| }
<


[#2 Range] =
[#2 Domain] = 1:23-1:23
><
1| public void myFunk() {


[#3 Range] = 2:8-2:24
>----------------<
2| String foo, bar;

[#3 Domain] = 1:26-3:4
>
1| public void myFunk() {
2| String foo, bar;
3| }
----<


[#4 Range] = 2:8-2:24
>----------------<
2| String foo, bar;

[#4 Domain] = 2:0-2:24
>------------------------<
2| String foo, bar;


[#5 Range] = 2:15-2:23
>--------<
2| String foo, bar;

[#5 Domain] = 2:8-2:24
>----------------<
2| String foo, bar;
67 changes: 67 additions & 0 deletions data/fixtures/scopes/java/collectionItem.unenclosed.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
public class MyClass {
String foo, bar;
}
---

[#1 Content] =
[#1 Domain] = 1:4-1:14
>----------<
1| String foo, bar;

[#1 Removal] = 1:4-1:16
>------------<
1| String foo, bar;

[#1 Trailing delimiter] = 1:14-1:16
>--<
1| String foo, bar;

[#1 Insertion delimiter] = ",\n"


[#2 Content] =
[#2 Domain] = 1:11-1:14
>---<
1| String foo, bar;

[#2 Removal] = 1:11-1:16
>-----<
1| String foo, bar;

[#2 Trailing delimiter] = 1:14-1:16
>--<
1| String foo, bar;

[#2 Insertion delimiter] = ", "


[#3 Content] =
[#3 Domain] = 1:16-1:19
>---<
1| String foo, bar;

[#3 Removal] = 1:14-1:19
>-----<
1| String foo, bar;

[#3 Leading delimiter] = 1:14-1:16
>--<
1| String foo, bar;

[#3 Insertion delimiter] = ", "


[#4 Content] =
[#4 Domain] = 1:16-1:20
>----<
1| String foo, bar;

[#4 Removal] = 1:14-1:20
>------<
1| String foo, bar;

[#4 Leading delimiter] = 1:14-1:16
>--<
1| String foo, bar;

[#4 Insertion delimiter] = ",\n"
91 changes: 91 additions & 0 deletions data/fixtures/scopes/java/collectionItem.unenclosed2.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
public class MyClass {
public void myFunk() {
String foo, bar;
}
}
---

[#1 Content] =
[#1 Domain] = 1:4-3:5
>----------------------
1| public void myFunk() {
2| String foo, bar;
3| }
-----<

[#1 Removal] = 1:0-3:5
>--------------------------
1| public void myFunk() {
2| String foo, bar;
3| }
-----<

[#1 Leading delimiter] = 1:0-1:4
>----<
1| public void myFunk() {

[#1 Insertion delimiter] = ",\n"


[#2 Content] =
[#2 Domain] = 2:8-2:18
>----------<
2| String foo, bar;

[#2 Removal] = 2:8-2:20
>------------<
2| String foo, bar;

[#2 Trailing delimiter] = 2:18-2:20
>--<
2| String foo, bar;

[#2 Insertion delimiter] = ",\n"


[#3 Content] =
[#3 Domain] = 2:15-2:18
>---<
2| String foo, bar;

[#3 Removal] = 2:15-2:20
>-----<
2| String foo, bar;

[#3 Trailing delimiter] = 2:18-2:20
>--<
2| String foo, bar;

[#3 Insertion delimiter] = ", "


[#4 Content] =
[#4 Domain] = 2:20-2:23
>---<
2| String foo, bar;

[#4 Removal] = 2:18-2:23
>-----<
2| String foo, bar;

[#4 Leading delimiter] = 2:18-2:20
>--<
2| String foo, bar;

[#4 Insertion delimiter] = ", "


[#5 Content] =
[#5 Domain] = 2:20-2:24
>----<
2| String foo, bar;

[#5 Removal] = 2:18-2:24
>------<
2| String foo, bar;

[#5 Leading delimiter] = 2:18-2:20
>--<
2| String foo, bar;

[#5 Insertion delimiter] = ",\n"
13 changes: 8 additions & 5 deletions packages/common/src/scopeSupportFacets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = {
"argument.actual": supported,
"argument.actual.iteration": supported,

element: notApplicable,
tags: notApplicable,
attribute: notApplicable,
"key.attribute": notApplicable,
"value.attribute": notApplicable,
"collectionItem.unenclosed": supported,
"collectionItem.unenclosed.iteration": supported,

"branch.if": supported,
"branch.if.iteration": supported,
"branch.try": supported,
"branch.try.iteration": supported,

element: notApplicable,
tags: notApplicable,
attribute: notApplicable,
"key.attribute": notApplicable,
"value.attribute": notApplicable,
};
44 changes: 44 additions & 0 deletions queries/java.scm
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,57 @@
value: (_)? @value @name.trailing.startOf
)
) @_.domain

(field_declaration
(variable_declarator
name: (_) @name @value.leading.endOf
value: (_)? @value @name.trailing.startOf
)
) @_.domain

;;!! int foo, bar;
;;! ^^^ ^^^
(
(local_variable_declaration
type: (_)
(variable_declarator)? @_.leading.endOf
.
(variable_declarator) @collectionItem
.
(variable_declarator)? @_.trailing.startOf
)
(#insertion-delimiter! @collectionItem ", ")
)

(
(field_declaration
type: (_)
(variable_declarator)? @_.leading.endOf
.
(variable_declarator) @collectionItem
.
(variable_declarator)? @_.trailing.startOf
)
(#insertion-delimiter! @collectionItem ", ")
)

;;!! int foo, bar;
;;! ^^^^^^^^
;;! -------------
(local_variable_declaration
type: (_)
.
(_) @collectionItem.iteration.start.startOf
";"? @collectionItem.iteration.end.startOf
) @collectionItem.iteration.domain

(field_declaration
type: (_)
.
(_) @collectionItem.iteration.start.startOf
";"? @collectionItem.iteration.end.startOf
) @collectionItem.iteration.domain

;;!! value = 1;
;;! ^
;;! xxxx
Expand Down

0 comments on commit 301b2d8

Please sign in to comment.