Skip to content

fix: support final keyword in method parameters W-20084355 - #67

Merged
mshanemc merged 4 commits into
mainfrom
fix/issue-49-final-parameter
Nov 4, 2025
Merged

mshanemc merged 4 commits into
mainfrom
fix/issue-49-final-parameter

Conversation

@mshanemc

@mshanemc mshanemc commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

see closed stacked PRs for visual proofs (you can get to them by looking at the issue and following the links)

closes issues from grammar repo (represented by @W-20084355@)

#50
#49
#44
#43
#26

closes issues from vscode repo that were also GUS WI

@W-16795524@ aka forcedotcom/salesforcedx-vscode#5031
@W-19265631@ aka forcedotcom/salesforcedx-vscode#4920
@W-10935217@ aka
forcedotcom/salesforcedx-vscode#2134

QA: there's now an sfdx project in the grammar repo on this PR. That's for visually inspecting. To use

  1. yarn build
  2. copy to vscode like yarn build && cp grammars/apex.tmLanguage ../salesforcedx-vscode/packages/salesforcedx-vscode-apex/grammars
  3. in vscode repo, disable the copy-files (that'll try to copy files from node_modules and undo step 2). Maybe step 2 would be better if you copied it into the equivalent node_modules grammar?
  4. launch ext and open the repros project from this repo

mshanemc and others added 3 commits October 30, 2025 12:04
- Update parameter rule to recognize final keyword before type
- Add test case for method parameters with final keyword
- Fixes issue #49

The parameter rule previously only supported 'this' keyword as an optional
modifier. This change extends it to also support 'final', which is commonly
used in Apex to prevent parameter reassignment.

Closes #49
- 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 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
@mshanemc mshanemc changed the title fix: support final keyword in method parameters fix: support final keyword in method parameters W-20084355 Oct 30, 2025
* 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.
*/
public class AnnotationOnSameLine_PR68_PR69 {

@Future(callout=true) public static void futureMethod() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These repro classes were helpful for the QA and such but do we need to keep them in the repo? I can see the benefit of having easily accessible test materials like this to check for regressions at a later point. But curious to hear what the rationale behind leaving these in vs the traditional unit tests alone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the UT weren't good enough, especially if you (like me) don't have a solid understanding of the grammar yml. I found it helpful to have some files to open and see the effects of that changes. Sometimes the test would pass but it didn't "look right"

[I wish I could visual-snapshot them, but I don't know how to do the "syntax highlighting" stuff outside of vscode]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It 100% made recreating the QA scenarios so much easier to manually inspect. I'm ok to keep the resource like this for other testing scenarios later too.

Comment thread test/utils/tokenize.ts
export const Decimal = createToken('Decimal', 'keyword.type.apex');
export const Double = createToken('Double', 'keyword.type.apex');
export const ID = createToken('ID', 'keyword.type.apex');
export const ID = createToken('Id', 'keyword.type.apex');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this actually something that's case sensitive?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing in apex is case sensitive. I personally think the "Id" is more consistent with the rest of the primitive types
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_primitives.htm and am used to seeing it written that way in the ecosystem
cf https://github.com/search?q=org%3Atrailheadapps+id+language%3AApex&type=code

but with the syntax highlighting, you have to have ID. So I wanted to "fix" it to support the vernacular without breaking what we've previously supported.

image

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me. Having both available is nice so I get what you're going for now. Agreed!

@kylewalke kylewalke left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple q's but QA passes and everything I was able to see from the related PR's looked good!

@mshanemc
mshanemc merged commit a6af492 into main Nov 4, 2025
14 checks passed
@mshanemc
mshanemc deleted the fix/issue-49-final-parameter branch November 4, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants