mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Generate features docs from source
This commit is contained in:
parent
383247a9ae
commit
c8f27a4a88
15 changed files with 258 additions and 58 deletions
|
@ -18,6 +18,19 @@ pub struct StructureNode {
|
|||
pub deprecated: bool,
|
||||
}
|
||||
|
||||
// Feature: File Structure
|
||||
//
|
||||
// Provides a tree of the symbols defined in the file. Can be used to
|
||||
//
|
||||
// * fuzzy search symbol in a file (super useful)
|
||||
// * draw breadcrumbs to describe the context around the cursor
|
||||
// * draw outline of the file
|
||||
//
|
||||
// |===
|
||||
// | Editor | Shortcut
|
||||
//
|
||||
// | VS Code | kbd:[Ctrl+Shift+O]
|
||||
// |===
|
||||
pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
|
||||
let mut res = Vec::new();
|
||||
let mut stack = Vec::new();
|
||||
|
|
|
@ -14,6 +14,16 @@ use ra_syntax::{
|
|||
|
||||
use crate::FileRange;
|
||||
|
||||
// Feature: Extend Selection
|
||||
//
|
||||
// Extends the current selection to the encompassing syntactic construct
|
||||
// (expression, statement, item, module, etc). It works with multiple cursors.
|
||||
//
|
||||
// |===
|
||||
// | Editor | Shortcut
|
||||
//
|
||||
// | VS Code | kbd:[Ctrl+Shift+→]
|
||||
// |===
|
||||
pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
|
||||
let sema = Semantics::new(db);
|
||||
let src = sema.parse(frange.file_id);
|
||||
|
|
|
@ -17,6 +17,15 @@ use crate::{
|
|||
FilePosition, NavigationTarget, RangeInfo,
|
||||
};
|
||||
|
||||
// Feature: Go To Definition
|
||||
//
|
||||
// Navigates to the definition of an identifier.
|
||||
//
|
||||
// |===
|
||||
// | Editor | Shortcut
|
||||
//
|
||||
// | VS Code | kbd:[F12]
|
||||
// |===
|
||||
pub(crate) fn goto_definition(
|
||||
db: &RootDatabase,
|
||||
position: FilePosition,
|
||||
|
|
|
@ -6,6 +6,15 @@ use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
|
|||
|
||||
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
|
||||
|
||||
// Feature: Go To Implementation
|
||||
//
|
||||
// Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
|
||||
//
|
||||
// |===
|
||||
// | Editor | Shortcut
|
||||
//
|
||||
// | VS Code | kbd:[Ctrl+F12]
|
||||
// |===
|
||||
pub(crate) fn goto_implementation(
|
||||
db: &RootDatabase,
|
||||
position: FilePosition,
|
|
@ -5,6 +5,9 @@ use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffs
|
|||
|
||||
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
|
||||
|
||||
// Feature: Go To Type Definition
|
||||
//
|
||||
// Navigates to the type of an identifier.
|
||||
pub(crate) fn goto_type_definition(
|
||||
db: &RootDatabase,
|
||||
position: FilePosition,
|
||||
|
|
|
@ -23,6 +23,7 @@ mod completion;
|
|||
mod runnables;
|
||||
mod goto_definition;
|
||||
mod goto_type_definition;
|
||||
mod goto_implementation;
|
||||
mod extend_selection;
|
||||
mod hover;
|
||||
mod call_hierarchy;
|
||||
|
@ -30,7 +31,6 @@ mod call_info;
|
|||
mod syntax_highlighting;
|
||||
mod parent_module;
|
||||
mod references;
|
||||
mod impls;
|
||||
mod diagnostics;
|
||||
mod syntax_tree;
|
||||
mod folding_ranges;
|
||||
|
@ -373,7 +373,7 @@ impl Analysis {
|
|||
&self,
|
||||
position: FilePosition,
|
||||
) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> {
|
||||
self.with_db(|db| impls::goto_implementation(db, position))
|
||||
self.with_db(|db| goto_implementation::goto_implementation(db, position))
|
||||
}
|
||||
|
||||
/// Returns the type definitions for the symbol at `position`.
|
||||
|
|
|
@ -32,6 +32,13 @@ pub(crate) use on_enter::on_enter;
|
|||
|
||||
pub(crate) const TRIGGER_CHARS: &str = ".=>";
|
||||
|
||||
// Feature: On Typing Assists
|
||||
//
|
||||
// Some features trigger on typing certain characters:
|
||||
//
|
||||
// - typing `let =` tries to smartly add `;` if `=` is followed by an existing expression
|
||||
// - Enter inside comments automatically inserts `///`
|
||||
// - typing `.` in a chain method call auto-indents
|
||||
pub(crate) fn on_char_typed(
|
||||
db: &RootDatabase,
|
||||
position: FilePosition,
|
||||
|
|
|
@ -110,6 +110,27 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
|
|||
Arc::new(SymbolIndex::new(symbols))
|
||||
}
|
||||
|
||||
// Feature: Workspace Symbol
|
||||
//
|
||||
// Uses fuzzy-search to find types, modules and functions by name across your
|
||||
// project and dependencies. This is **the** most useful feature, which improves code
|
||||
// navigation tremendously. It mostly works on top of the built-in LSP
|
||||
// functionality, however `#` and `*` symbols can be used to narrow down the
|
||||
// search. Specifically,
|
||||
//
|
||||
// - `Foo` searches for `Foo` type in the current workspace
|
||||
// - `foo#` searches for `foo` function in the current workspace
|
||||
// - `Foo*` searches for `Foo` type among dependencies, including `stdlib`
|
||||
// - `foo#*` searches for `foo` function among dependencies
|
||||
//
|
||||
// That is, `#` switches from "types" to all symbols, `*` switches from the current
|
||||
// workspace to dependencies.
|
||||
//
|
||||
// |===
|
||||
// | Editor | Shortcut
|
||||
//
|
||||
// | VS Code | kbd:[Ctrl+T]
|
||||
// |===
|
||||
pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
|
||||
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
|
||||
struct Snap(salsa::Snapshot<RootDatabase>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue