From b6fcacd96d26e7edaf37bda852b8b3ad104d4c90 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Oct 2019 17:49:39 +0300 Subject: move all assists to use generated docs --- crates/ra_assists/src/assists/add_import.rs | 21 ++++++++++++++++----- crates/ra_assists/src/doc_tests/generated.rs | 15 +++++++++++++++ docs/user/assists.md | 14 ++++++++++++++ docs/user/features.md | 20 +++----------------- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs index c522d6a5a..e87fae1af 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 @@ 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) {} +// ``` +// -> +// ``` +// 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 ebe49aecf..1bee76f59 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -141,6 +141,21 @@ impl T for () { ) } +#[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 b1fe44d84..303353e74 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 7ae2ca7b6..c160dd70b 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 -- cgit v1.2.3