feat: completions imports exclude supports sub items#22416
Conversation
Example
---
**Before this PR**
```json
{
"rust-analyzer.completion.autoimport.exclude": [
{"path":"std::intrinsics::AtomicOrdering","type":"always"},
{"path":"std::intrinsics::ConstParamTy","type":"always"},
// ... 223 items
]
}
```
**After this PR**
```json
{
"rust-analyzer.completion.autoimport.exclude": [
{"path":"std::intrinsics","type":"subItems"},
]
}
```
|
Intrinsics won't be completed anymore after #22044. Is there another motivation? |
|
Like |
|
Fair enough. |
What do you mean? |
| let method_imported = import.item_to_import != import.original_item; | ||
| if method_imported | ||
| && (is_exclude_flyimport.is_some() | ||
| && (is_exclude_flyimport == Some(AutoImportExclusionType::Methods) |
There was a problem hiding this comment.
While it does not make things less correct, it also does not make them more correct; therefore I see no reason for this change.
| /// For traits the type "methods" can be used to only exclude the methods but not the trait | ||
| /// itself. | ||
| /// | ||
| /// For modules the type "subItems" can be used to only exclude the sub items but not the module |
There was a problem hiding this comment.
| /// For modules the type "subItems" can be used to only exclude the sub items but not the module | |
| /// For modules, the type "subItems" can be used to exclude the module and all items in it. This does not include items defined in nested modules. |
We should also consider whether it should really exclude the module itself, probably not but then the problem is that there is no way to exclude both.
There was a problem hiding this comment.
but then the problem is that there is no way to exclude both.
Both can be excluded, such as:
Oh, maybe we can add a SmallVec<AutoImportExclusiveType>?
There was a problem hiding this comment.
Or ide_completion::AutoImportExclusionType::SubItems { with_self: bool } and AutoImportExclusionType::SubItemsAndSelf?
There was a problem hiding this comment.
However, I think it is more reasonable not to exclude the module itself.
Taking std::arch::aarch64::float16x8_t as an example, not wanting to import it also means that if necessary, we would prefer to have auto import of std::arch::aarch64 it self, to use aarch64::float16x8_t
There was a problem hiding this comment.
However, I think it is more reasonable not to exclude the module itself.
We should also consider whether it should really exclude the module itself, probably not
That's what I said too.
There was a problem hiding this comment.
"sub items" is not clear enough. That's why I used the term "items defined in this module".
| "enumDescriptions": [ | ||
| "Do not show this item or its methods (if it is a trait) in auto-import completions.", | ||
| "Do not show this traits methods in auto-import completions." | ||
| "Do not show this traits methods in auto-import completions.", |
There was a problem hiding this comment.
| "Do not show this traits methods in auto-import completions.", | |
| "Do not show this trait's methods in auto-import completions.", |
A preexisting grammatical mistake.
| "Do not show this item or its methods (if it is a trait) in auto-import completions.", | ||
| "Do not show this traits methods in auto-import completions." | ||
| "Do not show this traits methods in auto-import completions.", | ||
| "Do not show this modules sub items in auto-import completions." |
There was a problem hiding this comment.
| "Do not show this modules sub items in auto-import completions." | |
| "Do not show this modules and items defined in it in auto-import completions.", |
I mean that I agree this is something worth having. |
53e7d3a to
ef9e665
Compare
Close #20468
Similar to implementing #20468 (comment) , but non-based string
Example
Before this PR
{ "rust-analyzer.completion.autoimport.exclude": [ {"path":"std::intrinsics::AtomicOrdering","type":"always"}, {"path":"std::intrinsics::ConstParamTy","type":"always"}, // ... 223 items ] }After this PR
{ "rust-analyzer.completion.autoimport.exclude": [ {"path":"std::intrinsics","type":"subItems"}, ] }