Skip to content
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

Way to hide imports on "Find all references" ? #13184

Closed
enomado opened this issue Sep 3, 2022 · 9 comments
Closed

Way to hide imports on "Find all references" ? #13184

enomado opened this issue Sep 3, 2022 · 9 comments
Labels
A-ide general IDE features C-feature Category: feature request good first issue

Comments

@enomado
Copy link
Contributor

enomado commented Sep 3, 2022

Sorry for this question in issues, but may be there is a config option or so?

@lnicola
Copy link
Member

lnicola commented Sep 3, 2022

No, there isn't.

@lnicola lnicola added good first issue C-feature Category: feature request A-ide general IDE features labels Sep 3, 2022
@enomado
Copy link
Contributor Author

enomado commented Sep 4, 2022

Looks like I made it.

src/references.rs/find_all_refs



match &mut yolo {
        Some(h) => {
            for l in h {
                for (file_id, rr) in &mut l.references {
                    let lema = sema.parse(file_id.clone()).syntax().clone();

                    rr.retain(|(rrr, cat)| {
                        let y = lema.child_or_token_at_range(rrr.clone()).unwrap();

                        let sdd = match y {
                            syntax::NodeOrToken::Node(x) => {
                                let p = x.kind();

                                if matches!(p, USE) {
                                    // dbg!(&x);
                                    dbg!("MATCH");
                                    false
                                } else {
                                    true
                                }

                                // dbg!(format!("{}", &x));
                            }
                            syntax::NodeOrToken::Token(x) => {
                                //
                                // x.kind()
                                dbg!(&x);
                                false
                            }
                        };
                        sdd
                    });


                }
            }
        }
        None => {}
    };

Dont mind on naming.

Is my idea on filtering like that okay? I wanna do PR

@Veykril
Copy link
Member

Veykril commented Sep 4, 2022

There is no need to use the text range to look up with, the references contain the syntax node that matches so you just have to traverse the tree upwards from the node to check if its an ident of a use path.

@enomado
Copy link
Contributor Author

enomado commented Sep 4, 2022

@Veykril

If they do, this could be much simpler. .

pub references: NoHashHashMap<FileId, Vec<(TextRange, Option<ReferenceCategory>)>>,

only FileId and Range.

@Veykril
Copy link
Member

Veykril commented Sep 4, 2022

I don't follow what you mean here

@enomado
Copy link
Contributor Author

enomado commented Sep 4, 2022

@Veykril

references contain the syntax node

I mean no. It do not

@Veykril
Copy link
Member

Veykril commented Sep 4, 2022

But they do? https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-db/src/search.rs#L55-L63 contains an ast::NameLike which is the node.

Oh I see, you are trying to filter out too late, you'll need to filter in the make_searcher closure.

@enomado
Copy link
Contributor Author

enomado commented Sep 4, 2022

@Veykril Yep I didnt show a whole code. My fault. You are right. Thank you for the suggestion. That variety of types, transformations confused me

bors added a commit that referenced this issue Sep 12, 2022
Filter imports on find-all-references

Attempt to #13184
@jplatte
Copy link
Contributor

jplatte commented Sep 14, 2022

Can this be closed now with #13186 and #13228 merged?

@Veykril Veykril closed this as completed Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-feature Category: feature request good first issue
Projects
None yet
Development

No branches or pull requests

4 participants