Include missing imports by changing how the diagnostics are filtered out #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for the awesome plugin! I wanted to write something similar but I'm so glad I checked to see what's out there and was delighted to see this project :)
As discussed in #1 the plugin doesn't suggest all the possible imports and I did some digging and found the root cause. For some reason not all diagnostic items have
item.user_data.nvim.lsp.completion_item.labelDetails.description. The plugin is filtering these out as it needs it in the display but nothing else it seems. I replaced this withitem.user_data.nvim.lsp.completion_item.data.autoImportTextwhich seems to contain the import statement to be added, so I used that instead.This makes the change not strictly backwards-compatible but couldn't find another way to do it and personally I prefer to see the exact import in the list. We can also extract the
format_importfunction into a config option in the future but I think it's fine as it is (for my needs at least).Another option is to use the
item.user_data.nvim.lsp.completion_item.additionalTextEdits.[].newTextas this contains the exact changes that will be applied but that has weird edge cases I didn't want to both implementing. For example, if the file already containsfrom typing import Anyand we want to autoimportdataclass_transform, the values ofnewTextwould befrom typing_extensions import dataclass_transformand, dataclass_transofrm, the latter referring to appending to the existing import.