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

feat: enable excluding refs search results in test #16441

Merged
merged 4 commits into from Jan 31, 2024

Conversation

Young-Flash
Copy link
Member

@Young-Flash Young-Flash commented Jan 29, 2024

Change

Here I introduce a new ReferenceCategory::Test type to indicate whether the function where this reference is located is marked as #[test], and expose an config item (rust-analyzer.references.excludeTests) to client.

I also changed the signature of ReferenceCategory::new, adding a sema: &Semantics<'_, RootDatabase> param to do some hir analysis. Hope the current implementation is good to go.

Demo

"rust-analyzer.references.excludeTests": false

include

"rust-analyzer.references.excludeTests": true

exclude

Performance

I look a bit more about the latency in rust-analyzer server LSP log trace, compared the Find All References between v0.4.1825 and this PR over syntax::ast::AstNode::syntax() and ide_assists::tests::check_assist(), taking an average of 5 operations response time (every operation is perform after restart rust-analyzer server so it's not the cache reslut). I found this PR does't bring noticable regression.

item excludeTests? v0.4.1825 this PR ref results
syntax::ast::AstNode::syntax false 13329.4 ms 13464.2 ms 2419 results in 257 files
syntax::ast::AstNode::syntax true - 13449.0 ms 2396 results in 256 files
ide_assists::tests::check_assist false 333.2 ms 348.2 ms 1684 results in 110 files
ide_assists::tests::check_assist true - 335.6 ms 113 results in 110 files

close #14530

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 29, 2024
@Young-Flash
Copy link
Member Author

I look a bit more about the latency in rust-analyzer server LSP log trace, compared the Find All References between v0.4.1825 and this PR over syntax::ast::AstNode::syntax() and ide_assists::tests::check_assist(), taking an average of 5 operations response time (every operation is perform after restart rust-analyzer server so it's not the cache reslut). I found this PR does't bring noticable regression.

item excludeTests? v0.4.1825 this PR ref results
syntax::ast::AstNode::syntax false 13329.4 ms 13464.2 ms 2419 results in 257 files
syntax::ast::AstNode::syntax true - 13449.0 ms 2396 results in 256 files
ide_assists::tests::check_assist false 333.2 ms 348.2 ms 1684 results in 110 files
ide_assists::tests::check_assist true - 335.6 ms 113 results in 110 files

@Veykril
Copy link
Member

Veykril commented Jan 31, 2024

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 31, 2024

📌 Commit 2b71aca has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 31, 2024

⌛ Testing commit 2b71aca with merge e4146af...

@bors
Copy link
Collaborator

bors commented Jan 31, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing e4146af to master...

@bors bors merged commit e4146af into rust-lang:master Jan 31, 2024
10 checks passed
@Young-Flash Young-Flash deleted the exclude_tests_refs branch January 31, 2024 08:05
@PSeitz PSeitz mentioned this pull request Mar 6, 2024
Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Great to see this! Supporting this feature is exactly why the search API was designed as it was, with reference categories and such!

@@ -1055,6 +1055,7 @@ pub(crate) fn handle_references(
let position = from_proto::file_position(&snap, params.text_document_position)?;

let exclude_imports = snap.config.find_all_refs_exclude_imports();
let exclude_tests = snap.config.find_all_refs_exclude_tests();
Copy link
Member

Choose a reason for hiding this comment

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

exclude_tests should be pushed down as a parameter to find_all_refs.

that way, a potentially more optimal implementation would be able to avoid even analyzing the test, which would be faster than filtering out results after the fact.

I think the second parameter we are passing here, which is currently None, is something like a SearchScope. It exists exactly to narrow down search results, and I think could be extended to exclude tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, I had create an issue for this

(sorry for the slow response, kind of busy recently)

@@ -134,6 +134,7 @@ pub enum ReferenceCategory {
// FIXME: Some day should be able to search in doc comments. Would probably
// need to switch from enum to bitflags then?
// DocComment
Test,
Copy link
Member

@matklad matklad Apr 13, 2024

Choose a reason for hiding this comment

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

Something can be a test and a read at the same time. So, the time has come to use a bitset here! This is precisely the situation the old comment just above this line talks about

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.

Find all references, exclusing test configuration
5 participants