From 8ae3b75058a500ff9615ff47f3daeae5c14c07f8 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 9 Nov 2024 11:53:20 +0100 Subject: [PATCH 1/3] Added item scope to java --- .../collectionItem.unenclosed.iteration.scope | 12 +++++ ...collectionItem.unenclosed.iteration2.scope | 14 ++++++ .../java/collectionItem.unenclosed.scope | 35 +++++++++++++++ .../java/collectionItem.unenclosed2.scope | 37 ++++++++++++++++ .../common/src/scopeSupportFacets/java.ts | 13 +++--- queries/java.scm | 44 +++++++++++++++++++ 6 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope create mode 100644 data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope create mode 100644 data/fixtures/scopes/java/collectionItem.unenclosed.scope create mode 100644 data/fixtures/scopes/java/collectionItem.unenclosed2.scope diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope new file mode 100644 index 0000000000..1f0ae8f127 --- /dev/null +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope @@ -0,0 +1,12 @@ +public class MyClass { + String foo, bar; +} +--- + +[Range] = 1:11-1:19 + >--------< +1| String foo, bar; + +[Domain] = 1:4-1:20 + >----------------< +1| String foo, bar; diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope new file mode 100644 index 0000000000..af2605a2aa --- /dev/null +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope @@ -0,0 +1,14 @@ +public class MyClass { + public void myFunk() { + String foo, bar; + } +} +--- + +[Range] = 2:15-2:23 + >--------< +2| String foo, bar; + +[Domain] = 2:8-2:24 + >----------------< +2| String foo, bar; diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.scope new file mode 100644 index 0000000000..7c7a0fa33d --- /dev/null +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.scope @@ -0,0 +1,35 @@ +public class MyClass { + String foo, bar; +} +--- + +[#1 Content] = +[#1 Domain] = 1:11-1:14 + >---< +1| String foo, bar; + +[#1 Removal] = 1:11-1:16 + >-----< +1| String foo, bar; + +[#1 Trailing delimiter] = 1:14-1:16 + >--< +1| String foo, bar; + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 1:16-1:19 + >---< +1| String foo, bar; + +[#2 Removal] = 1:14-1:19 + >-----< +1| String foo, bar; + +[#2 Leading delimiter] = 1:14-1:16 + >--< +1| String foo, bar; + +[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed2.scope b/data/fixtures/scopes/java/collectionItem.unenclosed2.scope new file mode 100644 index 0000000000..b821c3407f --- /dev/null +++ b/data/fixtures/scopes/java/collectionItem.unenclosed2.scope @@ -0,0 +1,37 @@ +public class MyClass { + public void myFunk() { + String foo, bar; + } +} +--- + +[#1 Content] = +[#1 Domain] = 2:15-2:18 + >---< +2| String foo, bar; + +[#1 Removal] = 2:15-2:20 + >-----< +2| String foo, bar; + +[#1 Trailing delimiter] = 2:18-2:20 + >--< +2| String foo, bar; + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 2:20-2:23 + >---< +2| String foo, bar; + +[#2 Removal] = 2:18-2:23 + >-----< +2| String foo, bar; + +[#2 Leading delimiter] = 2:18-2:20 + >--< +2| String foo, bar; + +[#2 Insertion delimiter] = ", " diff --git a/packages/common/src/scopeSupportFacets/java.ts b/packages/common/src/scopeSupportFacets/java.ts index f6b27eeb72..6f9bda944a 100644 --- a/packages/common/src/scopeSupportFacets/java.ts +++ b/packages/common/src/scopeSupportFacets/java.ts @@ -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, }; diff --git a/queries/java.scm b/queries/java.scm index c438a00f71..ddd20e3653 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -316,6 +316,7 @@ value: (_)? @value @name.trailing.startOf ) ) @_.domain + (field_declaration (variable_declarator name: (_) @name @value.leading.endOf @@ -323,6 +324,49 @@ ) ) @_.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 From fc10f5ad7be044fd540a81aed9acfcc45959b6c5 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 9 Nov 2024 12:01:52 +0100 Subject: [PATCH 2/3] Update comment --- queries/java.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/java.scm b/queries/java.scm index ddd20e3653..10e1e28f50 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -351,7 +351,7 @@ ) ;;!! int foo, bar; -;;! ^^^^ ^^^^ +;;! ^^^^^^^^ ;;! ------------- (local_variable_declaration type: (_) From a3ad89a8afae51496f59919c572393472b261a5d Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 14 Jan 2025 07:14:02 +0100 Subject: [PATCH 3/3] Update scope fixtures --- .../collectionItem.unenclosed.iteration.scope | 25 ++++++- ...collectionItem.unenclosed.iteration2.scope | 48 ++++++++++++- .../java/collectionItem.unenclosed.scope | 50 ++++++++++--- .../java/collectionItem.unenclosed2.scope | 72 ++++++++++++++++--- 4 files changed, 173 insertions(+), 22 deletions(-) diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope index 1f0ae8f127..323bff9b47 100644 --- a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration.scope @@ -3,10 +3,31 @@ public class MyClass { } --- -[Range] = 1:11-1:19 +[#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; -[Domain] = 1:4-1:20 +[#3 Domain] = 1:4-1:20 >----------------< 1| String foo, bar; diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope index af2605a2aa..2920e986f2 100644 --- a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope @@ -5,10 +5,54 @@ public class MyClass { } --- -[Range] = 2:15-2:23 +[#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; -[Domain] = 2:8-2:24 +[#5 Domain] = 2:8-2:24 >----------------< 2| String foo, bar; diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.scope index 7c7a0fa33d..999c5c0da9 100644 --- a/data/fixtures/scopes/java/collectionItem.unenclosed.scope +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.scope @@ -4,32 +4,64 @@ public class MyClass { --- [#1 Content] = -[#1 Domain] = 1:11-1:14 - >---< +[#1 Domain] = 1:4-1:14 + >----------< 1| String foo, bar; -[#1 Removal] = 1:11-1:16 - >-----< +[#1 Removal] = 1:4-1:16 + >------------< 1| String foo, bar; [#1 Trailing delimiter] = 1:14-1:16 >--< 1| String foo, bar; -[#1 Insertion delimiter] = ", " +[#1 Insertion delimiter] = ",\n" [#2 Content] = -[#2 Domain] = 1:16-1:19 +[#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; -[#2 Removal] = 1:14-1:19 +[#3 Removal] = 1:14-1:19 >-----< 1| String foo, bar; -[#2 Leading delimiter] = 1:14-1:16 +[#3 Leading delimiter] = 1:14-1:16 >--< 1| String foo, bar; -[#2 Insertion delimiter] = ", " +[#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" diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed2.scope b/data/fixtures/scopes/java/collectionItem.unenclosed2.scope index b821c3407f..ccc7682a58 100644 --- a/data/fixtures/scopes/java/collectionItem.unenclosed2.scope +++ b/data/fixtures/scopes/java/collectionItem.unenclosed2.scope @@ -6,32 +6,86 @@ public class MyClass { --- [#1 Content] = -[#1 Domain] = 2:15-2:18 +[#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; -[#1 Removal] = 2:15-2:20 +[#3 Removal] = 2:15-2:20 >-----< 2| String foo, bar; -[#1 Trailing delimiter] = 2:18-2:20 +[#3 Trailing delimiter] = 2:18-2:20 >--< 2| String foo, bar; -[#1 Insertion delimiter] = ", " +[#3 Insertion delimiter] = ", " -[#2 Content] = -[#2 Domain] = 2:20-2:23 +[#4 Content] = +[#4 Domain] = 2:20-2:23 >---< 2| String foo, bar; -[#2 Removal] = 2:18-2:23 +[#4 Removal] = 2:18-2:23 >-----< 2| String foo, bar; -[#2 Leading delimiter] = 2:18-2:20 +[#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; -[#2 Insertion delimiter] = ", " +[#5 Insertion delimiter] = ",\n"