mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Don't require module docs for Features and Assists
This commit is contained in:
parent
f593393ebb
commit
8915183d7d
16 changed files with 140 additions and 45 deletions
|
@ -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) }
|
||||
|
|
|
@ -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<u32> for A {
|
||||
fn from(v: u32) -> Self {
|
||||
A::One(v)
|
||||
}
|
||||
}
|
||||
"#####,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn doctest_add_function() {
|
||||
check_doc_test(
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use std::iter::successors;
|
||||
|
||||
use hir::Semantics;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir::Semantics;
|
||||
use ra_ide_db::{
|
||||
defs::{classify_name, classify_name_ref},
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use ra_ide_db::RootDatabase;
|
||||
use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<TextSize> {
|
||||
const BRACES: &[SyntaxKind] =
|
||||
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]];
|
||||
|
|
|
@ -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<NavigationTarget> {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//! FIXME: write short doc here
|
||||
|
||||
use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
|
||||
use itertools::Itertools;
|
||||
use ra_ide_db::RootDatabase;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<u32> 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.
|
||||
|
|
|
@ -4,24 +4,8 @@ you can use <kbd>Ctrl+Shift+P</kbd> to search for the corresponding action.
|
|||
|
||||
### Commands <kbd>ctrl+shift+p</kbd>
|
||||
|
||||
#### 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
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue