Merge #2095
2095: move all assists to use generated docs r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
f6588b8676
@ -1,5 +1,3 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use hir::{self, db::HirDatabase};
|
||||
use ra_syntax::{
|
||||
ast::{self, NameOwner},
|
||||
@ -14,9 +12,9 @@ use crate::{
|
||||
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
|
||||
|
@ -141,6 +141,21 @@ impl T for () {
|
||||
)
|
||||
}
|
||||
|
||||
#[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(
|
||||
|
@ -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).
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user