mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
move all assists to use generated docs
This commit is contained in:
parent
cda6355de2
commit
b6fcacd96d
4 changed files with 48 additions and 22 deletions
|
@ -1,5 +1,3 @@
|
||||||
//! FIXME: write short doc here
|
|
||||||
|
|
||||||
use hir::{self, db::HirDatabase};
|
use hir::{self, db::HirDatabase};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, NameOwner},
|
ast::{self, NameOwner},
|
||||||
|
@ -14,9 +12,9 @@ use crate::{
|
||||||
AssistId,
|
AssistId,
|
||||||
};
|
};
|
||||||
|
|
||||||
// This function produces sequence of text edits into edit
|
/// This function produces sequence of text edits into edit
|
||||||
// to import the target path in the most appropriate scope given
|
/// to import the target path in the most appropriate scope given
|
||||||
// the cursor position
|
/// the cursor position
|
||||||
pub fn auto_import_text_edit(
|
pub fn auto_import_text_edit(
|
||||||
// Ideally the position of the cursor, used to
|
// Ideally the position of the cursor, used to
|
||||||
position: &SyntaxNode,
|
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> {
|
pub(crate) fn add_import(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||||
let path: ast::Path = ctx.find_node_at_offset()?;
|
let path: ast::Path = ctx.find_node_at_offset()?;
|
||||||
// We don't want to mess with use statements
|
// 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]
|
#[test]
|
||||||
fn doctest_apply_demorgan() {
|
fn doctest_apply_demorgan() {
|
||||||
check(
|
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_demorgan`
|
||||||
|
|
||||||
Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
|
Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
|
||||||
|
|
|
@ -99,24 +99,10 @@ Stop `cargo watch`
|
||||||
|
|
||||||
### Assists (Code Actions)
|
### Assists (Code Actions)
|
||||||
|
|
||||||
These are triggered in a particular context via light bulb. We use custom code on
|
Assists, or code actions, are small local refactorings, available in a particular context.
|
||||||
the VS Code side to be able to position cursor. `<|>` signifies cursor
|
They are usually triggered by a shortcut or by clicking a light bulb icon in the editor.
|
||||||
|
|
||||||
See [assists.md](./assists.md)
|
See [assists.md](./assists.md) for the list of available assists.
|
||||||
|
|
||||||
- Import path
|
|
||||||
|
|
||||||
```rust
|
|
||||||
// before:
|
|
||||||
impl std::fmt::Debug<|> for Foo {
|
|
||||||
}
|
|
||||||
|
|
||||||
// after:
|
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
impl Debug<|> for Foo {
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Magic Completions
|
### Magic Completions
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue