-//! FIXME: write short doc here
-
use hir::{self, db::HirDatabase};
use ra_syntax::{
ast::{self, NameOwner},
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,
}
}
+// 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
)
}
+#[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(
}
```
+## `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).
### 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