]> git.lizzy.rs Git - rust.git/commitdiff
move all assists to use generated docs
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 27 Oct 2019 14:49:39 +0000 (17:49 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 27 Oct 2019 14:49:39 +0000 (17:49 +0300)
crates/ra_assists/src/assists/add_import.rs
crates/ra_assists/src/doc_tests/generated.rs
docs/user/assists.md
docs/user/features.md

index c522d6a5a71cc58292a06f18fde0b3423c925a4a..e87fae1af0a524ccd082f9063f72371caa53d67b 100644 (file)
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use hir::{self, db::HirDatabase};
 use ra_syntax::{
     ast::{self, NameOwner},
@@ -14,9 +12,9 @@
     AssistId,
 };
 
-// This function produces sequence of text edits into edit
-// to import the target path in the most appropriate scope given
-// the cursor position
+/// This function produces sequence of text edits into edit
+/// to import the target path in the most appropriate scope given
+/// the cursor position
 pub fn auto_import_text_edit(
     // Ideally the position of the cursor, used to
     position: &SyntaxNode,
@@ -39,6 +37,19 @@ pub fn auto_import_text_edit(
     }
 }
 
+// Assist: add_import
+//
+// Adds a use statement for a given fully-qualified path.
+//
+// ```
+// fn process(map: std::collections::<|>HashMap<String, String>) {}
+// ```
+// ->
+// ```
+// use std::collections::HashMap;
+//
+// fn process(map: HashMap<String, String>) {}
+// ```
 pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
     let path: ast::Path = ctx.find_node_at_offset()?;
     // We don't want to mess with use statements
index ebe49aecfe20342a1db494e2ad7e4b4cc87ce6e3..1bee76f59a33674daa8d060e1a3e9860cc71f5f2 100644 (file)
@@ -141,6 +141,21 @@ fn foo(&self) { unimplemented!() }
     )
 }
 
+#[test]
+fn doctest_add_import() {
+    check(
+        "add_import",
+        r#####"
+fn process(map: std::collections::<|>HashMap<String, String>) {}
+"#####,
+        r#####"
+use std::collections::HashMap;
+
+fn process(map: HashMap<String, String>) {}
+"#####,
+    )
+}
+
 #[test]
 fn doctest_apply_demorgan() {
     check(
index b1fe44d84055f3837fff80b64edd902dc622372a..303353e742940bf542ad54cb0554d1c3527c4abe 100644 (file)
@@ -136,6 +136,20 @@ impl T for () {
 }
 ```
 
+## `add_import`
+
+Adds a use statement for a given fully-qualified path.
+
+```rust
+// BEFORE
+fn process(map: std::collections::┃HashMap<String, String>) {}
+
+// AFTER
+use std::collections::HashMap;
+
+fn process(map: HashMap<String, String>) {}
+```
+
 ## `apply_demorgan`
 
 Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
index 7ae2ca7b6ee451a87962f97154e8bcf1b28a5731..c160dd70bd95c5b378421ace92825cc344d0e009 100644 (file)
@@ -99,24 +99,10 @@ Stop `cargo watch`
 
 ### Assists (Code Actions)
 
-These are triggered in a particular context via light bulb. We use custom code on
-the VS Code side to be able to position cursor. `<|>` signifies cursor
+Assists, or code actions, are small local refactorings, available in a particular context.
+They are usually triggered by a shortcut or by clicking a light bulb icon in the editor.
 
-See [assists.md](./assists.md)
-
-- Import path
-
-```rust
-// before:
-impl std::fmt::Debug<|> for Foo {
-}
-
-// after:
-use std::fmt::Debug;
-
-impl Debug<|> for Foo {
-}
-```
+See [assists.md](./assists.md) for the list of available assists.
 
 ### Magic Completions