Vscode-java: Organize Imports on Save breaks randomly

Created on 1 Oct 2018  路  7Comments  路  Source: redhat-developer/vscode-java

Hi,

how may I organize imports on file save?

The setting "java.saveActions.organizeImports": true does nothing.

Environment
  • Operating System: Windows 10
  • JDK version: OpenJDK 1.8.0_172
  • Visual Studio Code version: 1.27.2 (user setup)
  • Java extension version: please...what?
Steps To Reproduce
  1. Go to settings
  2. add "java.saveActions.organizeImports": true
  3. Open a java file
  4. insert a non used import like "import java.awt.color.*;"
  5. Hit Ctrl + S
  6. See that nothing happens
  7. Hit Ctrl + Alt + O
  8. See the import is cleaned
Current Result

Cleanup not performed on save.

Expected Result

Cleanup should be performed on save.

Additional Informations

I opened a Java Maven project (Eclipse project).

bug need info

Most helpful comment

@bundery could you try the following settings:

"editor.codeActionsOnSave": {
    "source.organizeImports": true
},
"java.saveActions.organizeImports": false

All 7 comments

works for me. Try enabling verbose logging in your settings.json ("java.trace.server": "verbose"), and paste the logs here

btw

Java extension version: please...what?
screen shot 2018-10-03 at 6 21 30 pm
-> 0.32.0 here

Thanks for your reply. I got 0.31.0 and now upgraded to 0.32.0.

Edit: Log

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:23.573
!MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:23.773
!MESSAGE >> workspace/executeCommand vscode.java.test.fetch

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:23.776
!MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.008
!MESSAGE >> document/didChange

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.187
!MESSAGE >> document/didChange

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.432
!MESSAGE >> workspace/executeCommand vscode.java.test.fetch

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.435
!MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.532
!MESSAGE >> document/documentSymbol

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.581
!MESSAGE >> document/formatting

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.628
!MESSAGE >> document/didChange

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.739
!MESSAGE begin problem for /OpenInNewWindowAction.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.742
!MESSAGE 5 problems reported for /OpenInNewWindowAction.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.746
!MESSAGE Reconciled 0, validated: 1. Took 155 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.750
!MESSAGE >> document/willSaveWailUntil

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.854
!MESSAGE >> document/didSave

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.943
!MESSAGE >> workspace/executeCommand vscode.java.test.fetch

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.946
!MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:24.984
!MESSAGE >> document/documentSymbol

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:25.204
!MESSAGE >> workspace/didChangeWatchedFiles 

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:25.209
!MESSAGE >> workspace/executeCommand vscode.java.test.fetch

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:25.214
!MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:25.332
!MESSAGE begin problem for /OpenInNewWindowAction.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:25.335
!MESSAGE 5 problems reported for /OpenInNewWindowAction.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:27:25.336
!MESSAGE Reconciled 0, validated: 1. Took 187 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:28:22.255
!MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:28:22.468
!MESSAGE >> workspace/executeCommand vscode.java.test.fetch

!ENTRY org.eclipse.jdt.ls.core 1 0 2018-10-05 09:28:22.470
!MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

This issue is still seen in the latest vscode editor.

This issue is still seen in the latest vscode editor.

@snjeza I believe this is what I saw in https://github.com/eclipse/eclipse.jdt.ls/pull/1415#issuecomment-617941928. My guess is the Compilation Unit is not reconciled properly at that point.

@bundery could you try the following settings:

"editor.codeActionsOnSave": {
    "source.organizeImports": true
},
"java.saveActions.organizeImports": false

I have also never been able to get this settings to work. This includes two completely separate installations and maven projects.

The workaround / tip provided by @snjeza does work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ViniciusAtaide picture ViniciusAtaide  路  4Comments

danielcalvogonzalez picture danielcalvogonzalez  路  3Comments

roben picture roben  路  4Comments

ulongx picture ulongx  路  4Comments

joewood picture joewood  路  3Comments