From: Aleksey Kladov Date: Sun, 27 Oct 2019 14:49:39 +0000 (+0300) Subject: move all assists to use generated docs X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b6fcacd96d26e7edaf37bda852b8b3ad104d4c90;p=rust.git move all assists to use generated docs --- diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs index c522d6a5a71..e87fae1af0a 100644 --- a/crates/ra_assists/src/assists/add_import.rs +++ b/crates/ra_assists/src/assists/add_import.rs @@ -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) {} +// ``` +// -> +// ``` +// use std::collections::HashMap; +// +// fn process(map: HashMap) {} +// ``` pub(crate) fn add_import(ctx: AssistCtx) -> Option { let path: ast::Path = ctx.find_node_at_offset()?; // 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 ebe49aecfe2..1bee76f59a3 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -141,6 +141,21 @@ fn foo(&self) { unimplemented!() } ) } +#[test] +fn doctest_add_import() { + check( + "add_import", + r#####" +fn process(map: std::collections::<|>HashMap) {} +"#####, + r#####" +use std::collections::HashMap; + +fn process(map: HashMap) {} +"#####, + ) +} + #[test] fn doctest_apply_demorgan() { check( diff --git a/docs/user/assists.md b/docs/user/assists.md index b1fe44d8405..303353e7429 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -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) {} + +// AFTER +use std::collections::HashMap; + +fn process(map: HashMap) {} +``` + ## `apply_demorgan` Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). diff --git a/docs/user/features.md b/docs/user/features.md index 7ae2ca7b6ee..c160dd70bd9 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -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