Skip to content

Conversation

@arturbalabanov
Copy link

@arturbalabanov arturbalabanov commented Feb 2, 2025

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 with item.user_data.nvim.lsp.completion_item.data.autoImportText which 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_import function 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.[].newText as 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 contains from typing import Any and we want to autoimport dataclass_transform, the values of newText would be from typing_extensions import dataclass_transform and , dataclass_transofrm, the latter referring to appending to the existing import.

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

Successfully merging this pull request may close these issues.

1 participant