mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Specify actions
This commit is contained in:
parent
c116171879
commit
f593393ebb
7 changed files with 64 additions and 17 deletions
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
FilePosition, NavigationTarget, RangeInfo,
|
FilePosition, NavigationTarget, RangeInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Feature: Go To Definition
|
// Feature: Go to Definition
|
||||||
//
|
//
|
||||||
// Navigates to the definition of an identifier.
|
// Navigates to the definition of an identifier.
|
||||||
//
|
//
|
||||||
|
|
|
@ -6,7 +6,7 @@ use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
|
||||||
|
|
||||||
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
|
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
|
||||||
|
|
||||||
// Feature: Go To Implementation
|
// Feature: Go to Implementation
|
||||||
//
|
//
|
||||||
// Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
|
// Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
|
||||||
//
|
//
|
||||||
|
|
|
@ -5,9 +5,15 @@ use ra_syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffs
|
||||||
|
|
||||||
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
|
use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo};
|
||||||
|
|
||||||
// Feature: Go To Type Definition
|
// Feature: Go to Type Definition
|
||||||
//
|
//
|
||||||
// Navigates to the type of an identifier.
|
// Navigates to the type of an identifier.
|
||||||
|
//
|
||||||
|
// |===
|
||||||
|
// | Editor | Action Name
|
||||||
|
//
|
||||||
|
// | VS Code | **Go to Type Definition*
|
||||||
|
// |===
|
||||||
pub(crate) fn goto_type_definition(
|
pub(crate) fn goto_type_definition(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
|
|
|
@ -44,6 +44,17 @@ pub enum RunnableKind {
|
||||||
Bin,
|
Bin,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Feature: Run
|
||||||
|
//
|
||||||
|
// Shows a popup suggesting to run a test/benchmark/binary **at the current cursor
|
||||||
|
// location**. Super useful for repeatedly running just a single test. Do bind this
|
||||||
|
// to a shortcut!
|
||||||
|
//
|
||||||
|
// |===
|
||||||
|
// | Editor | Action Name
|
||||||
|
//
|
||||||
|
// | VS Code | **Rust Analyzer: Run**
|
||||||
|
// |===
|
||||||
pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
|
pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
|
||||||
let sema = Semantics::new(db);
|
let sema = Semantics::new(db);
|
||||||
let source_file = sema.parse(file_id);
|
let source_file = sema.parse(file_id);
|
||||||
|
|
|
@ -4,12 +4,6 @@ you can use <kbd>Ctrl+Shift+P</kbd> to search for the corresponding action.
|
||||||
|
|
||||||
### Commands <kbd>ctrl+shift+p</kbd>
|
### Commands <kbd>ctrl+shift+p</kbd>
|
||||||
|
|
||||||
#### Run
|
|
||||||
|
|
||||||
Shows a popup suggesting to run a test/benchmark/binary **at the current cursor
|
|
||||||
location**. Super useful for repeatedly running just a single test. Do bind this
|
|
||||||
to a shortcut!
|
|
||||||
|
|
||||||
#### Parent Module
|
#### Parent Module
|
||||||
|
|
||||||
Navigates to the parent module of the current module.
|
Navigates to the parent module of the current module.
|
||||||
|
|
|
@ -29,7 +29,7 @@ Provides a tree of the symbols defined in the file. Can be used to
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
=== Go To Definition
|
=== Go to Definition
|
||||||
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_definition.rs[goto_definition.rs]
|
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_definition.rs[goto_definition.rs]
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ Navigates to the definition of an identifier.
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
=== Go To Implementation
|
=== Go to Implementation
|
||||||
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_implementation.rs[goto_implementation.rs]
|
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_implementation.rs[goto_implementation.rs]
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,12 +55,18 @@ Navigates to the impl block of structs, enums or traits. Also implemented as a c
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
||||||
=== Go To Type Definition
|
=== Go to Type Definition
|
||||||
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_type_definition.rs[goto_type_definition.rs]
|
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_type_definition.rs[goto_type_definition.rs]
|
||||||
|
|
||||||
|
|
||||||
Navigates to the type of an identifier.
|
Navigates to the type of an identifier.
|
||||||
|
|
||||||
|
|===
|
||||||
|
| Editor | Action Name
|
||||||
|
|
||||||
|
| VS Code | **Go to Type Definition*
|
||||||
|
|===
|
||||||
|
|
||||||
|
|
||||||
=== On Typing Assists
|
=== On Typing Assists
|
||||||
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/typing.rs[typing.rs]
|
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/typing.rs[typing.rs]
|
||||||
|
@ -73,6 +79,21 @@ Some features trigger on typing certain characters:
|
||||||
- typing `.` in a chain method call auto-indents
|
- typing `.` in a chain method call auto-indents
|
||||||
|
|
||||||
|
|
||||||
|
=== Run
|
||||||
|
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/runnables.rs[runnables.rs]
|
||||||
|
|
||||||
|
|
||||||
|
Shows a popup suggesting to run a test/benchmark/binary **at the current cursor
|
||||||
|
location**. Super useful for repeatedly running just a single test. Do bind this
|
||||||
|
to a shortcut!
|
||||||
|
|
||||||
|
|===
|
||||||
|
| Editor | Action Name
|
||||||
|
|
||||||
|
| VS Code | **Rust Analyzer: Run**
|
||||||
|
|===
|
||||||
|
|
||||||
|
|
||||||
=== Workspace Symbol
|
=== Workspace Symbol
|
||||||
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/symbol_index.rs[symbol_index.rs]
|
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/symbol_index.rs[symbol_index.rs]
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,7 @@ impl Feature {
|
||||||
|
|
||||||
for block in comment_blocks {
|
for block in comment_blocks {
|
||||||
let id = block.id;
|
let id = block.id;
|
||||||
assert!(
|
assert!(is_valid_feature_name(&id), "invalid feature name: {:?}", id);
|
||||||
id.split_ascii_whitespace().all(|it| it.starts_with(char::is_uppercase)),
|
|
||||||
"bad feature: {}",
|
|
||||||
id
|
|
||||||
);
|
|
||||||
let doc = block.contents.join("\n");
|
let doc = block.contents.join("\n");
|
||||||
acc.push(Feature { id, path: path.clone(), doc })
|
acc.push(Feature { id, path: path.clone(), doc })
|
||||||
}
|
}
|
||||||
|
@ -52,6 +48,25 @@ impl Feature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_valid_feature_name(feature: &str) -> bool {
|
||||||
|
'word: for word in feature.split_whitespace() {
|
||||||
|
for &short in ["to"].iter() {
|
||||||
|
if word == short {
|
||||||
|
continue 'word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for &short in ["To"].iter() {
|
||||||
|
if word == short {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !word.starts_with(char::is_uppercase) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Feature {
|
impl fmt::Display for Feature {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
writeln!(f, "=== {}", self.id)?;
|
writeln!(f, "=== {}", self.id)?;
|
||||||
|
|
Loading…
Reference in a new issue