From 8915183d7da07a4b295e5e93a889dea4c15024a0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 May 2020 09:59:38 +0200 Subject: Don't require module docs for Features and Assists --- .../src/handlers/add_from_impl_for_enum.rs | 4 +- crates/ra_assists/src/tests/generated.rs | 19 ++++++++ crates/ra_ide/src/display/structure.rs | 6 +-- crates/ra_ide/src/extend_selection.rs | 2 - crates/ra_ide/src/goto_definition.rs | 2 - crates/ra_ide/src/goto_implementation.rs | 2 - crates/ra_ide/src/goto_type_definition.rs | 2 - crates/ra_ide/src/join_lines.rs | 11 ++++- crates/ra_ide/src/matching_brace.rs | 13 ++++- crates/ra_ide/src/parent_module.rs | 12 ++++- crates/ra_ide/src/runnables.rs | 2 - crates/ra_ide/src/syntax_tree.rs | 14 ++++-- docs/user/assists.md | 18 +++++++ docs/user/features.md | 16 ------- docs/user/generated_features.adoc | 55 ++++++++++++++++++++++ xtask/tests/tidy.rs | 7 ++- 16 files changed, 140 insertions(+), 45 deletions(-) diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs index 6a675e812..776bddf91 100644 --- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs @@ -4,9 +4,9 @@ use test_utils::mark; use crate::{utils::FamousDefs, AssistContext, AssistId, Assists}; -// Assist add_from_impl_for_enum +// Assist: add_from_impl_for_enum // -// Adds a From impl for an enum variant with one tuple field +// Adds a From impl for an enum variant with one tuple field. // // ``` // enum A { <|>One(u32) } diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs index 250e56a69..4e0536828 100644 --- a/crates/ra_assists/src/tests/generated.rs +++ b/crates/ra_assists/src/tests/generated.rs @@ -58,6 +58,25 @@ fn main() { ) } +#[test] +fn doctest_add_from_impl_for_enum() { + check_doc_test( + "add_from_impl_for_enum", + r#####" +enum A { <|>One(u32) } +"#####, + r#####" +enum A { One(u32) } + +impl From for A { + fn from(v: u32) -> Self { + A::One(v) + } +} +"#####, + ) +} + #[test] fn doctest_add_function() { check_doc_test( diff --git a/crates/ra_ide/src/display/structure.rs b/crates/ra_ide/src/display/structure.rs index 3f59b89bb..aad5a8e4d 100644 --- a/crates/ra_ide/src/display/structure.rs +++ b/crates/ra_ide/src/display/structure.rs @@ -1,10 +1,6 @@ -//! FIXME: write short doc here - -use crate::TextRange; - use ra_syntax::{ ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, - match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, + match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, }; #[derive(Debug, Clone)] diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index cee0a19e1..a4bc93cdb 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use std::iter::successors; use hir::Semantics; diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index daeeac76f..a6c86e99c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use hir::Semantics; use ra_ide_db::{ defs::{classify_name, classify_name_ref}, diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 622a094e6..0cec0657e 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use hir::{Crate, ImplDef, Semantics}; use ra_ide_db::RootDatabase; use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs index e74a502ec..91a3097fb 100644 --- a/crates/ra_ide/src/goto_type_definition.rs +++ b/crates/ra_ide/src/goto_type_definition.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use ra_ide_db::RootDatabase; use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset}; diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index af1ade8a1..5036c1fb0 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use itertools::Itertools; use ra_fmt::{compute_ws, extract_trivial_expression}; use ra_syntax::{ @@ -11,6 +9,15 @@ use ra_syntax::{ }; use ra_text_edit::{TextEdit, TextEditBuilder}; +// Feature: Join Lines +// +// Join selected lines into one, smartly fixing up whitespace, trailing commas, and braces. +// +// |=== +// | Editor | Action Name +// +// | VS Code | **Rust Analyzer: Join lines** +// |=== pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { let range = if range.is_empty() { let syntax = file.syntax(); diff --git a/crates/ra_ide/src/matching_brace.rs b/crates/ra_ide/src/matching_brace.rs index b85348706..407a9636d 100644 --- a/crates/ra_ide/src/matching_brace.rs +++ b/crates/ra_ide/src/matching_brace.rs @@ -1,7 +1,16 @@ -//! FIXME: write short doc here - use ra_syntax::{ast::AstNode, SourceFile, SyntaxKind, TextSize, T}; +// Feature: Matching Brace +// +// If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair, +// moves cursor to the matching brace. It uses the actual parser to determine +// braces, so it won't confuse generics with comparisons. +// +// |=== +// | Editor | Action Name +// +// | VS Code | **Rust Analyzer: Find matching brace** +// |=== pub fn matching_brace(file: &SourceFile, offset: TextSize) -> Option { const BRACES: &[SyntaxKind] = &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]]; diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index a083fb1eb..fa1535da5 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use hir::Semantics; use ra_db::{CrateId, FileId, FilePosition}; use ra_ide_db::RootDatabase; @@ -11,6 +9,16 @@ use test_utils::mark; use crate::NavigationTarget; +// Feature: Parent Module +// +// Navigates to the parent module of the current module. +// +// |=== +// | Editor | Action Name +// +// | VS Code | **Rust Analyzer: Locate parent module** +// |=== + /// This returns `Vec` because a module may be included from several places. We /// don't handle this case yet though, so the Vec has length at most one. pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec { diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 4bf2678e1..286d45eee 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; use itertools::Itertools; use ra_ide_db::RootDatabase; diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs index 86c70ff83..2192f5090 100644 --- a/crates/ra_ide/src/syntax_tree.rs +++ b/crates/ra_ide/src/syntax_tree.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use ra_db::SourceDatabase; use ra_ide_db::RootDatabase; use ra_syntax::{ @@ -8,8 +6,16 @@ use ra_syntax::{ SyntaxToken, TextRange, TextSize, }; -pub use ra_db::FileId; - +// Feature: Show Syntax Tree +// +// Shows the parse tree of the current file. It exists mostly for debugging +// rust-analyzer itself. +// +// |=== +// | Editor | Action Name +// +// | VS Code | **Rust Analyzer: Show Syntax Tree** +// |=== pub(crate) fn syntax_tree( db: &RootDatabase, file_id: FileId, diff --git a/docs/user/assists.md b/docs/user/assists.md index 4ad7ea59d..b5d813b54 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -56,6 +56,24 @@ fn main() { } ``` +## `add_from_impl_for_enum` + +Adds a From impl for an enum variant with one tuple field. + +```rust +// BEFORE +enum A { ┃One(u32) } + +// AFTER +enum A { One(u32) } + +impl From for A { + fn from(v: u32) -> Self { + A::One(v) + } +} +``` + ## `add_function` Adds a stub function with a signature matching the function under the cursor. diff --git a/docs/user/features.md b/docs/user/features.md index df8e73a20..ba7ca15a6 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -4,24 +4,8 @@ you can use Ctrl+Shift+P to search for the corresponding action. ### Commands ctrl+shift+p -#### Parent Module -Navigates to the parent module of the current module. -#### Matching Brace - -If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair, -moves cursor to the matching brace. It uses the actual parser to determine -braces, so it won't confuse generics with comparisons. - -#### Join Lines - -Join selected lines into one, smartly fixing up whitespace and trailing commas. - -#### Show Syntax Tree - -Shows the parse tree of the current file. It exists mostly for debugging -rust-analyzer itself. #### Expand Macro Recursively diff --git a/docs/user/generated_features.adoc b/docs/user/generated_features.adoc index 1f6fcc974..bf0a36d01 100644 --- a/docs/user/generated_features.adoc +++ b/docs/user/generated_features.adoc @@ -68,6 +68,34 @@ Navigates to the type of an identifier. |=== +=== Join Lines +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/join_lines.rs[join_lines.rs] + + +Join selected lines into one, smartly fixing up whitespace, trailing commas, and braces. + +|=== +| Editor | Action Name + +| VS Code | **Rust Analyzer: Join lines** +|=== + + +=== Matching Brace +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/matching_brace.rs[matching_brace.rs] + + +If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair, +moves cursor to the matching brace. It uses the actual parser to determine +braces, so it won't confuse generics with comparisons. + +|=== +| Editor | Action Name + +| VS Code | **Rust Analyzer: Find matching brace** +|=== + + === On Typing Assists **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/typing.rs[typing.rs] @@ -79,6 +107,19 @@ Some features trigger on typing certain characters: - typing `.` in a chain method call auto-indents +=== Parent Module +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/parent_module.rs[parent_module.rs] + + +Navigates to the parent module of the current module. + +|=== +| Editor | Action Name + +| VS Code | **Rust Analyzer: Locate parent module** +|=== + + === Run **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/runnables.rs[runnables.rs] @@ -94,6 +135,20 @@ to a shortcut! |=== +=== Show Syntax Tree +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/syntax_tree.rs[syntax_tree.rs] + + +Shows the parse tree of the current file. It exists mostly for debugging +rust-analyzer itself. + +|=== +| Editor | Action Name + +| VS Code | **Rust Analyzer: Show Syntax Tree** +|=== + + === Workspace Symbol **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/symbol_index.rs[symbol_index.rs] diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 06ff45d99..4ac5d929f 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -102,7 +102,7 @@ impl TidyDocs { fn visit(&mut self, path: &Path, text: &str) { // Test hopefully don't really need comments, and for assists we already // have special comments which are source of doc tests and user docs. - if is_exclude_dir(path, &["tests", "test_data", "handlers"]) { + if is_exclude_dir(path, &["tests", "test_data"]) { return; } @@ -117,9 +117,12 @@ impl TidyDocs { if first_line.starts_with("//!") { if first_line.contains("FIXME") { - self.contains_fixme.push(path.to_path_buf()) + self.contains_fixme.push(path.to_path_buf()); } } else { + if text.contains("// Feature:") || text.contains("// Assist:") { + return; + } self.missing_docs.push(path.display().to_string()); } -- cgit v1.2.3