Giter VIP home page Giter VIP logo

Comments (23)

dangmai avatar dangmai commented on June 19, 2024 6

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.

JAertgeerts avatar JAertgeerts commented on June 19, 2024 5

@vazexqi Or open source the AST? :-)

from salesforcedx-vscode.

Szandor72 avatar Szandor72 commented on June 19, 2024 4

Uncrustify for VS Code does work to format Apex whilst this is being sorted out. Much needed feature, I agree.

from salesforcedx-vscode.

ntotten avatar ntotten commented on June 19, 2024 4

@dangmai let’s have a chat and see how we can help. Email me [email protected]

from salesforcedx-vscode.

vazexqi avatar vazexqi commented on June 19, 2024 2

I've confirmed with our Apex compiler team that:

  1. Comments are not retained at this time.
  2. 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.

vazexqi avatar vazexqi commented on June 19, 2024 2

Just a quick update.

  1. Comments are now being retained as part of the Apex compiler. The compiler team made good progress on that this release.
  2. 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.

ntotten avatar ntotten commented on June 19, 2024 1

This is now supported using Apex Prettier. See documents for setup: https://forcedotcom.github.io/salesforcedx-vscode/articles/getting-started/prettier

from salesforcedx-vscode.

vazexqi avatar vazexqi commented on June 19, 2024

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.

brandonmikeska avatar brandonmikeska commented on June 19, 2024

@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.

xixiaofinland avatar xixiaofinland commented on June 19, 2024

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.

vazexqi avatar vazexqi commented on June 19, 2024

@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.

xixiaofinland avatar xixiaofinland commented on June 19, 2024

@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.

SalesforceBobLightning avatar SalesforceBobLightning commented on June 19, 2024

Hey @vazexqi

Any word on an ETA for this?

from salesforcedx-vscode.

ntotten avatar ntotten commented on June 19, 2024

@SalesforceBobLightning Unfortunately, it's at least 6 months out.

from salesforcedx-vscode.

brandonmikeska avatar brandonmikeska commented on June 19, 2024

@ntotten is the plan to contribute to prettier or open source the formatting so all IDEs can use it?

from salesforcedx-vscode.

ntotten avatar ntotten commented on June 19, 2024

See #707

from salesforcedx-vscode.

Stragis avatar Stragis commented on June 19, 2024

Any progress here? I just started using Uncrustify after getting frustrated trying to get prettier to work for the 3rd time.

from salesforcedx-vscode.

praksb avatar praksb commented on June 19, 2024

@Stragis:
@dangmai has an RC out for Apex prettier: https://github.com/dangmai/prettier-plugin-apex

from salesforcedx-vscode.

riteshkonduru avatar riteshkonduru commented on June 19, 2024

any update over here

from salesforcedx-vscode.

praksb avatar praksb commented on June 19, 2024

@riteshkonduru have you tried: https://github.com/dangmai/prettier-plugin-apex ?

from salesforcedx-vscode.

k010c1232 avatar k010c1232 commented on June 19, 2024

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.

Stragis avatar Stragis commented on June 19, 2024

from salesforcedx-vscode.

iamricardo avatar iamricardo commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.