Skip to content

Add-import on completion #96

@georgewfraser

Description

@georgewfraser

Right now, we automatically add imports on save: https://github.com/georgewfraser/java-language-server/blob/incremental/src/main/java/org/javacs/CompileBatch.java#L291

This works well for scenarios like copy-pasting large blocks of code, but it doesn't work great when you autocomplete:

  • User starts typing the name of an unimported class
  • User selects a particular unimported class and tab completes
  • This class is still not imported, so subsequent autocomplete is broken until the user saves

For example, new SomeNotImportedClass()._ will not autocomplete.

The Language Server Protocol provides for this exact scenario with CompletionItem#additionalTextEdits: https://microsoft.github.io/language-server-protocol/specification#textDocument_completion

Related: #95, #44

@albfan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions