Skip to content

Generate formatter settings from the server instead of a static file - #4579

Open
robstryker wants to merge 1 commit into
redhat-developer:mainfrom
robstryker:java-format-settings-generator
Open

robstryker wants to merge 1 commit into
redhat-developer:mainfrom
robstryker:java-format-settings-generator

Conversation

@robstryker

Copy link
Copy Markdown
Contributor

Summary

Requires eclipse-jdtls/eclipse.jdt.ls#3989.

java.open.formatter.settings (added 2018, last touched 2021) created a new settings file by
byte-copying a bundled static template, formatters/eclipse-formatter.xml - 405 undocumented,
uncommented options with no curation, frozen at whatever Eclipse defaults were true when that file
was last updated by hand.

This replaces the static copy with a live call to the server's new
java.project.generateFormatterSettings command, which generates the same kind of file from the
project's actual current effective settings, with the ~25 most commonly customized options
documented and live at the top and everything else present but commented out - something to find
and uncomment instead of a wall of undocumented options or no file at all.

Also fixed/cleaned up while already touching this code

  • java.format.settings.url was being updated before the file write was confirmed to succeed - a
    user declining the old "are you sure?" dialog, or a failed write, used to leave the setting
    pointing at a file that doesn't exist. Now it's only updated after a successful write.
  • Dropped the redundant second confirmation dialog ("are you sure you want to create it?") on top of
    the existing input-box prompt - one clear ask instead of two for what's now a single action.
  • Added a cross-link from java.format.settings.url's own description to this command, so a user
    looking at that setting (the natural place to look when wondering how to customize formatting) can
    discover it without already knowing it exists via the wiki or Command Palette.

The workspace-root-vs-global file location logic, the already-configured/remote-URL fast paths, and
the command id (java.open.formatter.settings) are all unchanged.

Test plan

  • tsc --noEmit compiles clean
  • npm run eslint passes clean
  • Manually verify: run "Open Java Formatter Settings" with no java.format.settings.url set, in
    a workspace with no existing formatter file - confirm the input box prompt appears, the
    generated file is written to the workspace root, the setting gets updated, and the file opens
    with the new curated/commented format
  • Manually verify the already-configured and remote-URL fast paths are unaffected

java.open.formatter.settings (added 2018, last touched 2021) created a
new settings file by byte-copying a bundled static template,
formatters/eclipse-formatter.xml - 405 undocumented, uncommented
options with no curation, frozen at whatever Eclipse defaults were
true when that file was last updated by hand.

Replace the static copy with a live call to the server's new
java.project.generateFormatterSettings command (eclipse-jdtls/eclipse.jdt.ls),
which generates the same kind of file from the project's actual
current effective settings, with the ~25 most commonly customized
options documented and live at the top and everything else present
but commented out - something to find and uncomment instead of a wall
of undocumented options or no file at all.

Also, while already touching this code:
- Fixed java.format.settings.url being updated before the file write
  was confirmed to succeed - a user declining or a write failing used
  to leave the setting pointing at a file that doesn't exist.
- Dropped the redundant second confirmation dialog ("are you sure you
  want to create it?") on top of the existing input-box prompt - one
  clear ask instead of two for what's now a single action.
- Added a cross-link from java.format.settings.url's own description
  to this command, so a user looking at that setting (the natural
  place to look when wondering how to customize formatting) can
  discover it without already knowing it exists via the wiki or
  Command Palette.

The workspace-root-vs-global file location logic, the already-
configured/remote-URL fast paths, and the command id are all
unchanged.

This branch has not been deployed

No deployments
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.

1 participant