From 9c0b74595cadd059ebcd7938372c330745da3c12 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 24 May 2025 11:16:23 +0200 Subject: [PATCH] Updated type arguments implementation --- data/fixtures/scopes/java/type.field.scope | 21 +++-- .../java/type.typeArgument.iteration.scope | 21 ++--- .../scopes/java/type.typeArgument.scope | 83 ++++++++----------- .../typescript.core/type.typeArgument.scope | 21 +++-- .../typescript.core/type.typeArgument2.scope | 10 +++ queries/java.scm | 25 +++--- queries/typescript.core.scm | 51 ++++++------ 7 files changed, 115 insertions(+), 117 deletions(-) create mode 100644 data/fixtures/scopes/typescript.core/type.typeArgument2.scope diff --git a/data/fixtures/scopes/java/type.field.scope b/data/fixtures/scopes/java/type.field.scope index bbab5b7e8f..a8097eaca7 100644 --- a/data/fixtures/scopes/java/type.field.scope +++ b/data/fixtures/scopes/java/type.field.scope @@ -39,12 +39,19 @@ class MyClass { [#3 Content] = -[#3 Removal] = [#3 Domain] = 1:8-1:11 >---< 1| Map foo; -[#3 Insertion delimiter] = " " +[#3 Removal] = 1:8-1:13 + >-----< +1| Map foo; + +[#3 Trailing delimiter] = 1:11-1:13 + >--< +1| Map foo; + +[#3 Insertion delimiter] = ", " [#4 Content] = @@ -52,12 +59,12 @@ class MyClass { >---< 1| Map foo; -[#4 Removal] = 1:12-1:16 - >----< +[#4 Removal] = 1:11-1:16 + >-----< 1| Map foo; -[#4 Leading delimiter] = 1:12-1:13 - >-< +[#4 Leading delimiter] = 1:11-1:13 + >--< 1| Map foo; -[#4 Insertion delimiter] = " " +[#4 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/java/type.typeArgument.iteration.scope b/data/fixtures/scopes/java/type.typeArgument.iteration.scope index 1aa65a64ac..f51d7acf21 100644 --- a/data/fixtures/scopes/java/type.typeArgument.iteration.scope +++ b/data/fixtures/scopes/java/type.typeArgument.iteration.scope @@ -1,18 +1,7 @@ -class MyClass { - Map foo; -} +Map foo; --- -[#1 Range] = -[#1 Domain] = 0:15-2:0 - > -0| class MyClass { -1| Map foo; -2| } - < - - -[#2 Range] = -[#2 Domain] = 1:8-1:16 - >--------< -1| Map foo; +[Range] = +[Domain] = 0:4-0:12 + >--------< +0| Map foo; diff --git a/data/fixtures/scopes/java/type.typeArgument.scope b/data/fixtures/scopes/java/type.typeArgument.scope index bbab5b7e8f..3012e5f19f 100644 --- a/data/fixtures/scopes/java/type.typeArgument.scope +++ b/data/fixtures/scopes/java/type.typeArgument.scope @@ -1,63 +1,52 @@ -class MyClass { - Map foo; -} +Map foo; --- -[#1 Content] = -[#1 Removal] = -[#1 Domain] = 0:0-2:1 - >--------------- -0| class MyClass { -1| Map foo; -2| } - -< +[#1 Content] = 0:0-0:13 + >-------------< +0| Map foo; -[#1 Insertion delimiter] = " " - - -[#2 Content] = 1:4-1:17 - >-------------< -1| Map foo; +[#1 Removal] = 0:0-0:14 + >--------------< +0| Map foo; -[#2 Removal] = 1:4-1:18 - >--------------< -1| Map foo; +[#1 Trailing delimiter] = 0:13-0:14 + >-< +0| Map foo; -[#2 Leading delimiter] = 1:0-1:4 - >----< -1| Map foo; +[#1 Domain] = 0:0-0:18 + >------------------< +0| Map foo; -[#2 Trailing delimiter] = 1:17-1:18 - >-< -1| Map foo; +[#1 Insertion delimiter] = " " -[#2 Domain] = 1:4-1:22 - >------------------< -1| Map foo; -[#2 Insertion delimiter] = " " +[#2 Content] = +[#2 Domain] = 0:4-0:7 + >---< +0| Map foo; +[#2 Removal] = 0:4-0:9 + >-----< +0| Map foo; -[#3 Content] = -[#3 Removal] = -[#3 Domain] = 1:8-1:11 - >---< -1| Map foo; +[#2 Trailing delimiter] = 0:7-0:9 + >--< +0| Map foo; -[#3 Insertion delimiter] = " " +[#2 Insertion delimiter] = ", " -[#4 Content] = -[#4 Domain] = 1:13-1:16 - >---< -1| Map foo; +[#3 Content] = +[#3 Domain] = 0:9-0:12 + >---< +0| Map foo; -[#4 Removal] = 1:12-1:16 - >----< -1| Map foo; +[#3 Removal] = 0:7-0:12 + >-----< +0| Map foo; -[#4 Leading delimiter] = 1:12-1:13 - >-< -1| Map foo; +[#3 Leading delimiter] = 0:7-0:9 + >--< +0| Map foo; -[#4 Insertion delimiter] = " " +[#3 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/typescript.core/type.typeArgument.scope b/data/fixtures/scopes/typescript.core/type.typeArgument.scope index af00e8f116..0b73b4b849 100644 --- a/data/fixtures/scopes/typescript.core/type.typeArgument.scope +++ b/data/fixtures/scopes/typescript.core/type.typeArgument.scope @@ -21,12 +21,19 @@ let value: Map; [#2 Content] = -[#2 Removal] = [#2 Domain] = 0:15-0:21 >------< 0| let value: Map; -[#2 Insertion delimiter] = " " +[#2 Removal] = 0:15-0:23 + >--------< +0| let value: Map; + +[#2 Trailing delimiter] = 0:21-0:23 + >--< +0| let value: Map; + +[#2 Insertion delimiter] = ", " [#3 Content] = @@ -34,12 +41,12 @@ let value: Map; >------< 0| let value: Map; -[#3 Removal] = 0:22-0:29 - >-------< +[#3 Removal] = 0:21-0:29 + >--------< 0| let value: Map; -[#3 Leading delimiter] = 0:22-0:23 - >-< +[#3 Leading delimiter] = 0:21-0:23 + >--< 0| let value: Map; -[#3 Insertion delimiter] = " " +[#3 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/typescript.core/type.typeArgument2.scope b/data/fixtures/scopes/typescript.core/type.typeArgument2.scope new file mode 100644 index 0000000000..124024978b --- /dev/null +++ b/data/fixtures/scopes/typescript.core/type.typeArgument2.scope @@ -0,0 +1,10 @@ +useState() +--- + +[Content] = +[Removal] = +[Domain] = 0:9-0:15 + >------< +0| useState() + +[Insertion delimiter] = ", " diff --git a/queries/java.scm b/queries/java.scm index 4a1bc3c8d4..f5c45453d1 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -306,12 +306,6 @@ . ) @type.iteration.domain @name.iteration.domain -;;!! Map -;;! ^^^^^^^ ^^^^^^ -(type_arguments - (type_identifier) @type -) - ;;!! List list = value; ;;! ^^^^^^^^^^^^ ;;! -------------------------- @@ -480,21 +474,26 @@ (#not-type? @value block) ) @_.domain -;;!! public Map foo; -;;! ^^^^^^^^^^^^^ -;;! ------------------------- +;;!! Map foo; +;;! ^^^^^^^^^^^^^ +;;! ------------------ (field_declaration type: (_) @type ) @_.domain -;;!! public Map foo; -;;! ^^^ ^^^ +;;!! Map foo; +;;! ^^^ ^^^ (type_arguments + (_)? @_.leading.endOf + . (_) @type + . + (_)? @_.trailing.startOf + (#insertion-delimiter! @type ", ") ) -;;!! public Map foo; -;;! ^^^^^^^^ +;;!! Map foo; +;;! ^^^^^^^^ (type_arguments . "<" @type.iteration.start.endOf diff --git a/queries/typescript.core.scm b/queries/typescript.core.scm index 382572ac0d..58ddad21f9 100644 --- a/queries/typescript.core.scm +++ b/queries/typescript.core.scm @@ -263,15 +263,33 @@ type_arguments: (_)? @type.end ) +;;!! Map +;;! ^^^^^^ ^^^^^^ ;;!! useState() ;;! ^^^^^^ -;;!! useState>() -;;! ^^^^^^^^^^^^^^^^^^^^^^ -;;! ^^^^^^ ^^^^^^ -(type_arguments - (_) @type +( + (type_arguments + (_)? @_.leading.endOf + . + (_) @type + . + (_)? @_.trailing.startOf + ) @_dummy + (#not-parent-type? @_dummy type_assertion) + (#insertion-delimiter! @type ", ") +) + +;;!! Map +;;! ^^^^^^^^^^^^^^ +( + (type_arguments + . + "<" @type.iteration.start.endOf + ">" @type.iteration.end.startOf + . + ) @_dummy (#not-parent-type? @_dummy type_assertion) -) @_dummy +) ;;!! function foo() {} ;;! ^ @@ -414,24 +432,3 @@ "}" @type.iteration.end.startOf . ) - -;;!! Map -;;! ^^^^^^ ^^^^^^ -( - (type_arguments - (_) @type - ) @_dummy - (#not-parent-type? @_dummy type_assertion) -) - -;;!! Map -;;! ^^^^^^^^^^^^^^ -( - (type_arguments - . - "<" @type.iteration.start.endOf - ">" @type.iteration.end.startOf - . - ) @_dummy - (#not-parent-type? @_dummy type_assertion) -)