Comments (23)
Hey guys, I've started working on a prettier plugin for Apex at https://github.com/dangmai/prettier-plugin-apex Right now the formatting is still a mess, but I'm prioritizing printing out the correct AST first. The lack of comments is definitely a challenge but I do have some ideas on how to tackle it in the short term at least. Feel free to contribute code/ideas.
from salesforcedx-vscode.
@vazexqi Or open source the AST? :-)
from salesforcedx-vscode.
Uncrustify for VS Code does work to format Apex whilst this is being sorted out. Much needed feature, I agree.
from salesforcedx-vscode.
@dangmai letβs have a chat and see how we can help. Email me [email protected]
from salesforcedx-vscode.
I've confirmed with our Apex compiler team that:
- Comments are not retained at this time.
- White space is also not retained at this time. This usually doesn't create an issue except for the case where prettier/prettier actually respects double new lines and lets you keep it as-is. So if we don't retain whitespace, we cannot detect the case of double-newlines and preserve that.
2 is not a big of a blocker. 1 is a blocker. I'll update when I hear back more on what we can do to get the comments in.
from salesforcedx-vscode.
Just a quick update.
- Comments are now being retained as part of the Apex compiler. The compiler team made good progress on that this release.
- However, we prioritized getting Switch Statement support (See Switching It Up With Apex) for code completion, code navigation, and debugger so we have not had much progress on the formatter yet.
from salesforcedx-vscode.
This is now supported using Apex Prettier. See documents for setup: https://forcedotcom.github.io/salesforcedx-vscode/articles/getting-started/prettier
from salesforcedx-vscode.
Yes this is possible with the Language Server Protocol. See https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_formatting
I am partial to the style that Prettier uses (which is based on A prettier printer). This needs a bit of thinking, though:
- [Technical] The current Apex AST doesn't record the comments so we would lose them if we only rely on AST. Some work needs to be done here. I don't have an estimate yet on the work needed.
- [Style] The prettier style is very opionated and doesn't offer many configurations. This is why I like it but others might hate it.
from salesforcedx-vscode.
@vazexqi so the latest prettier release allows a config file to allow more control over the project can be formatted. I like the opinion as well since I don't have to think about it but with the route prettier is going it seems like a lot of the issues people can be configured.
But as it seems the AST doesn't keep comments, looks like we would have to wait on trying to implement this correct?
from salesforcedx-vscode.
This feature actually is a big hurdle.
is all needed info and API accessible for public in order to get this task done?
Also how deep do we need to dig into, AST and Language server APIs?
It sounds like a good practice on learning how to write CSV plugin and talk to Apex language server!
from salesforcedx-vscode.
@Xixiao007 - Thanks for the interest. There is a dependency on #305 that blocks public contributions for now :-( We are discussing that now and how we can enable that.
from salesforcedx-vscode.
@vazexqi got it, then looking forward.
One silly question though, can I use JAVA auto formatting plugins on Apex to serve the purpose? (I didn't get it work on my side)
from salesforcedx-vscode.
Hey @vazexqi
Any word on an ETA for this?
from salesforcedx-vscode.
@SalesforceBobLightning Unfortunately, it's at least 6 months out.
from salesforcedx-vscode.
@ntotten is the plan to contribute to prettier or open source the formatting so all IDEs can use it?
from salesforcedx-vscode.
See #707
from salesforcedx-vscode.
Any progress here? I just started using Uncrustify after getting frustrated trying to get prettier to work for the 3rd time.
from salesforcedx-vscode.
@Stragis:
@dangmai has an RC out for Apex prettier: https://github.com/dangmai/prettier-plugin-apex
from salesforcedx-vscode.
any update over here
from salesforcedx-vscode.
@riteshkonduru have you tried: https://github.com/dangmai/prettier-plugin-apex ?
from salesforcedx-vscode.
I'm using prettier-plugin-apex+VSCode+Prettier Extension for VSCode and done setting "true" format on save. But can't format and was display "There is no formatter for 'apex' files installed" message on VSCode. How can I setup format on save?
from salesforcedx-vscode.
from salesforcedx-vscode.
I have it installed locally and am running into the same problem, the document link on how to set it up also returns a 404
from salesforcedx-vscode.
Related Issues (20)
- Change Default Org does not show the already connected orgs. Unable to change the Default Org HOT 4
- Unable to change the default org if nodes in config.json are not in the right order HOT 3
- Command 'SFDX: Launch Apex Replay Debugger with Current File' resulted in an error HOT 4
- Apex extension stopped working in big repos HOT 8
- RuntimeNamespace error HOT 5
- Code coverage highlighting no longer displaying and returns error message on Apex v60.8.0 HOT 10
- SFDX: Authorize an Org failed to runv HOT 7
- Failure performing refresh sObject describe request HOT 28
- Apex Tests Sidebar includes non-existent Apex Test Classes HOT 9
- 'Expected double-quoted property name in JSON at position 62273' Code Coverage NOT WORKING HOT 2
- sfdx apex:test:run command in CI passes run with lower test coverage HOT 2
- Apex Language Server Fails to Start - Expected the service ApexIndexer [FAILED] to be RUNNING HOT 5
- The unpackaged Apex tests execution after unit tests execution should fail when the code coverage is less than 75% HOT 3
- The Outline window gets broken if there is an abstract method in the class HOT 3
- Issues retrieving code coverage for a large codebase HOT 12
- Running Interactive debugger doesn't show Variables HOT 5
- Very slow
- The test class runs very slowly HOT 6
- Error when the command npm i @salesforce/lwc-dev-server HOT 3
- LWC LightningComponentBundle is not working for target in vs code HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from salesforcedx-vscode.