-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add-import on completion #96
Comments
Following so I guess you suppose it is triggered on save because some IDEs autoformat on save, am I right? We attend The additionalEdits makes sense, let me check if we are taking care of that when we receive the completionItems. Seems we need to call |
Confirmed: After call
We are still not taking care of additionalTextEdits, but as seen it's just plumbings |
It's a bit trickier than just connecting additionalTextEdits <--> existing formatting code. Imports are sometimes ambiguous, but when completing you have additional context: the user has selected a specific not-yet-imported class, so you know which import needs to be added. Same is true for code actions. So, you will probably need to refactor the formatting code a bit to make it reusable for codeActions and completions, but it shouldn't be too difficult. |
This patch introduces a new interface to represent the import order. We also provide its two implementations: the simple one (all imports in a single section with lexicographical order), and the one conforming to the Chromium Java style guide (which I use for my project). The interface is used in two places: the existing logic to add an import as a quick fix, and the new logic to add an import on completing class names. The style can be configured by user settings. Fixes georgewfraser#96
This patch introduces a new interface to represent the import order. We also provide its two implementations: the simple one (all imports in a single section with lexicographical order), and the one conforming to the Chromium Java style guide (which I use for my project). The interface is used in two places: the existing logic to add an import as a quick fix, and the new logic to add an import on completing class names. The style can be configured by user settings. Fixes georgewfraser#96
This patch introduces a new interface to represent the import order. We also provide its two implementations: the simple one (all imports in a single section with lexicographical order), and the one conforming to the Chromium Java style guide (which I use for my project). The interface is used in two places: the existing logic to add an import as a quick fix, and the new logic to add an import on completing class names. The style can be configured by user settings. Fixes georgewfraser#96
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:
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
The text was updated successfully, but these errors were encountered: