diff --git a/data/fixtures/scopes/csharp/interior.class.scope b/data/fixtures/scopes/csharp/interior.class.scope new file mode 100644 index 0000000000..5390112f29 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.class.scope @@ -0,0 +1,25 @@ +class Foo { } +--- + +[#1 Content] = +[#1 Removal] = 0:11-0:12 + >-< +0| class Foo { } + +[#1 Domain] = 0:0-0:13 + >-------------< +0| class Foo { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:11-0:12 + >-< +0| class Foo { } + +[#2 Domain] = 0:10-0:13 + >---< +0| class Foo { } + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.function.scope b/data/fixtures/scopes/csharp/interior.function.scope new file mode 100644 index 0000000000..1c8b29392b --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.function.scope @@ -0,0 +1,37 @@ +void Foo() { } +--- + +[#1 Content] = +[#1 Removal] = 0:12-0:13 + >-< +0| void Foo() { } + +[#1 Domain] = 0:0-0:14 + >--------------< +0| void Foo() { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:9-0:9 + >< +0| void Foo() { } + +[#2 Domain] = 0:8-0:10 + >--< +0| void Foo() { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:12-0:13 + >-< +0| void Foo() { } + +[#3 Domain] = 0:11-0:14 + >---< +0| void Foo() { } + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.if.scope b/data/fixtures/scopes/csharp/interior.if.scope new file mode 100644 index 0000000000..52ac91931a --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.if.scope @@ -0,0 +1,99 @@ +if (true) { } +else if (false) { } +else { } +--- + +[#1 Content] = +[#1 Removal] = 0:11-0:12 + >-< +0| if (true) { } + +[#1 Domain] = 0:0-0:13 + >-------------< +0| if (true) { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:4-0:8 + >----< +0| if (true) { } + +[#2 Domain] = 0:3-0:9 + >------< +0| if (true) { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:11-0:12 + >-< +0| if (true) { } + +[#3 Domain] = 0:10-0:13 + >---< +0| if (true) { } + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = 1:17-1:18 + >-< +1| else if (false) { } + +[#4 Domain] = 1:0-1:19 + >-------------------< +1| else if (false) { } + +[#4 Insertion delimiter] = " " + + +[#5 Content] = +[#5 Removal] = 1:9-1:14 + >-----< +1| else if (false) { } + +[#5 Domain] = 1:8-1:15 + >-------< +1| else if (false) { } + +[#5 Insertion delimiter] = " " + + +[#6 Content] = +[#6 Removal] = 1:17-1:18 + >-< +1| else if (false) { } + +[#6 Domain] = 1:16-1:19 + >---< +1| else if (false) { } + +[#6 Insertion delimiter] = " " + + +[#7 Content] = +[#7 Removal] = 2:6-2:7 + >-< +2| else { } + +[#7 Domain] = 2:0-2:8 + >--------< +2| else { } + +[#7 Insertion delimiter] = " " + + +[#8 Content] = +[#8 Removal] = 2:6-2:7 + >-< +2| else { } + +[#8 Domain] = 2:5-2:8 + >---< +2| else { } + +[#8 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.lambda.scope b/data/fixtures/scopes/csharp/interior.lambda.scope new file mode 100644 index 0000000000..6d85ffaf2f --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.lambda.scope @@ -0,0 +1,25 @@ +() => 0; +--- + +[#1 Content] = +[#1 Removal] = 0:1-0:1 + >< +0| () => 0; + +[#1 Domain] = 0:0-0:2 + >--< +0| () => 0; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:6-0:7 + >-< +0| () => 0; + +[#2 Domain] = 0:0-0:7 + >-------< +0| () => 0; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.lambda2.scope b/data/fixtures/scopes/csharp/interior.lambda2.scope new file mode 100644 index 0000000000..ef5ef5acf1 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.lambda2.scope @@ -0,0 +1,37 @@ +() => { }; +--- + +[#1 Content] = +[#1 Removal] = 0:1-0:1 + >< +0| () => { }; + +[#1 Domain] = 0:0-0:2 + >--< +0| () => { }; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:7-0:8 + >-< +0| () => { }; + +[#2 Domain] = 0:0-0:9 + >---------< +0| () => { }; + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:7-0:8 + >-< +0| () => { }; + +[#3 Domain] = 0:6-0:9 + >---< +0| () => { }; + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.loop.scope b/data/fixtures/scopes/csharp/interior.loop.scope new file mode 100644 index 0000000000..0fe48d4d34 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.loop.scope @@ -0,0 +1,25 @@ +while (true) { } +--- + +[#1 Content] = +[#1 Removal] = 0:7-0:11 + >----< +0| while (true) { } + +[#1 Domain] = 0:6-0:12 + >------< +0| while (true) { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:14-0:15 + >-< +0| while (true) { } + +[#2 Domain] = 0:13-0:16 + >---< +0| while (true) { } + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.loop2.scope b/data/fixtures/scopes/csharp/interior.loop2.scope new file mode 100644 index 0000000000..d1833e59d1 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.loop2.scope @@ -0,0 +1,37 @@ +do { } while (true); +--- + +[#1 Content] = +[#1 Removal] = 0:4-0:5 + >-< +0| do { } while (true); + +[#1 Domain] = 0:0-0:20 + >--------------------< +0| do { } while (true); + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:4-0:5 + >-< +0| do { } while (true); + +[#2 Domain] = 0:3-0:6 + >---< +0| do { } while (true); + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:14-0:18 + >----< +0| do { } while (true); + +[#3 Domain] = 0:13-0:19 + >------< +0| do { } while (true); + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.loop3.scope b/data/fixtures/scopes/csharp/interior.loop3.scope new file mode 100644 index 0000000000..e1cf88df36 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.loop3.scope @@ -0,0 +1,37 @@ +for (int i = 0; i < size; ++i) { } +--- + +[#1 Content] = +[#1 Removal] = 0:32-0:33 + >-< +0| for (int i = 0; i < size; ++i) { } + +[#1 Domain] = 0:0-0:34 + >----------------------------------< +0| for (int i = 0; i < size; ++i) { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:5-0:29 + >------------------------< +0| for (int i = 0; i < size; ++i) { } + +[#2 Domain] = 0:4-0:30 + >--------------------------< +0| for (int i = 0; i < size; ++i) { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:32-0:33 + >-< +0| for (int i = 0; i < size; ++i) { } + +[#3 Domain] = 0:31-0:34 + >---< +0| for (int i = 0; i < size; ++i) { } + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.loop4.scope b/data/fixtures/scopes/csharp/interior.loop4.scope new file mode 100644 index 0000000000..13e6cbc8e7 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.loop4.scope @@ -0,0 +1,37 @@ +foreach (int v in values) { } +--- + +[#1 Content] = +[#1 Removal] = 0:27-0:28 + >-< +0| foreach (int v in values) { } + +[#1 Domain] = 0:0-0:29 + >-----------------------------< +0| foreach (int v in values) { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:9-0:24 + >---------------< +0| foreach (int v in values) { } + +[#2 Domain] = 0:8-0:25 + >-----------------< +0| foreach (int v in values) { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:27-0:28 + >-< +0| foreach (int v in values) { } + +[#3 Domain] = 0:26-0:29 + >---< +0| foreach (int v in values) { } + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.switchCase.scope b/data/fixtures/scopes/csharp/interior.switchCase.scope new file mode 100644 index 0000000000..c0c5b32760 --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.switchCase.scope @@ -0,0 +1,181 @@ +switch (aaa) { + case 0: + foo; + break; + case 1: { + break; + } + default: + break; +} +--- + +[#1 Content] = 1:4-8:14 + >------- +1| case 0: +2| foo; +3| break; +4| case 1: { +5| break; +6| } +7| default: +8| break; + --------------< + +[#1 Removal] = 0:14-9:0 + > +0| switch (aaa) { +1| case 0: +2| foo; +3| break; +4| case 1: { +5| break; +6| } +7| default: +8| break; +9| } + < + +[#1 Domain] = 0:0-9:1 + >-------------- +0| switch (aaa) { +1| case 0: +2| foo; +3| break; +4| case 1: { +5| break; +6| } +7| default: +8| break; +9| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:8-0:11 + >---< +0| switch (aaa) { + +[#2 Domain] = 0:7-0:12 + >-----< +0| switch (aaa) { + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 1:4-8:14 + >------- +1| case 0: +2| foo; +3| break; +4| case 1: { +5| break; +6| } +7| default: +8| break; + --------------< + +[#3 Removal] = 0:14-9:0 + > +0| switch (aaa) { +1| case 0: +2| foo; +3| break; +4| case 1: { +5| break; +6| } +7| default: +8| break; +9| } + < + +[#3 Domain] = 0:13-9:1 + >- +0| switch (aaa) { +1| case 0: +2| foo; +3| break; +4| case 1: { +5| break; +6| } +7| default: +8| break; +9| } + -< + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = 2:8-3:14 + >---- +2| foo; +3| break; + --------------< + +[#4 Domain] = 1:4-3:14 + >------- +1| case 0: +2| foo; +3| break; + --------------< + +[#4 Insertion delimiter] = " " + + +[#5 Content] = 5:8-5:14 + >------< +5| break; + +[#5 Removal] = 4:13-6:4 + > +4| case 1: { +5| break; +6| } + ----< + +[#5 Domain] = 4:4-6:5 + >--------- +4| case 1: { +5| break; +6| } + -----< + +[#5 Insertion delimiter] = " " + + +[#6 Content] = 5:8-5:14 + >------< +5| break; + +[#6 Removal] = 4:13-6:4 + > +4| case 1: { +5| break; +6| } + ----< + +[#6 Domain] = 4:12-6:5 + >- +4| case 1: { +5| break; +6| } + -----< + +[#6 Insertion delimiter] = " " + + +[#7 Content] = +[#7 Removal] = 8:8-8:14 + >------< +8| break; + +[#7 Domain] = 7:4-8:14 + >-------- +7| default: +8| break; + --------------< + +[#7 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.ternary.scope b/data/fixtures/scopes/csharp/interior.ternary.scope new file mode 100644 index 0000000000..79ef01735b --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.ternary.scope @@ -0,0 +1,28 @@ +true ? 1 : 0; +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-0:4 + >----< +0| true ? 1 : 0; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 0:7-0:8 + >-< +0| true ? 1 : 0; + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 0:11-0:12 + >-< +0| true ? 1 : 0; + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/interior.try.scope b/data/fixtures/scopes/csharp/interior.try.scope new file mode 100644 index 0000000000..87dc4ae08a --- /dev/null +++ b/data/fixtures/scopes/csharp/interior.try.scope @@ -0,0 +1,87 @@ +try { } +catch(Exception ex) { } +finally { } +--- + +[#1 Content] = +[#1 Removal] = 0:5-0:6 + >-< +0| try { } + +[#1 Domain] = 0:0-0:7 + >-------< +0| try { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:5-0:6 + >-< +0| try { } + +[#2 Domain] = 0:4-0:7 + >---< +0| try { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 1:21-1:22 + >-< +1| catch(Exception ex) { } + +[#3 Domain] = 1:0-1:23 + >-----------------------< +1| catch(Exception ex) { } + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = 1:6-1:18 + >------------< +1| catch(Exception ex) { } + +[#4 Domain] = 1:5-1:19 + >--------------< +1| catch(Exception ex) { } + +[#4 Insertion delimiter] = " " + + +[#5 Content] = +[#5 Removal] = 1:21-1:22 + >-< +1| catch(Exception ex) { } + +[#5 Domain] = 1:20-1:23 + >---< +1| catch(Exception ex) { } + +[#5 Insertion delimiter] = " " + + +[#6 Content] = +[#6 Removal] = 2:9-2:10 + >-< +2| finally { } + +[#6 Domain] = 2:0-2:11 + >-----------< +2| finally { } + +[#6 Insertion delimiter] = " " + + +[#7 Content] = +[#7 Removal] = 2:9-2:10 + >-< +2| finally { } + +[#7 Domain] = 2:8-2:11 + >---< +2| finally { } + +[#7 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/csharp.ts b/packages/common/src/scopeSupportFacets/csharp.ts index be75bf962a..0f5cb23cb6 100644 --- a/packages/common/src/scopeSupportFacets/csharp.ts +++ b/packages/common/src/scopeSupportFacets/csharp.ts @@ -1,7 +1,7 @@ import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; -const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; +const { supported, notApplicable } = ScopeSupportFacetLevel; export const csharpScopeSupport: LanguageScopeSupportFacetMap = { switchStatementSubject: supported, @@ -160,16 +160,14 @@ export const csharpScopeSupport: LanguageScopeSupportFacetMap = { "textFragment.comment.line": supported, "textFragment.comment.block": supported, - // Unsupported - - "interior.class": unsupported, - "interior.function": unsupported, - "interior.if": unsupported, - "interior.lambda": unsupported, - "interior.loop": unsupported, - "interior.switchCase": unsupported, - "interior.ternary": unsupported, - "interior.try": unsupported, + "interior.class": supported, + "interior.function": supported, + "interior.if": supported, + "interior.lambda": supported, + "interior.loop": supported, + "interior.switchCase": supported, + "interior.ternary": supported, + "interior.try": supported, // Not applicable diff --git a/queries/csharp.scm b/queries/csharp.scm index 6c5f1a49aa..326f17d4b3 100644 --- a/queries/csharp.scm +++ b/queries/csharp.scm @@ -72,22 +72,37 @@ ) @branch.start.startOf @branch.removal.start.startOf @condition.domain (#not-parent-type? @condition.domain "if_statement") ) +( + (if_statement + consequence: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @interior.domain.end.endOf + ) @interior.domain.start.startOf + (#not-parent-type? @interior.domain.start.startOf "if_statement") +) ;;!! else if () {} ;;! ^^^^^^^^^^^^^ (if_statement - "else" @branch.start.startOf @condition.domain.start.startOf + "else" @branch.start.startOf @interior.domain.start.startOf @condition.domain.start.startOf (if_statement condition: (_) @condition - consequence: (_) @branch.end.endOf @condition.domain.end.endOf + consequence: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @branch.end.endOf @interior.domain.end.endOf @condition.domain.end.endOf ) ) ;;!! else {} ;;! ^^^^^^^ (if_statement - "else" @branch.start - alternative: (block) @branch.end + "else" @branch.start @interior.domain.start.startOf + alternative: (block + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @branch.end @interior.domain.end.endOf ) ;;!! if () {} else if () {} else {} @@ -100,8 +115,11 @@ ;;!! try () {} ;;! ^^^^^^^^^ (try_statement - body: (_) @branch.end.endOf -) @branch.start.startOf + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @branch.end.endOf @interior.domain.end.endOf +) @branch.start.startOf @interior.domain.start.startOf ;;!! catch () {} ;;! ^^^^^^^^^^^ @@ -109,7 +127,12 @@ ;;!! finally {} ;;! ^^^^^^^^^^ -(finally_clause) @branch +(finally_clause + (block + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @branch @interior.domain ;;!! try () {} catch () {} finally {} ;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,17 +156,23 @@ ;;! ^^^^ ;;! ^ ^ (conditional_expression - condition: (_) @condition - consequence: (_) @branch + condition: (_) @condition @interior ) @condition.domain (conditional_expression - alternative: (_) @branch -) @condition.domain + consequence: (_) @branch @interior +) +(conditional_expression + alternative: (_) @branch @interior +) ;;!! class Foo {} ;;! ^^^^^^^^^^^^ (class_declaration name: (identifier) @className + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) ) @class @type @_.domain ( @@ -156,13 +185,21 @@ ;;! *** (_ body: (_ - . "{" @class.iteration.start.endOf @className.iteration.start.endOf "}" @class.iteration.end.startOf @className.iteration.end.startOf - . ) ) +( + (_ + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) + ) @_.domain + (#not-type? @_.domain try_statement) +) + ;;!! "Hello world" ( (string_literal) @string @textFragment @@ -185,8 +222,8 @@ ;;!! () => 2; ;;! ^ (lambda_expression - body: (_) @value - (#not-type? @value block) + body: (_) @value @interior + (#not-type? @value block initializer_expression) ) @_.domain ;;!! return 2; @@ -260,11 +297,21 @@ ) @_.domain (do_statement + (block + "{" @interior.start.endOf + "}" @interior.end.startOf + ) "while" . (_) @condition ) @_.domain +;;!! case 0: break; +;;! ^^^^^^^^^^^^^^ +(switch_section) @branch + +;;!! case 0: break; +;;! ^ (switch_section (case_switch_label . @@ -272,7 +319,28 @@ ) ) @_.domain -(switch_section) @branch +;;!! default: break; +;;! ^^^^^^ +(switch_section + [ + (case_switch_label) + (default_switch_label) + ] + . + (_) @interior.start + (_)? @interior.end + . + (#not-type? @interior.start "block") +) @_.domain + +;;!! case 0: { } +;;! ^ +(switch_section + (block + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @_.domain (switch_statement body: (switch_body