Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier fails when trying to format Apex using the ?. or ?? operators #1379

Closed
naveen1883 opened this issue May 10, 2024 · 4 comments
Closed

Comments

@naveen1883
Copy link

'Prettier' code formatter for Apex does not currently support ?. or ?? operators, so it will not format Apex using those operators. To bypass this, you can replace those operators and then try formatting. After formatting, you can undo-replace those operators (don't use Control + Z since it will undo the code formatting done by 'Prettier').

Sample VS Code find-replace expressions:

replace ?.
from: ?.
todo: /?./.

undo replace ?.
from: /?./.
todo: ?.

replace ??
from: ??
todo: /??/ ==

undo replace ??
from: /??/ ==
todo: ??

@dangmai
Copy link
Owner

dangmai commented May 10, 2024

@dangmai dangmai closed this as completed May 10, 2024
@naveen1883
Copy link
Author

naveen1883 commented May 10, 2024

Hey @dangmai, thank you for replying. I thought Prettier didn't support ?? and ?. since that is what the error message was saying when I tried formatting using the 2.0.1 version. I have updated to the latest version (2.1.4) and tried formatting the same file which uses these operators and now I am getting a different error.

["ERROR" - 3:46:39 PM] Error formatting document.
["ERROR" - 3:46:39 PM] No handler found for apex.jorje.data.ast.Expr$NullCoalescingExpr. Please file a bug report.
Error: No handler found for apex.jorje.data.ast.Expr$NullCoalescingExpr. Please file a bug report.

Am I missing something that needs to be configured?

@dangmai
Copy link
Owner

dangmai commented May 10, 2024

Hello, please restart VSCode, it should work afterwards.

@naveen1883
Copy link
Author

Thank you very much! That fixed it. Also just read #1176 which explained the same thing. Should've done that before opening an issue. Thank you once again!

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

No branches or pull requests

2 participants