Skip to content

feat: completions imports exclude supports sub items#22416

Open
A4-Tacks wants to merge 3 commits into
rust-lang:masterfrom
A4-Tacks:exclude-module-items
Open

feat: completions imports exclude supports sub items#22416
A4-Tacks wants to merge 3 commits into
rust-lang:masterfrom
A4-Tacks:exclude-module-items

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented May 21, 2026

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"},
    ]
}

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"},
    ]
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 21, 2026
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Intrinsics won't be completed anymore after #22044. Is there another motivation?

@A4-Tacks
Copy link
Copy Markdown
Member Author

Like std::arch::aarch64:: with >7000 items

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Fair enough.

@A4-Tacks
Copy link
Copy Markdown
Member Author

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)
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it does not make things less correct, it also does not make them more correct; therefore I see no reason for this change.

View changes since the review

Comment thread crates/rust-analyzer/src/config.rs Outdated
/// 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
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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.

View changes since the review

Copy link
Copy Markdown
Member Author

@A4-Tacks A4-Tacks May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or ide_completion::AutoImportExclusionType::SubItems { with_self: bool } and AutoImportExclusionType::SubItemsAndSelf?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sub items" is not clear enough. That's why I used the term "items defined in this module".

Comment thread crates/rust-analyzer/src/config.rs Outdated
"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.",
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.

View changes since the review

Comment thread crates/rust-analyzer/src/config.rs Outdated
"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."
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.",

View changes since the review

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

Fair enough.

What do you mean?

I mean that I agree this is something worth having.

@A4-Tacks A4-Tacks requested a review from ChayimFriedman2 May 21, 2026 08:16
@A4-Tacks A4-Tacks force-pushed the exclude-module-items branch from 53e7d3a to ef9e665 Compare May 24, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to ignore some path for auto-import

3 participants