aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/add_import.rs21
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs15
2 files changed, 31 insertions, 5 deletions
diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs
index c522d6a5a..e87fae1af 100644
--- a/crates/ra_assists/src/assists/add_import.rs
+++ b/crates/ra_assists/src/assists/add_import.rs
@@ -1,5 +1,3 @@
1//! FIXME: write short doc here
2
3use hir::{self, db::HirDatabase}; 1use hir::{self, db::HirDatabase};
4use ra_syntax::{ 2use ra_syntax::{
5 ast::{self, NameOwner}, 3 ast::{self, NameOwner},
@@ -14,9 +12,9 @@ use crate::{
14 AssistId, 12 AssistId,
15}; 13};
16 14
17// This function produces sequence of text edits into edit 15/// This function produces sequence of text edits into edit
18// to import the target path in the most appropriate scope given 16/// to import the target path in the most appropriate scope given
19// the cursor position 17/// the cursor position
20pub fn auto_import_text_edit( 18pub fn auto_import_text_edit(
21 // Ideally the position of the cursor, used to 19 // Ideally the position of the cursor, used to
22 position: &SyntaxNode, 20 position: &SyntaxNode,
@@ -39,6 +37,19 @@ pub fn auto_import_text_edit(
39 } 37 }
40} 38}
41 39
40// Assist: add_import
41//
42// Adds a use statement for a given fully-qualified path.
43//
44// ```
45// fn process(map: std::collections::<|>HashMap<String, String>) {}
46// ```
47// ->
48// ```
49// use std::collections::HashMap;
50//
51// fn process(map: HashMap<String, String>) {}
52// ```
42pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 53pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
43 let path: ast::Path = ctx.find_node_at_offset()?; 54 let path: ast::Path = ctx.find_node_at_offset()?;
44 // We don't want to mess with use statements 55 // We don't want to mess with use statements
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index ebe49aecf..1bee76f59 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -142,6 +142,21 @@ impl T for () {
142} 142}
143 143
144#[test] 144#[test]
145fn doctest_add_import() {
146 check(
147 "add_import",
148 r#####"
149fn process(map: std::collections::<|>HashMap<String, String>) {}
150"#####,
151 r#####"
152use std::collections::HashMap;
153
154fn process(map: HashMap<String, String>) {}
155"#####,
156 )
157}
158
159#[test]
145fn doctest_apply_demorgan() { 160fn doctest_apply_demorgan() {
146 check( 161 check(
147 "apply_demorgan", 162 "apply_demorgan",