redhat-developer / vscode-java

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

Import from code actions doesn't work well after delete java file which is created from code actions #3663

Closed yuyully closed 1 month ago

yuyully commented 4 months ago
Environment
Steps To Reproduce
  1. Set "editor.pasteAs.enabled": false in settings.json
  2. Copy and paste File f = new File("demo.txt"); in java file > Save file > Select 'create class 'File'' from code actions > Delete the new created File.java > import from code actions doesn't work
  3. Copy and paste List<String> stringList = new ArrayList<>(); in java file > Save file > Select 'create class 'List'' from code actions > Delete the new created List.java > import from code actions is missing
Current Result

import not work import is missing

Expected Result
Additional Informations
rgrunber commented 1 month ago

I'm able to reproduce this and have some idea of how we could go about fixing it. Can you confirm that just typing anything (even a space) in the file, restores the expected "Import List (java.util)" ?

This looks like a case of the AST model being stale resulting in some incorrect quick-fix suggestions. Modifying the contents of the file in any ways retriggers some operations that restore things.

yuyully commented 1 month ago

Can you confirm that just typing anything (even a space) in the file, restores the expected "Import List (java.util)" ?

Yes, if typing something before select code actions, all work fine.

rgrunber commented 1 month ago

Not exactly the same as https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/1918 , but similar. Basically the cached AST model was out of date.