redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 433 forks source link

Format document doesn't work when document is not saved #3716

Open geoff-m opened 2 months ago

geoff-m commented 2 months ago

Formatting the document does not work when the document is not saved to disk.

Environment
Steps To Reproduce
  1. File >> New Text File
  2. Put some Java code in the new document that would be changed by formatting. If the language mode is not automatically detected as Java, set it manually.
  3. Right-click anywhere in the document and click Format document.
Current Result

Nothing happens.

Expected Result

The code gets formatted.

fbricon commented 2 months ago

Indeed the language server needs a java file to exist in order to perform. Now, you can try creating a new empty file, save it as a .java file, then paste your java code, formatting should work without resaving the file.