Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error for missing import #1266

Closed
anthonyvdotbe opened this issue Feb 11, 2020 · 4 comments
Closed

No error for missing import #1266

anthonyvdotbe opened this issue Feb 11, 2020 · 4 comments

Comments

@anthonyvdotbe
Copy link

As a follow-up to #1265: sometimes there's no error reported for a missing import

Environment
  • Operating System: Windows 10
  • JDK version: JDK 13
  • Visual Studio Code version: VS Code 1.42.0
  • Java extension version: 0.55.1
Steps To Reproduce

Copy-paste the code below in a Java file. Note that there's no error reported for the missing import of java.util.List

import java.util.Map;

class Test {

    static class Employee {

        final String name;

        Employee(String name) {
            this.name = name;
        }

        String name() {
            return name;
        }

    }

    public static void main(String... args) {
        var totals = Map.of(new Employee("John"), 0);
        Employee e = new Employee("Jane");
        //totals.put(e., 0);
        List.of("foo").forEach(item -> {
            totals.put(null, 0);
        });
    }

}
Current Result

image

Expected Result

An error is reported on the usage of List.of

@snjeza
Copy link
Contributor

snjeza commented Feb 11, 2020

I can't reproduce the issue.

1266

Could you attach a project example?

@anthonyvdotbe
Copy link
Author

Most likely it's because I was using a stand-alone file, and so had an "incomplete classpath", isn't it? If so, you can close this issue.

@snjeza snjeza closed this as completed Feb 12, 2020
@testforstephen
Copy link
Collaborator

@anthonyvdotbe When you open an external Java (aka stand-alone) file in VS Code, we only show syntax errors. The quickfix for missing import won't be enabled. If you want to import all missing types quickly, you can use the global Organize imports command (Shift + Alt + O) for that.

@anthonyvdotbe
Copy link
Author

@testforstephen Thanks for the tip. While I know about the command, because there are no visual clues that doing Organize imports might help, I simply don't think of doing it. I filed #1270 as a follow-up issue to improve support for standalone files.

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

No branches or pull requests

3 participants