Skip to content

Commit c8f27a4

Browse files
committed
Generate features docs from source
1 parent 383247a commit c8f27a4

File tree

15 files changed

+258
-58
lines changed

15 files changed

+258
-58
lines changed

crates/ra_ide/src/display/structure.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ pub struct StructureNode {
1818
pub deprecated: bool,
1919
}
2020

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

crates/ra_ide/src/extend_selection.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ use ra_syntax::{
1414

1515
use crate::FileRange;
1616

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

crates/ra_ide/src/goto_definition.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ use crate::{
1717
FilePosition, NavigationTarget, RangeInfo,
1818
};
1919

20+
// Feature: Go To Definition
21+
//
22+
// Navigates to the definition of an identifier.
23+
//
24+
// |===
25+
// | Editor | Shortcut
26+
//
27+
// | VS Code | kbd:[F12]
28+
// |===
2029
pub(crate) fn goto_definition(
2130
db: &RootDatabase,
2231
position: FilePosition,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
66

77
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
88

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

crates/ra_ide/src/goto_type_definition.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffs
55

66
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
77

8+
// Feature: Go To Type Definition
9+
//
10+
// Navigates to the type of an identifier.
811
pub(crate) fn goto_type_definition(
912
db: &RootDatabase,
1013
position: FilePosition,

crates/ra_ide/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ mod completion;
2323
mod runnables;
2424
mod goto_definition;
2525
mod goto_type_definition;
26+
mod goto_implementation;
2627
mod extend_selection;
2728
mod hover;
2829
mod call_hierarchy;
2930
mod call_info;
3031
mod syntax_highlighting;
3132
mod parent_module;
3233
mod references;
33-
mod impls;
3434
mod diagnostics;
3535
mod syntax_tree;
3636
mod folding_ranges;
@@ -373,7 +373,7 @@ impl Analysis {
373373
&self,
374374
position: FilePosition,
375375
) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> {
376-
self.with_db(|db| impls::goto_implementation(db, position))
376+
self.with_db(|db| goto_implementation::goto_implementation(db, position))
377377
}
378378

379379
/// Returns the type definitions for the symbol at `position`.

crates/ra_ide/src/typing.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ pub(crate) use on_enter::on_enter;
3232

3333
pub(crate) const TRIGGER_CHARS: &str = ".=>";
3434

35+
// Feature: On Typing Assists
36+
//
37+
// Some features trigger on typing certain characters:
38+
//
39+
// - typing `let =` tries to smartly add `;` if `=` is followed by an existing expression
40+
// - Enter inside comments automatically inserts `///`
41+
// - typing `.` in a chain method call auto-indents
3542
pub(crate) fn on_char_typed(
3643
db: &RootDatabase,
3744
position: FilePosition,

crates/ra_ide_db/src/symbol_index.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
110110
Arc::new(SymbolIndex::new(symbols))
111111
}
112112

113+
// Feature: Workspace Symbol
114+
//
115+
// Uses fuzzy-search to find types, modules and functions by name across your
116+
// project and dependencies. This is **the** most useful feature, which improves code
117+
// navigation tremendously. It mostly works on top of the built-in LSP
118+
// functionality, however `#` and `*` symbols can be used to narrow down the
119+
// search. Specifically,
120+
//
121+
// - `Foo` searches for `Foo` type in the current workspace
122+
// - `foo#` searches for `foo` function in the current workspace
123+
// - `Foo*` searches for `Foo` type among dependencies, including `stdlib`
124+
// - `foo#*` searches for `foo` function among dependencies
125+
//
126+
// That is, `#` switches from "types" to all symbols, `*` switches from the current
127+
// workspace to dependencies.
128+
//
129+
// |===
130+
// | Editor | Shortcut
131+
//
132+
// | VS Code | kbd:[Ctrl+T]
133+
// |===
113134
pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
114135
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
115136
struct Snap(salsa::Snapshot<RootDatabase>);

docs/user/features.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,6 @@ This document is an index of features that the rust-analyzer language server
22
provides. Shortcuts are for the default VS Code layout. If there's no shortcut,
33
you can use <kbd>Ctrl+Shift+P</kbd> to search for the corresponding action.
44

5-
### Workspace Symbol <kbd>ctrl+t</kbd>
6-
7-
Uses fuzzy-search to find types, modules and functions by name across your
8-
project and dependencies. This is **the** most useful feature, which improves code
9-
navigation tremendously. It mostly works on top of the built-in LSP
10-
functionality, however `#` and `*` symbols can be used to narrow down the
11-
search. Specifically,
12-
13-
- `Foo` searches for `Foo` type in the current workspace
14-
- `foo#` searches for `foo` function in the current workspace
15-
- `Foo*` searches for `Foo` type among dependencies, including `stdlib`
16-
- `foo#*` searches for `foo` function among dependencies
17-
18-
That is, `#` switches from "types" to all symbols, `*` switches from the current
19-
workspace to dependencies.
20-
21-
### Document Symbol <kbd>ctrl+shift+o</kbd>
22-
23-
Provides a tree of the symbols defined in the file. Can be used to
24-
25-
* fuzzy search symbol in a file (super useful)
26-
* draw breadcrumbs to describe the context around the cursor
27-
* draw outline of the file
28-
29-
### On Typing Assists
30-
31-
Some features trigger on typing certain characters:
32-
33-
- typing `let =` tries to smartly add `;` if `=` is followed by an existing expression
34-
- Enter inside comments automatically inserts `///`
35-
- typing `.` in a chain method call auto-indents
36-
37-
### Extend Selection
38-
39-
Extends the current selection to the encompassing syntactic construct
40-
(expression, statement, item, module, etc). It works with multiple cursors. This
41-
is a relatively new feature of LSP:
42-
https://github.com/Microsoft/language-server-protocol/issues/613, check your
43-
editor's LSP library to see if this feature is supported.
44-
45-
### Go to Definition
46-
47-
Navigates to the definition of an identifier.
48-
49-
### Go to Implementation
50-
51-
Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
52-
53-
### Go to Type Defintion
54-
55-
Navigates to the type of an identifier.
56-
575
### Commands <kbd>ctrl+shift+p</kbd>
586

597
#### Run

docs/user/generated_features.adoc

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
=== Extend Selection
2+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/extend_selection.rs[extend_selection.rs]
3+
4+
5+
Extends the current selection to the encompassing syntactic construct
6+
(expression, statement, item, module, etc). It works with multiple cursors.
7+
8+
|===
9+
| Editor | Shortcut
10+
11+
| VS Code | kbd:[Ctrl+Shift+→]
12+
|===
13+
14+
15+
=== File Structure
16+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/display/structure.rs[structure.rs]
17+
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+
|===
30+
31+
32+
=== Go To Definition
33+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_definition.rs[goto_definition.rs]
34+
35+
36+
Navigates to the definition of an identifier.
37+
38+
|===
39+
| Editor | Shortcut
40+
41+
| VS Code | kbd:[F12]
42+
|===
43+
44+
45+
=== Go To Implementation
46+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_implementation.rs[goto_implementation.rs]
47+
48+
49+
Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
50+
51+
|===
52+
| Editor | Shortcut
53+
54+
| VS Code | kbd:[Ctrl+F12]
55+
|===
56+
57+
58+
=== Go To Type Definition
59+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_type_definition.rs[goto_type_definition.rs]
60+
61+
62+
Navigates to the type of an identifier.
63+
64+
65+
=== On Typing Assists
66+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/typing.rs[typing.rs]
67+
68+
69+
Some features trigger on typing certain characters:
70+
71+
- typing `let =` tries to smartly add `;` if `=` is followed by an existing expression
72+
- Enter inside comments automatically inserts `///`
73+
- typing `.` in a chain method call auto-indents
74+
75+
76+
=== Workspace Symbol
77+
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/symbol_index.rs[symbol_index.rs]
78+
79+
80+
Uses fuzzy-search to find types, modules and functions by name across your
81+
project and dependencies. This is **the** most useful feature, which improves code
82+
navigation tremendously. It mostly works on top of the built-in LSP
83+
functionality, however `#` and `*` symbols can be used to narrow down the
84+
search. Specifically,
85+
86+
- `Foo` searches for `Foo` type in the current workspace
87+
- `foo#` searches for `foo` function in the current workspace
88+
- `Foo*` searches for `Foo` type among dependencies, including `stdlib`
89+
- `foo#*` searches for `foo` function among dependencies
90+
91+
That is, `#` switches from "types" to all symbols, `*` switches from the current
92+
workspace to dependencies.
93+
94+
|===
95+
| Editor | Shortcut
96+
97+
| VS Code | kbd:[Ctrl+T]
98+
|===

0 commit comments

Comments
 (0)