aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-14 16:17:03 +0000
committerGitHub <[email protected]>2021-02-14 16:17:03 +0000
commita0322defc375d7fd3890225768a85a31f2bdb0be (patch)
treee09243414c566cde0ecdb500e7441bf21ead1d0e /crates/assists/src/handlers
parentd50a37d3aa473937919030b39587df3d93f9bd8c (diff)
parent8ac6041bcf7c970104939bdbdda5af4873ebd472 (diff)
Merge #7656
7656: Implement constructor usage search for almost all items r=matklad a=Veykril This PR moves the filering for enum constructors to the HIR, with this unprefixed variants as well as when the enum has been renamed via use will then still show up properly. We now walk the ast of the `NameRef` up until we find a `PathExpr`(which also handles `CallExpr` for tuple-type structs and variants already) or a `RecordExpr`. For enum search we then take the `path` out of that expression and do a resolution on it to compare it with the definition enum. With this PR we now support searching for all constructor literals, Unit-, Tuple- and Record-Structs, Unit-, Tuple- and Record-Variants as well as Unions. There is one shortcoming due to how the search is triggered. Unit Variants constructors can't be searched as we have no position for it to kick off the search(since a comma doesn't have to exist for the last variant). Closes #2549 though it doesn't implement it as outlined in the issue since the reference kind was removed recently, though I believe the approach taken here is better personally. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r--crates/assists/src/handlers/inline_local_variable.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/crates/assists/src/handlers/inline_local_variable.rs b/crates/assists/src/handlers/inline_local_variable.rs
index 8d28431cf..9b228443f 100644
--- a/crates/assists/src/handlers/inline_local_variable.rs
+++ b/crates/assists/src/handlers/inline_local_variable.rs
@@ -1,6 +1,5 @@
1use std::collections::HashMap;
2
3use ide_db::{defs::Definition, search::FileReference}; 1use ide_db::{defs::Definition, search::FileReference};
2use rustc_hash::FxHashMap;
4use syntax::{ 3use syntax::{
5 ast::{self, AstNode, AstToken}, 4 ast::{self, AstNode, AstToken},
6 TextRange, 5 TextRange,
@@ -111,7 +110,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O
111 .collect::<Result<_, _>>() 110 .collect::<Result<_, _>>()
112 .map(|b| (file_id, b)) 111 .map(|b| (file_id, b))
113 }) 112 })
114 .collect::<Result<HashMap<_, Vec<_>>, _>>()?; 113 .collect::<Result<FxHashMap<_, Vec<_>>, _>>()?;
115 114
116 let init_str = initializer_expr.syntax().text().to_string(); 115 let init_str = initializer_expr.syntax().text().to_string();
117 let init_in_paren = format!("({})", &init_str); 116 let init_in_paren = format!("({})", &init_str);