diff --git a/data/fixtures/scopes/c/interior.class.scope b/data/fixtures/scopes/c/interior.class.scope new file mode 100644 index 0000000000..164ee35df2 --- /dev/null +++ b/data/fixtures/scopes/c/interior.class.scope @@ -0,0 +1,31 @@ +struct aaa { int bbb; }; +--- + +[#1 Content] = 0:13-0:21 + >--------< +0| struct aaa { int bbb; }; + +[#1 Removal] = 0:12-0:22 + >----------< +0| struct aaa { int bbb; }; + +[#1 Domain] = 0:0-0:24 + >------------------------< +0| struct aaa { int bbb; }; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:13-0:21 + >--------< +0| struct aaa { int bbb; }; + +[#2 Removal] = 0:12-0:22 + >----------< +0| struct aaa { int bbb; }; + +[#2 Domain] = 0:11-0:23 + >------------< +0| struct aaa { int bbb; }; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.class2.scope b/data/fixtures/scopes/c/interior.class2.scope new file mode 100644 index 0000000000..eb42135bfa --- /dev/null +++ b/data/fixtures/scopes/c/interior.class2.scope @@ -0,0 +1,31 @@ +typedef struct { int fff; } ggg; +--- + +[#1 Content] = 0:17-0:25 + >--------< +0| typedef struct { int fff; } ggg; + +[#1 Removal] = 0:16-0:26 + >----------< +0| typedef struct { int fff; } ggg; + +[#1 Domain] = 0:0-0:32 + >--------------------------------< +0| typedef struct { int fff; } ggg; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:17-0:25 + >--------< +0| typedef struct { int fff; } ggg; + +[#2 Removal] = 0:16-0:26 + >----------< +0| typedef struct { int fff; } ggg; + +[#2 Domain] = 0:15-0:27 + >------------< +0| typedef struct { int fff; } ggg; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.class3.scope b/data/fixtures/scopes/c/interior.class3.scope new file mode 100644 index 0000000000..caf1852f93 --- /dev/null +++ b/data/fixtures/scopes/c/interior.class3.scope @@ -0,0 +1,31 @@ +union bbb { int ccc; }; +--- + +[#1 Content] = 0:12-0:20 + >--------< +0| union bbb { int ccc; }; + +[#1 Removal] = 0:11-0:21 + >----------< +0| union bbb { int ccc; }; + +[#1 Domain] = 0:0-0:23 + >-----------------------< +0| union bbb { int ccc; }; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:12-0:20 + >--------< +0| union bbb { int ccc; }; + +[#2 Removal] = 0:11-0:21 + >----------< +0| union bbb { int ccc; }; + +[#2 Domain] = 0:10-0:22 + >------------< +0| union bbb { int ccc; }; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.class4.scope b/data/fixtures/scopes/c/interior.class4.scope new file mode 100644 index 0000000000..5cff878228 --- /dev/null +++ b/data/fixtures/scopes/c/interior.class4.scope @@ -0,0 +1,31 @@ +typedef union { int hhh; } iii; +--- + +[#1 Content] = 0:16-0:24 + >--------< +0| typedef union { int hhh; } iii; + +[#1 Removal] = 0:15-0:25 + >----------< +0| typedef union { int hhh; } iii; + +[#1 Domain] = 0:0-0:31 + >-------------------------------< +0| typedef union { int hhh; } iii; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:16-0:24 + >--------< +0| typedef union { int hhh; } iii; + +[#2 Removal] = 0:15-0:25 + >----------< +0| typedef union { int hhh; } iii; + +[#2 Domain] = 0:14-0:26 + >------------< +0| typedef union { int hhh; } iii; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.class5.scope b/data/fixtures/scopes/c/interior.class5.scope new file mode 100644 index 0000000000..6a02da0db7 --- /dev/null +++ b/data/fixtures/scopes/c/interior.class5.scope @@ -0,0 +1,31 @@ +enum ccc { ddd, eee }; +--- + +[#1 Content] = 0:11-0:19 + >--------< +0| enum ccc { ddd, eee }; + +[#1 Removal] = 0:10-0:20 + >----------< +0| enum ccc { ddd, eee }; + +[#1 Domain] = 0:0-0:22 + >----------------------< +0| enum ccc { ddd, eee }; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:11-0:19 + >--------< +0| enum ccc { ddd, eee }; + +[#2 Removal] = 0:10-0:20 + >----------< +0| enum ccc { ddd, eee }; + +[#2 Domain] = 0:9-0:21 + >------------< +0| enum ccc { ddd, eee }; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.class6.scope b/data/fixtures/scopes/c/interior.class6.scope new file mode 100644 index 0000000000..e350fb3791 --- /dev/null +++ b/data/fixtures/scopes/c/interior.class6.scope @@ -0,0 +1,31 @@ +typedef enum { jjj, kkk } lll; +--- + +[#1 Content] = 0:15-0:23 + >--------< +0| typedef enum { jjj, kkk } lll; + +[#1 Removal] = 0:14-0:24 + >----------< +0| typedef enum { jjj, kkk } lll; + +[#1 Domain] = 0:0-0:30 + >------------------------------< +0| typedef enum { jjj, kkk } lll; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:15-0:23 + >--------< +0| typedef enum { jjj, kkk } lll; + +[#2 Removal] = 0:14-0:24 + >----------< +0| typedef enum { jjj, kkk } lll; + +[#2 Domain] = 0:13-0:25 + >------------< +0| typedef enum { jjj, kkk } lll; + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.function.scope b/data/fixtures/scopes/c/interior.function.scope new file mode 100644 index 0000000000..55b8aa5f08 --- /dev/null +++ b/data/fixtures/scopes/c/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/c/interior.function2.scope b/data/fixtures/scopes/c/interior.function2.scope new file mode 100644 index 0000000000..4b4ed12560 --- /dev/null +++ b/data/fixtures/scopes/c/interior.function2.scope @@ -0,0 +1,37 @@ +void NS::foo() { } +--- + +[#1 Content] = +[#1 Removal] = 0:16-0:17 + >-< +0| void NS::foo() { } + +[#1 Domain] = 0:0-0:18 + >------------------< +0| void NS::foo() { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:13-0:13 + >< +0| void NS::foo() { } + +[#2 Domain] = 0:12-0:14 + >--< +0| void NS::foo() { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:16-0:17 + >-< +0| void NS::foo() { } + +[#3 Domain] = 0:15-0:18 + >---< +0| void NS::foo() { } + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.if.scope b/data/fixtures/scopes/c/interior.if.scope new file mode 100644 index 0000000000..52ac91931a --- /dev/null +++ b/data/fixtures/scopes/c/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/c/interior.loop.scope b/data/fixtures/scopes/c/interior.loop.scope new file mode 100644 index 0000000000..e1cf88df36 --- /dev/null +++ b/data/fixtures/scopes/c/interior.loop.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/c/interior.loop2.scope b/data/fixtures/scopes/c/interior.loop2.scope new file mode 100644 index 0000000000..3e16181107 --- /dev/null +++ b/data/fixtures/scopes/c/interior.loop2.scope @@ -0,0 +1,37 @@ +while (true) { } +--- + +[#1 Content] = +[#1 Removal] = 0:14-0:15 + >-< +0| while (true) { } + +[#1 Domain] = 0:0-0:16 + >----------------< +0| while (true) { } + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:7-0:11 + >----< +0| while (true) { } + +[#2 Domain] = 0:6-0:12 + >------< +0| while (true) { } + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:14-0:15 + >-< +0| while (true) { } + +[#3 Domain] = 0:13-0:16 + >---< +0| while (true) { } + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.loop3.scope b/data/fixtures/scopes/c/interior.loop3.scope new file mode 100644 index 0000000000..d1833e59d1 --- /dev/null +++ b/data/fixtures/scopes/c/interior.loop3.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/c/interior.switchCase.scope b/data/fixtures/scopes/c/interior.switchCase.scope new file mode 100644 index 0000000000..6612ad442d --- /dev/null +++ b/data/fixtures/scopes/c/interior.switchCase.scope @@ -0,0 +1,209 @@ +switch (value) { + case 0: + break; + case 1: + foo; + break; + case 2: { + break; + } + default: + break; +} +--- + +[#1 Content] = 1:4-10:14 + >------- +1| case 0: +2| break; +3| case 1: +4| foo; +5| break; +6| case 2: { +7| break; +8| } +9| default: +10| break; + --------------< + +[#1 Removal] = 0:16-11:0 + > +0| switch (value) { +1| case 0: +2| break; +3| case 1: +4| foo; +5| break; +6| case 2: { +7| break; +8| } +9| default: +10| break; +11| } + < + +[#1 Domain] = 0:0-11:1 + >---------------- +0| switch (value) { +1| case 0: +2| break; +3| case 1: +4| foo; +5| break; +6| case 2: { +7| break; +8| } +9| default: +10| break; +11| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:8-0:13 + >-----< +0| switch (value) { + +[#2 Domain] = 0:7-0:14 + >-------< +0| switch (value) { + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 1:4-10:14 + >------- +1| case 0: +2| break; +3| case 1: +4| foo; +5| break; +6| case 2: { +7| break; +8| } +9| default: +10| break; + --------------< + +[#3 Removal] = 0:16-11:0 + > +0| switch (value) { +1| case 0: +2| break; +3| case 1: +4| foo; +5| break; +6| case 2: { +7| break; +8| } +9| default: +10| break; +11| } + < + +[#3 Domain] = 0:15-11:1 + >- +0| switch (value) { +1| case 0: +2| break; +3| case 1: +4| foo; +5| break; +6| case 2: { +7| break; +8| } +9| default: +10| break; +11| } + -< + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = 2:8-2:14 + >------< +2| break; + +[#4 Domain] = 1:4-2:14 + >------- +1| case 0: +2| break; + --------------< + +[#4 Insertion delimiter] = " " + + +[#5 Content] = +[#5 Removal] = 4:8-5:14 + >---- +4| foo; +5| break; + --------------< + +[#5 Domain] = 3:4-5:14 + >------- +3| case 1: +4| foo; +5| break; + --------------< + +[#5 Insertion delimiter] = " " + + +[#6 Content] = 7:8-7:14 + >------< +7| break; + +[#6 Removal] = 6:13-8:4 + > +6| case 2: { +7| break; +8| } + ----< + +[#6 Domain] = 6:4-8:5 + >--------- +6| case 2: { +7| break; +8| } + -----< + +[#6 Insertion delimiter] = " " + + +[#7 Content] = 7:8-7:14 + >------< +7| break; + +[#7 Removal] = 6:13-8:4 + > +6| case 2: { +7| break; +8| } + ----< + +[#7 Domain] = 6:12-8:5 + >- +6| case 2: { +7| break; +8| } + -----< + +[#7 Insertion delimiter] = " " + + +[#8 Content] = +[#8 Removal] = 10:8-10:14 + >------< +10| break; + +[#8 Domain] = 9:4-10:14 + >-------- +9| default: +10| break; + --------------< + +[#8 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/c/interior.ternary.scope b/data/fixtures/scopes/c/interior.ternary.scope new file mode 100644 index 0000000000..486ca84b01 --- /dev/null +++ b/data/fixtures/scopes/c/interior.ternary.scope @@ -0,0 +1,28 @@ +true ? 0 : 1 +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-0:4 + >----< +0| true ? 0 : 1 + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 0:7-0:8 + >-< +0| true ? 0 : 1 + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 0:11-0:12 + >-< +0| true ? 0 : 1 + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/cpp/interior.lambda.scope b/data/fixtures/scopes/cpp/interior.lambda.scope new file mode 100644 index 0000000000..f78e3c643c --- /dev/null +++ b/data/fixtures/scopes/cpp/interior.lambda.scope @@ -0,0 +1,69 @@ +[]() { + return 2; +}; +--- + +[#1 Content] = +[#1 Removal] = 0:1-0:1 + >< +0| []() { + +[#1 Domain] = 0:0-0:2 + >--< +0| []() { + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 1:4-1:13 + >---------< +1| return 2; + +[#2 Removal] = 0:6-2:0 + > +0| []() { +1| return 2; +2| }; + < + +[#2 Domain] = 0:0-2:1 + >------ +0| []() { +1| return 2; +2| }; + -< + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:3-0:3 + >< +0| []() { + +[#3 Domain] = 0:2-0:4 + >--< +0| []() { + +[#3 Insertion delimiter] = " " + + +[#4 Content] = 1:4-1:13 + >---------< +1| return 2; + +[#4 Removal] = 0:6-2:0 + > +0| []() { +1| return 2; +2| }; + < + +[#4 Domain] = 0:5-2:1 + >- +0| []() { +1| return 2; +2| }; + -< + +[#4 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/cpp/interior.try.scope b/data/fixtures/scopes/cpp/interior.try.scope new file mode 100644 index 0000000000..b64cb122de --- /dev/null +++ b/data/fixtures/scopes/cpp/interior.try.scope @@ -0,0 +1,62 @@ +try { } +catch (const std::exception& e) { } +--- + +[#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:33-1:34 + >-< +1| catch (const std::exception& e) { } + +[#3 Domain] = 1:0-1:35 + >-----------------------------------< +1| catch (const std::exception& e) { } + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = 1:7-1:30 + >-----------------------< +1| catch (const std::exception& e) { } + +[#4 Domain] = 1:6-1:31 + >-------------------------< +1| catch (const std::exception& e) { } + +[#4 Insertion delimiter] = " " + + +[#5 Content] = +[#5 Removal] = 1:33-1:34 + >-< +1| catch (const std::exception& e) { } + +[#5 Domain] = 1:32-1:35 + >---< +1| catch (const std::exception& e) { } + +[#5 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/c.ts b/packages/common/src/scopeSupportFacets/c.ts index 7258bbd57e..f6f34dc8e4 100644 --- a/packages/common/src/scopeSupportFacets/c.ts +++ b/packages/common/src/scopeSupportFacets/c.ts @@ -93,14 +93,14 @@ export const cCoreScopeSupport: LanguageScopeSupportFacetMap = { "type.class": supported, "type.return": supported, - // Unsupported + "interior.class": supported, + "interior.function": supported, + "interior.if": supported, + "interior.switchCase": supported, + "interior.ternary": supported, + "interior.loop": supported, - "interior.class": unsupported, - "interior.function": unsupported, - "interior.if": unsupported, - "interior.switchCase": unsupported, - "interior.ternary": unsupported, - "interior.loop": unsupported, + // Unsupported fieldAccess: unsupported, @@ -190,7 +190,7 @@ export const cScopeSupport: LanguageScopeSupportFacetMap = { ...cCoreScopeSupport, // Not applicable for C, but supported for C++ - // These are defined here because we don't want C++ to import them and + // These are defined here because we don't want C++ to import them and // accidentally forget to add support for them. attribute: notApplicable, diff --git a/packages/common/src/scopeSupportFacets/cpp.ts b/packages/common/src/scopeSupportFacets/cpp.ts index ba612187e9..17b5cdc78d 100644 --- a/packages/common/src/scopeSupportFacets/cpp.ts +++ b/packages/common/src/scopeSupportFacets/cpp.ts @@ -2,7 +2,7 @@ import { cCoreScopeSupport } from "./c"; import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; -const { supported, unsupported } = ScopeSupportFacetLevel; +const { supported } = ScopeSupportFacetLevel; export const cppScopeSupport: LanguageScopeSupportFacetMap = { ...cCoreScopeSupport, @@ -72,8 +72,6 @@ export const cppScopeSupport: LanguageScopeSupportFacetMap = { "type.typeArgument": supported, "type.typeArgument.iteration": supported, - // Unsupported - - "interior.lambda": unsupported, - "interior.try": unsupported, + "interior.lambda": supported, + "interior.try": supported, }; diff --git a/queries/c.scm b/queries/c.scm index 8b5dfd76c7..edc12b7e2e 100644 --- a/queries/c.scm +++ b/queries/c.scm @@ -58,78 +58,47 @@ (comment) @comment @textFragment +;;!! struct foo { }; +;;!! union foo { }; +;;!! enum foo { }; (_ - (struct_specifier - name: (_) @className @name - body: (_) - ) @_.domain.start @class.start @type.start - . - ";"? @_.domain.end @class.end @type.end -) -(_ - (enum_specifier - name: (_) @className @name - body: (_) - ) @_.domain.start @class.start @type.start - . - ";"? @_.domain.end @class.end @type.end -) -(_ - (union_specifier + (_ name: (_) @className @name - body: (_) + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) ) @_.domain.start @class.start @type.start . ";"? @_.domain.end @class.end @type.end + (#type? @class.start struct_specifier union_specifier enum_specifier) ) (_ - (struct_specifier - name: (_) - body: (_) - ) @statement.start - . - ";"? @statement.end -) -(_ - (enum_specifier - name: (_) - body: (_) - ) @statement.start - . - ";"? @statement.end -) -(_ - (union_specifier + (_ name: (_) body: (_) ) @statement.start . ";"? @statement.end + (#type? @statement.start struct_specifier union_specifier enum_specifier) ) +;;!! typedef struct {} foo; +;;!! typedef union {} foo; +;;!! typedef enum {} foo; (type_definition - type: (struct_specifier - body: (_) - ) - declarator: (type_identifier) @className @name -) @_.domain @class @type - -(type_definition - type: (enum_specifier - body: (_) - ) - declarator: (type_identifier) @className @name -) @_.domain @class @type - -(type_definition - type: (union_specifier - body: (_) - ) + type: (_ + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) + ) @_dummy declarator: (type_identifier) @className @name + (#type? @_dummy struct_specifier union_specifier enum_specifier) ) @_.domain @class @type -;;!! void funcName(); +;;!! void foo(); (declaration (function_declarator declarator: (_ @@ -138,7 +107,7 @@ ) ) @namedFunction @functionName.domain @name.domain -;;!! void C::funcName() {} +;;!! void C::foo() {} (declaration (function_declarator declarator: (_ @@ -155,7 +124,7 @@ ) ) @namedFunction @functionName.domain @name.domain -;;!! void funcName() {} +;;!! void foo() {} (function_definition declarator: (_ declarator: (_ @@ -164,6 +133,15 @@ ) ) @namedFunction @functionName.domain @name.domain +;;!! void foo() { } +;;! ^ +(function_definition + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @_.domain + ;;!! int aaa; ;;! ^^^ (field_declaration @@ -294,9 +272,12 @@ ;;! ^^^^^^^^ ( (if_statement - "if" @branch.start @branch.removal.start + "if" @branch.start @branch.removal.start @interior.domain.start condition: (_) @condition - consequence: (_) @branch.end @branch.removal.end + consequence: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @branch.end @branch.removal.end @interior.domain.end alternative: (else_clause (if_statement) @branch.removal.end.startOf )? @@ -308,10 +289,13 @@ ;;!! else if () {} ;;! ^^^^^^^^^^^^^ (else_clause - "else" @branch.start @condition.domain.start + "else" @branch.start @condition.domain.start @interior.domain.start (if_statement condition: (_) @condition - consequence: (_) @branch.end @condition.domain.end + consequence: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @branch.end @condition.domain.end @interior.domain.end (#child-range! @condition 0 -1 true true) ) ) @@ -320,8 +304,11 @@ ;;! ^^^^^^^ (if_statement (else_clause - (compound_statement) - ) @branch + (compound_statement + "{" @interior.start.endOf + "}" @interior.end.startOf + ) + ) @branch @interior.domain ) ( @@ -334,23 +321,35 @@ ;;! ^^^^^^^^ (for_statement condition: (_) @condition -) @branch @condition.domain + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @branch @_.domain ;;!! while (true) {} ;;! ^^^^^^^^^^^^^^^ ;;! ^^^^ (while_statement condition: (_) @condition + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) (#child-range! @condition 0 -1 true true) -) @branch @condition.domain +) @branch @_.domain ;;!! do {} while (true); ;;! ^^^^^^^^^^^^^^^^^^^ ;;! ^^^^ (do_statement + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) condition: (_) @condition (#child-range! @condition 0 -1 true true) -) @branch @condition.domain +) @branch @_.domain ;;!! switch (true) {} ;;! ^^^^ @@ -360,8 +359,8 @@ ")" @private.switchStatementSubject.end.startOf ) body: (_ - "{" @branch.iteration.start.endOf @condition.iteration.start.endOf - "}" @branch.iteration.end.startOf @condition.iteration.end.startOf + "{" @branch.iteration.start.endOf @condition.iteration.start.endOf @interior.start.endOf + "}" @branch.iteration.end.startOf @condition.iteration.end.startOf @interior.end.startOf ) ) @_.domain @branch.iteration.domain @condition.iteration.domain @@ -369,18 +368,50 @@ ;;! ^^^^^^^^^^^^^^ ;;! ^ (case_statement - value: (_)? @condition -) @branch @condition.domain + value: (_) @condition + . + (_) @interior.start + (_)? @interior.end + . + (#not-type? @interior.start "compound_statement") +) @branch @_.domain + +;;!! default: break; +;;! ^^^^^^^^^^^^^^; +(case_statement + !value + . + (_) @interior.start + (_)? @interior.end + . + (#not-type? @interior.start "compound_statement") +) @branch @_.domain + +;;!! case 0: { } +;;! ^ +(case_statement + (compound_statement + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @_.domain ;;!! true ? 0 : 1 ;;! ^^^^ -;;! ^ ^ (conditional_expression - condition: (_) @condition - consequence: (_) @branch + condition: (_) @condition @interior ) @condition.domain + +;;!! true ? 0 : 1 +;;! ^ +(conditional_expression + consequence: (_) @branch @interior +) + +;;!! true ? 0 : 1 +;;! ^ (conditional_expression - alternative: (_) @branch + alternative: (_) @branch @interior ) ;;!! int foo, bar; diff --git a/queries/cpp.scm b/queries/cpp.scm index ab2408f4c9..34e79d4301 100644 --- a/queries/cpp.scm +++ b/queries/cpp.scm @@ -57,7 +57,12 @@ ;;!! []() {} ;;! ^^^^^^^ -(lambda_expression) @anonymousFunction +(lambda_expression + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @anonymousFunction @interior.domain ;;!! [[attribute]] (attribute_declaration) @attribute @@ -87,12 +92,20 @@ ;;!! try {} ;;! ^^^^^^ (try_statement - "try" @branch.start - body: (_) @branch.end + "try" @branch.start @interior.domain.start + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) @branch.end @interior.domain.end ) @branch.iteration ;;!! catch (const std::exception& e) {} -(catch_clause) @branch +(catch_clause + body: (_ + "{" @interior.start.endOf + "}" @interior.end.startOf + ) +) @branch @interior.domain ;;!! new Foo() ;;! ^^^^^^^^^