Skip to content

Commit 5efbd5a

Browse files
authored
fix: DML operations on method call results (#26) (#71)
* test: add test for annotation on same line as method (issue #44) - Add test case for annotation on same line as method declaration - Test verifies correct highlighting in this scenario - Test currently passes, indicating issue may already be resolved Closes #44 * test: add tests for ternary expressions (issue #43) - Add test cases for nested ternary expressions - Add test case for ternary with method calls - Tests verify correct highlighting in these scenarios - Tests currently pass, indicating issue may already be resolved Closes #43 * fix: DML operations on method call results (issue #26) - Add dml-expression pattern to handle DML operations on expressions - Pattern matches insert/update/delete/upsert/undelete followed by expressions - Ensures DML operations receive same scope (support.function.apex) whether applied to new objects or method call results like Map.values() - Add test case verifying insert accounts.values() gets same scope as insert new List Closes #26 * fix: support namespace-qualified types in extends/implements (issue #50) - Update extends-class pattern to handle namespace-qualified types - Update implements-class pattern to handle namespace-qualified types - Patterns now correctly tokenize System.Exception, Database.Batchable, etc. - Use lookahead to distinguish namespace-qualified from simple types - Fix type-builtin to use 'Id' instead of 'ID' to match Apex convention - Add test cases for namespace-qualified extends and implements Closes #50 * fix: support namespace-qualified types in extends/implements (issue #50) - Update extends-class pattern to handle namespace-qualified types - Update implements-class pattern to handle namespace-qualified types - Patterns now correctly tokenize System.Exception, Database.Batchable, etc. - Use lookahead to distinguish namespace-qualified from simple types - Fix type-builtin to support both 'Id' and 'ID' (Apex is case-insensitive) - Add test cases for namespace-qualified extends and implements Closes #50 * test: add coverage for both Id and ID (case-insensitive Apex) - Add test for Id (lowercase d) as field type - Add test for ID (uppercase D) as field type - Add test for Id in generic type parameters - Add test for ID in generic type parameters - Verifies Apex case-insensitive support for Id/ID primitive type * feat: support for varied casing on ID/Id * fix: Add syntax highlighting for initialization blocks Add initializer-block pattern to grammar to properly highlight code inside initialization blocks (standalone { } blocks at class member level). The pattern matches standalone curly brace blocks and includes statement patterns for proper syntax highlighting, matching method body behavior. Fixes: forcedotcom/salesforcedx-vscode#4920 * test: Add tests for initialization block syntax highlighting Add comprehensive tests to verify initialization blocks are properly highlighted, including: - Empty initialization blocks - Method calls with string literals (the main issue #4920) - Multiple statements - Nested class scenario - Comparison with method body highlighting * test: Add test for static keyword before block Even though Apex doesn't support static initialization blocks, verify the grammar handles the syntax for highlighting purposes. * fix: Fix switch/when statement syntax highlighting and brace matching - Remove lookbehind end patterns from all when-* statements that prevented proper brace matching - Update end patterns to use lookahead that ends on closing brace or next when clause - Improve when-string pattern to support multiple comma-separated strings - Fix issue #2134: syntax highlighting and brace matching for switch/when statements All switch statement tests passing. * fix: Fix dash highlighting in switch statement string literals - Remove quote character from when-statement pattern character class - Change from ['_\-[:alnum:]]+ to [_\-[:alnum:]]+ - Ensures string literals with dashes like 'de-CH' and 'fr-CH' are matched by when-string pattern - Add test case for string literals containing dashes in switch statements This fixes an issue where the when-statement pattern would incorrectly match string literals containing dashes, preventing proper syntax highlighting. * fix: support namespace-qualified types in extends/implements (#50) (#72) * fix: support namespace-qualified types in extends/implements (issue #50) - Update extends-class pattern to handle namespace-qualified types - Update implements-class pattern to handle namespace-qualified types - Patterns now correctly tokenize System.Exception, Database.Batchable, etc. - Use lookahead to distinguish namespace-qualified from simple types - Fix type-builtin to support both 'Id' and 'ID' (Apex is case-insensitive) - Add test cases for namespace-qualified extends and implements Closes #50 * test: add coverage for both Id and ID (case-insensitive Apex) - Add test for Id (lowercase d) as field type - Add test for ID (uppercase D) as field type - Add test for Id in generic type parameters - Add test for ID in generic type parameters - Verifies Apex case-insensitive support for Id/ID primitive type * feat: support for varied casing on ID/Id * chore: pr reproducers in sfdx project for visual inspection * fix: 4920 initializer block syntax W-19265631 (#73) * fix: support namespace-qualified types in extends/implements (issue #50) - Update extends-class pattern to handle namespace-qualified types - Update implements-class pattern to handle namespace-qualified types - Patterns now correctly tokenize System.Exception, Database.Batchable, etc. - Use lookahead to distinguish namespace-qualified from simple types - Fix type-builtin to support both 'Id' and 'ID' (Apex is case-insensitive) - Add test cases for namespace-qualified extends and implements Closes #50 * test: add coverage for both Id and ID (case-insensitive Apex) - Add test for Id (lowercase d) as field type - Add test for ID (uppercase D) as field type - Add test for Id in generic type parameters - Add test for ID in generic type parameters - Verifies Apex case-insensitive support for Id/ID primitive type * feat: support for varied casing on ID/Id * fix: Add syntax highlighting for initialization blocks Add initializer-block pattern to grammar to properly highlight code inside initialization blocks (standalone { } blocks at class member level). The pattern matches standalone curly brace blocks and includes statement patterns for proper syntax highlighting, matching method body behavior. Fixes: forcedotcom/salesforcedx-vscode#4920 * test: Add tests for initialization block syntax highlighting Add comprehensive tests to verify initialization blocks are properly highlighted, including: - Empty initialization blocks - Method calls with string literals (the main issue #4920) - Multiple statements - Nested class scenario - Comparison with method body highlighting * test: Add test for static keyword before block Even though Apex doesn't support static initialization blocks, verify the grammar handles the syntax for highlighting purposes. * fix: Fix switch/when statement syntax highlighting and brace matching (issue #2134) (#74) * fix: support namespace-qualified types in extends/implements (issue #50) - Update extends-class pattern to handle namespace-qualified types - Update implements-class pattern to handle namespace-qualified types - Patterns now correctly tokenize System.Exception, Database.Batchable, etc. - Use lookahead to distinguish namespace-qualified from simple types - Fix type-builtin to support both 'Id' and 'ID' (Apex is case-insensitive) - Add test cases for namespace-qualified extends and implements Closes #50 * test: add coverage for both Id and ID (case-insensitive Apex) - Add test for Id (lowercase d) as field type - Add test for ID (uppercase D) as field type - Add test for Id in generic type parameters - Add test for ID in generic type parameters - Verifies Apex case-insensitive support for Id/ID primitive type * feat: support for varied casing on ID/Id * fix: Add syntax highlighting for initialization blocks Add initializer-block pattern to grammar to properly highlight code inside initialization blocks (standalone { } blocks at class member level). The pattern matches standalone curly brace blocks and includes statement patterns for proper syntax highlighting, matching method body behavior. Fixes: forcedotcom/salesforcedx-vscode#4920 * test: Add tests for initialization block syntax highlighting Add comprehensive tests to verify initialization blocks are properly highlighted, including: - Empty initialization blocks - Method calls with string literals (the main issue #4920) - Multiple statements - Nested class scenario - Comparison with method body highlighting * test: Add test for static keyword before block Even though Apex doesn't support static initialization blocks, verify the grammar handles the syntax for highlighting purposes. * fix: Fix switch/when statement syntax highlighting and brace matching - Remove lookbehind end patterns from all when-* statements that prevented proper brace matching - Update end patterns to use lookahead that ends on closing brace or next when clause - Improve when-string pattern to support multiple comma-separated strings - Fix issue #2134: syntax highlighting and brace matching for switch/when statements All switch statement tests passing. * fix: Fix dash highlighting in switch statement string literals - Remove quote character from when-statement pattern character class - Change from ['_\-[:alnum:]]+ to [_\-[:alnum:]]+ - Ensures string literals with dashes like 'de-CH' and 'fr-CH' are matched by when-string pattern - Add test case for string literals containing dashes in switch statements This fixes an issue where the when-statement pattern would incorrectly match string literals containing dashes, preventing proper syntax highlighting.
1 parent b6b7737 commit 5efbd5a

31 files changed

+1334
-61
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ jspm_packages/
2525

2626
# MacOS folder atttribute tracking
2727
**/.DS_Store
28+
29+
**/.sfdx
30+
**.sf

grammars/apex.tmLanguage

Lines changed: 142 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@
175175
<key>include</key>
176176
<string>#method-declaration</string>
177177
</dict>
178+
<dict>
179+
<key>include</key>
180+
<string>#initializer-block</string>
181+
</dict>
178182
<dict>
179183
<key>include</key>
180184
<string>#punctuation-semicolon</string>
@@ -309,6 +313,10 @@
309313
<key>include</key>
310314
<string>#comment</string>
311315
</dict>
316+
<dict>
317+
<key>include</key>
318+
<string>#dml-expression</string>
319+
</dict>
312320
<dict>
313321
<key>include</key>
314322
<string>#merge-expression</string>
@@ -693,6 +701,32 @@
693701
</dict>
694702
</array>
695703
</dict>
704+
<key>dml-expression</key>
705+
<dict>
706+
<key>begin</key>
707+
<string>\b(delete|insert|undelete|update|upsert)\b\s+(?!new\b)</string>
708+
<key>beginCaptures</key>
709+
<dict>
710+
<key>1</key>
711+
<dict>
712+
<key>name</key>
713+
<string>support.function.apex</string>
714+
</dict>
715+
</dict>
716+
<key>end</key>
717+
<string>(?&lt;=\;)</string>
718+
<key>patterns</key>
719+
<array>
720+
<dict>
721+
<key>include</key>
722+
<string>#expression</string>
723+
</dict>
724+
<dict>
725+
<key>include</key>
726+
<string>#punctuation-semicolon</string>
727+
</dict>
728+
</array>
729+
</dict>
696730
<key>merge-expression</key>
697731
<dict>
698732
<key>begin</key>
@@ -1328,22 +1362,49 @@
13281362
<key>extends-class</key>
13291363
<dict>
13301364
<key>begin</key>
1331-
<string>(extends)\b\s+([_[:alpha:]][_[:alnum:]]*)</string>
1365+
<string>(extends)\b\s+</string>
13321366
<key>beginCaptures</key>
13331367
<dict>
13341368
<key>1</key>
13351369
<dict>
13361370
<key>name</key>
13371371
<string>keyword.other.extends.apex</string>
13381372
</dict>
1339-
<key>2</key>
1340-
<dict>
1341-
<key>name</key>
1342-
<string>entity.name.type.extends.apex</string>
1343-
</dict>
13441373
</dict>
13451374
<key>end</key>
13461375
<string>(?={|implements)</string>
1376+
<key>patterns</key>
1377+
<array>
1378+
<dict>
1379+
<key>begin</key>
1380+
<string>(?=[_[:alpha:]][_[:alnum:]]*\s*\.)</string>
1381+
<key>end</key>
1382+
<string>(?={|implements)</string>
1383+
<key>patterns</key>
1384+
<array>
1385+
<dict>
1386+
<key>include</key>
1387+
<string>#support-type</string>
1388+
</dict>
1389+
<dict>
1390+
<key>include</key>
1391+
<string>#type</string>
1392+
</dict>
1393+
</array>
1394+
</dict>
1395+
<dict>
1396+
<key>match</key>
1397+
<string>([_[:alpha:]][_[:alnum:]]*)</string>
1398+
<key>captures</key>
1399+
<dict>
1400+
<key>1</key>
1401+
<dict>
1402+
<key>name</key>
1403+
<string>entity.name.type.extends.apex</string>
1404+
</dict>
1405+
</dict>
1406+
</dict>
1407+
</array>
13471408
</dict>
13481409
<key>implements-class</key>
13491410
<dict>
@@ -1359,6 +1420,23 @@
13591420
</dict>
13601421
<key>patterns</key>
13611422
<array>
1423+
<dict>
1424+
<key>begin</key>
1425+
<string>(?=[_[:alpha:]][_[:alnum:]]*\s*\.)</string>
1426+
<key>end</key>
1427+
<string>(?={|extends|,)</string>
1428+
<key>patterns</key>
1429+
<array>
1430+
<dict>
1431+
<key>include</key>
1432+
<string>#support-type</string>
1433+
</dict>
1434+
<dict>
1435+
<key>include</key>
1436+
<string>#type</string>
1437+
</dict>
1438+
</array>
1439+
</dict>
13621440
<dict>
13631441
<key>match</key>
13641442
<string>([_[:alpha:]][_[:alnum:]]*)\b\s*(,)?</string>
@@ -1376,6 +1454,10 @@
13761454
</dict>
13771455
</dict>
13781456
</dict>
1457+
<dict>
1458+
<key>include</key>
1459+
<string>#punctuation-comma</string>
1460+
</dict>
13791461
</array>
13801462
<key>end</key>
13811463
<string>(?={|extends)</string>
@@ -2436,6 +2518,36 @@
24362518
</dict>
24372519
</array>
24382520
</dict>
2521+
<key>initializer-block</key>
2522+
<dict>
2523+
<key>begin</key>
2524+
<string>\{</string>
2525+
<key>beginCaptures</key>
2526+
<dict>
2527+
<key>0</key>
2528+
<dict>
2529+
<key>name</key>
2530+
<string>punctuation.curlybrace.open.apex</string>
2531+
</dict>
2532+
</dict>
2533+
<key>end</key>
2534+
<string>\}</string>
2535+
<key>endCaptures</key>
2536+
<dict>
2537+
<key>0</key>
2538+
<dict>
2539+
<key>name</key>
2540+
<string>punctuation.curlybrace.close.apex</string>
2541+
</dict>
2542+
</dict>
2543+
<key>patterns</key>
2544+
<array>
2545+
<dict>
2546+
<key>include</key>
2547+
<string>#statement</string>
2548+
</dict>
2549+
</array>
2550+
</dict>
24392551
<key>variable-initializer</key>
24402552
<dict>
24412553
<key>begin</key>
@@ -2761,7 +2873,7 @@
27612873
<key>when-statement</key>
27622874
<dict>
27632875
<key>begin</key>
2764-
<string>(when)\b\s+([\'_\-[:alnum:]]+)\s*</string>
2876+
<string>(when)\b\s+([_\-[:alnum:]]+)\s*</string>
27652877
<key>beginCaptures</key>
27662878
<dict>
27672879
<key>1</key>
@@ -2781,7 +2893,7 @@
27812893
</dict>
27822894
</dict>
27832895
<key>end</key>
2784-
<string>(?&lt;=\})</string>
2896+
<string>(?=\})|(?=when\b)</string>
27852897
<key>patterns</key>
27862898
<array>
27872899
<dict>
@@ -2797,7 +2909,7 @@
27972909
<key>when-string</key>
27982910
<dict>
27992911
<key>begin</key>
2800-
<string>(when)\b\s*('[^'\n]*')(,)?</string>
2912+
<string>(when)\b\s*('[^'\n]*')(\s*(,)\s*('[^'\n]*'))*\s*</string>
28012913
<key>beginCaptures</key>
28022914
<dict>
28032915
<key>1</key>
@@ -2815,7 +2927,7 @@
28152927
</dict>
28162928
</array>
28172929
</dict>
2818-
<key>3</key>
2930+
<key>4</key>
28192931
<dict>
28202932
<key>patterns</key>
28212933
<array>
@@ -2825,9 +2937,19 @@
28252937
</dict>
28262938
</array>
28272939
</dict>
2940+
<key>5</key>
2941+
<dict>
2942+
<key>patterns</key>
2943+
<array>
2944+
<dict>
2945+
<key>include</key>
2946+
<string>#string-literal</string>
2947+
</dict>
2948+
</array>
2949+
</dict>
28282950
</dict>
28292951
<key>end</key>
2830-
<string>(?&lt;=\})</string>
2952+
<string>(?=\})|(?=when\b)</string>
28312953
<key>patterns</key>
28322954
<array>
28332955
<dict>
@@ -2858,7 +2980,7 @@
28582980
</dict>
28592981
</dict>
28602982
<key>end</key>
2861-
<string>(?&lt;=\})</string>
2983+
<string>(?=\})|(?=when\b)</string>
28622984
<key>patterns</key>
28632985
<array>
28642986
<dict>
@@ -2884,7 +3006,7 @@
28843006
</dict>
28853007
</dict>
28863008
<key>end</key>
2887-
<string>(?&lt;=\})</string>
3009+
<string>(?=\})|(?=when\b)</string>
28883010
<key>patterns</key>
28893011
<array>
28903012
<dict>
@@ -2895,6 +3017,10 @@
28953017
<key>include</key>
28963018
<string>#expression</string>
28973019
</dict>
3020+
<dict>
3021+
<key>include</key>
3022+
<string>#punctuation-comma</string>
3023+
</dict>
28983024
</array>
28993025
</dict>
29003026
<key>when-sobject-statement</key>
@@ -2920,7 +3046,7 @@
29203046
</dict>
29213047
</dict>
29223048
<key>end</key>
2923-
<string>(?&lt;=\})</string>
3049+
<string>(?=\})|(?=when\b)</string>
29243050
<key>patterns</key>
29253051
<array>
29263052
<dict>
@@ -4251,7 +4377,7 @@
42514377
<dict>
42524378
<key>match</key>
42534379
<string>(?x)
4254-
(?:(?:\b(this)\b)\s+)?
4380+
(?:(?:\b(this|final)\b)\s+)?
42554381
(?&lt;type_name&gt;
42564382
(?:
42574383
(?:ref\s+)? # ref return
@@ -4438,7 +4564,7 @@
44384564
<key>type-builtin</key>
44394565
<dict>
44404566
<key>match</key>
4441-
<string>\b(Blob|Boolean|byte|Date|Datetime|Decimal|Double|ID|Integer|Long|Object|String|Time|void)\b</string>
4567+
<string>\b(Blob|Boolean|byte|Date|Datetime|Decimal|Double|Id|ID|Integer|Long|Object|String|Time|void)\b</string>
44424568
<key>captures</key>
44434569
<dict>
44444570
<key>1</key>

0 commit comments

Comments
 (0)