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 +++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'crates') 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( -- cgit v1.2.3