aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-20 18:03:19 +0100
committerGitHub <[email protected]>2020-10-20 18:03:19 +0100
commit989de9e3094f54dba81ae59f4bbaaf3a8c0d67d1 (patch)
treed9d931042534ef62c280b50792a29a8371266d96 /crates/syntax/src
parent20d369a826e8f333cba1988325480a49a730f00e (diff)
parent1d612a6ec48390c38d577cd35369e0891fe6cb6e (diff)
Merge #6172
6172: Add qualify path assist r=matklad a=Veykril This implements a `qualify_path` assist which works quite similar to the `auto_import` assist but instead of adding imports to the file it well, qualifies the path. This PR also moves out the `AutoImportAssets` struct and functions from `auto_import` into a utils submodule as most of this is now shared between `auto_import` and `qualify_path`. Changes made to `AutoImportAssets` are solely in its `search_for_imports` function which now takes a prefixed parameter to discern between using `find_use_path_prefixed` and `find_use_path` as the former is the required behavior by `auto_import` and the latter by this assist. For missing imported traits instead of importing this will qualify the path with a trait cast as in: ```rust test_mod::TestStruct::TEST_CONST<|> ``` becomes ```rust <test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST ``` and for trait methods ideally it would do the following: ```rust let test_struct = test_mod::TestStruct {}; test_struct.test_meth<|>od() ``` becomes ```rust let test_struct = test_mod::TestStruct {}; test_mod::TestTrait::test_method(&test_struct) ``` Fixes #4124. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast/make.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 74dbdfaf7..5b06cb767 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -172,6 +172,9 @@ pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
172pub fn expr_method_call(receiver: ast::Expr, method: &str, arg_list: ast::ArgList) -> ast::Expr { 172pub fn expr_method_call(receiver: ast::Expr, method: &str, arg_list: ast::ArgList) -> ast::Expr {
173 expr_from_text(&format!("{}.{}{}", receiver, method, arg_list)) 173 expr_from_text(&format!("{}.{}{}", receiver, method, arg_list))
174} 174}
175pub fn expr_ref(expr: ast::Expr, exclusive: bool) -> ast::Expr {
176 expr_from_text(&if exclusive { format!("&mut {}", expr) } else { format!("&{}", expr) })
177}
175fn expr_from_text(text: &str) -> ast::Expr { 178fn expr_from_text(text: &str) -> ast::Expr {
176 ast_from_text(&format!("const C: () = {};", text)) 179 ast_from_text(&format!("const C: () = {};", text))
177} 180}