Skip to content

Auto-import was not triggered automatically in some cases #1098

Closed

Description

@EricZhangzf

Environment

  • Operating System: Win/Mac/Linux
  • JDK version: 13/12/8
  • Visual Studio Code version:1.39.2
  • Java extension version:0.51.0

Steps To Reproduce

  1. Make sure java.actionsOnPaste.organizeImports in settings is true.
  2. New Foo.java with codes as below:
import java.io.File;
 
public class Foo {
 
     public static void main(String[] args) {
        File f =new File("A.txt");
    }
}

Result:

  1. If copy the main method to another empty java file
    Auto-import was not triggered automatically.
    image

  2. If copy the all class to another empty java file
    Auto-import was triggered automatically.
    image

Activity

  1. fbricon commented on Oct 16, 2019

    @fbricon
    Collaborator

    The feature is expected to work when pasting into an empty file. It seems you're trying to paste in a file that already has a class definition, so it's not empty.

    Triggering autoimport when pasting in non-empty files might cause some issues eventually, that's why I'd prefer not to enable it at this time.

  2. testforstephen commented on Oct 16, 2019

    @testforstephen
    Collaborator

    Copying a method (even a code block) to an existing class is a higher frequency operation, so supporting copying a method is more helpful for me.

  3. fbricon commented on Oct 16, 2019

    @fbricon
    Collaborator

    Copying a method (even a code block) to an existing class is a higher frequency operation, so supporting copying a method is more helpful for me.

    Fair enough. Let's try it then, I'll mark the feature as experimental.

  4. added this to the Mid October 2019 milestone on Oct 16, 2019
  5. leonardofel commented on Oct 18, 2019

    @leonardofel

    oh very nice feature, but has a little problem...
    wtf
    Is an automatically activated experimental feature really necessary?

  6. fbricon commented on Oct 21, 2019

    @fbricon
    Collaborator

    @leonardofel can you please open a new ticket?

    The best way to expose users to the new feature is to enable it automatically. I reckon this was a bit risky, but since this can be disabled, I'm not too worried. In any case, we'll either fix your problem or backpedal on the enable-by-default bit.

  7. fbricon commented on Oct 21, 2019

    @fbricon
    Collaborator

    @leonardofel #1112 was opened about that issue

  8. leonardofel commented on Oct 21, 2019

    @leonardofel

    @leonardofel can you please open a new ticket?

    The best way to expose users to the new feature is to enable it automatically. I reckon this was a bit risky, but since this can be disabled, I'm not too worried. In any case, we'll either fix your problem or backpedal on the enable-by-default bit.

    I understand... this bug occurs when I paste during multicursor, anyway thx for the reply, waiting for future fix

  9. fbricon commented on Oct 22, 2019

    @fbricon
    Collaborator

    @leonardofel you can install the latest CI build containing the fix, from https://download.jboss.org/jbosstools/jdt.ls/staging/?C=M;O=D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions