Skip to content

Commit 09df51d

Browse files
bors[bot]matklad
andauthored
Merge #4664
4664: Generate feature documentation from code r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 5f72254 + 13a996f commit 09df51d

33 files changed

+859
-412
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ crates/*/target
77
*.log
88
*.iml
99
.vscode/settings.json
10-
cargo-timing*.html
10+
*.html

crates/ra_assists/src/handlers/add_from_impl_for_enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use test_utils::mark;
44

55
use crate::{utils::FamousDefs, AssistContext, AssistId, Assists};
66

7-
// Assist add_from_impl_for_enum
7+
// Assist: add_from_impl_for_enum
88
//
9-
// Adds a From impl for an enum variant with one tuple field
9+
// Adds a From impl for an enum variant with one tuple field.
1010
//
1111
// ```
1212
// enum A { <|>One(u32) }

crates/ra_assists/src/tests/generated.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ fn main() {
5858
)
5959
}
6060

61+
#[test]
62+
fn doctest_add_from_impl_for_enum() {
63+
check_doc_test(
64+
"add_from_impl_for_enum",
65+
r#####"
66+
enum A { <|>One(u32) }
67+
"#####,
68+
r#####"
69+
enum A { One(u32) }
70+
71+
impl From<u32> for A {
72+
fn from(v: u32) -> Self {
73+
A::One(v)
74+
}
75+
}
76+
"#####,
77+
)
78+
}
79+
6180
#[test]
6281
fn doctest_add_function() {
6382
check_doc_test(

crates/ra_ide/src/completion.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! FIXME: write short doc here
2-
31
mod completion_config;
42
mod completion_item;
53
mod completion_context;
@@ -35,6 +33,51 @@ pub use crate::completion::{
3533
completion_item::{CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat},
3634
};
3735

36+
//FIXME: split the following feature into fine-grained features.
37+
38+
// Feature: Magic Completions
39+
//
40+
// In addition to usual reference completion, rust-analyzer provides some ✨magic✨
41+
// completions as well:
42+
//
43+
// Keywords like `if`, `else` `while`, `loop` are completed with braces, and cursor
44+
// is placed at the appropriate position. Even though `if` is easy to type, you
45+
// still want to complete it, to get ` { }` for free! `return` is inserted with a
46+
// space or `;` depending on the return type of the function.
47+
//
48+
// When completing a function call, `()` are automatically inserted. If a function
49+
// takes arguments, the cursor is positioned inside the parenthesis.
50+
//
51+
// There are postfix completions, which can be triggered by typing something like
52+
// `foo().if`. The word after `.` determines postfix completion. Possible variants are:
53+
//
54+
// - `expr.if` -> `if expr {}` or `if let ... {}` for `Option` or `Result`
55+
// - `expr.match` -> `match expr {}`
56+
// - `expr.while` -> `while expr {}` or `while let ... {}` for `Option` or `Result`
57+
// - `expr.ref` -> `&expr`
58+
// - `expr.refm` -> `&mut expr`
59+
// - `expr.not` -> `!expr`
60+
// - `expr.dbg` -> `dbg!(expr)`
61+
//
62+
// There also snippet completions:
63+
//
64+
// .Expressions
65+
// - `pd` -> `println!("{:?}")`
66+
// - `ppd` -> `println!("{:#?}")`
67+
//
68+
// .Items
69+
// - `tfn` -> `#[test] fn f(){}`
70+
// - `tmod` ->
71+
// ```rust
72+
// #[cfg(test)]
73+
// mod tests {
74+
// use super::*;
75+
//
76+
// #[test]
77+
// fn test_fn() {}
78+
// }
79+
// ```
80+
3881
/// Main entry point for completion. We run completion as a two-phase process.
3982
///
4083
/// First, we look at the position and collect a so-called `CompletionContext.

crates/ra_ide/src/completion/complete_postfix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
//! FIXME: write short doc here
2-
2+
use ra_assists::utils::TryEnum;
33
use ra_syntax::{
44
ast::{self, AstNode},
55
TextRange, TextSize,
66
};
77
use ra_text_edit::TextEdit;
88

9-
use super::completion_config::SnippetCap;
109
use crate::{
1110
completion::{
1211
completion_context::CompletionContext,
1312
completion_item::{Builder, CompletionKind, Completions},
1413
},
1514
CompletionItem,
1615
};
17-
use ra_assists::utils::TryEnum;
16+
17+
use super::completion_config::SnippetCap;
1818

1919
pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
2020
if !ctx.config.enable_postfix_completions {

crates/ra_ide/src/display/structure.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
//! FIXME: write short doc here
2-
3-
use crate::TextRange;
4-
51
use ra_syntax::{
62
ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner},
7-
match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
3+
match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent,
84
};
95

106
#[derive(Debug, Clone)]
@@ -18,6 +14,19 @@ pub struct StructureNode {
1814
pub deprecated: bool,
1915
}
2016

17+
// Feature: File Structure
18+
//
19+
// Provides a tree of the symbols defined in the file. Can be used to
20+
//
21+
// * fuzzy search symbol in a file (super useful)
22+
// * draw breadcrumbs to describe the context around the cursor
23+
// * draw outline of the file
24+
//
25+
// |===
26+
// | Editor | Shortcut
27+
//
28+
// | VS Code | kbd:[Ctrl+Shift+O]
29+
// |===
2130
pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
2231
let mut res = Vec::new();
2332
let mut stack = Vec::new();

crates/ra_ide/src/expand_macro.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! This modules implements "expand macro" functionality in the IDE
2-
31
use hir::Semantics;
42
use ra_ide_db::RootDatabase;
53
use ra_syntax::{
@@ -14,6 +12,15 @@ pub struct ExpandedMacro {
1412
pub expansion: String,
1513
}
1614

15+
// Feature: Expand Macro Recursively
16+
//
17+
// Shows the full macro expansion of the macro at current cursor.
18+
//
19+
// |===
20+
// | Editor | Action Name
21+
//
22+
// | VS Code | **Rust Analyzer: Expand macro recursively**
23+
// |===
1724
pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<ExpandedMacro> {
1825
let sema = Semantics::new(db);
1926
let file = sema.parse(position.file_id);

crates/ra_ide/src/extend_selection.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! FIXME: write short doc here
2-
31
use std::iter::successors;
42

53
use hir::Semantics;
@@ -14,6 +12,16 @@ use ra_syntax::{
1412

1513
use crate::FileRange;
1614

15+
// Feature: Extend Selection
16+
//
17+
// Extends the current selection to the encompassing syntactic construct
18+
// (expression, statement, item, module, etc). It works with multiple cursors.
19+
//
20+
// |===
21+
// | Editor | Shortcut
22+
//
23+
// | VS Code | kbd:[Ctrl+Shift+→]
24+
// |===
1725
pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
1826
let sema = Semantics::new(db);
1927
let src = sema.parse(frange.file_id);

crates/ra_ide/src/goto_definition.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! FIXME: write short doc here
2-
31
use hir::Semantics;
42
use ra_ide_db::{
53
defs::{classify_name, classify_name_ref},
@@ -17,6 +15,15 @@ use crate::{
1715
FilePosition, NavigationTarget, RangeInfo,
1816
};
1917

18+
// Feature: Go to Definition
19+
//
20+
// Navigates to the definition of an identifier.
21+
//
22+
// |===
23+
// | Editor | Shortcut
24+
//
25+
// | VS Code | kbd:[F12]
26+
// |===
2027
pub(crate) fn goto_definition(
2128
db: &RootDatabase,
2229
position: FilePosition,

crates/ra_ide/src/impls.rs renamed to crates/ra_ide/src/goto_implementation.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
//! FIXME: write short doc here
2-
31
use hir::{Crate, ImplDef, Semantics};
42
use ra_ide_db::RootDatabase;
53
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
64

75
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
86

7+
// Feature: Go to Implementation
8+
//
9+
// Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
10+
//
11+
// |===
12+
// | Editor | Shortcut
13+
//
14+
// | VS Code | kbd:[Ctrl+F12]
15+
// |===
916
pub(crate) fn goto_implementation(
1017
db: &RootDatabase,
1118
position: FilePosition,

0 commit comments

Comments
 (0)