mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Update inline_call
assist doc example
This commit is contained in:
parent
2bc4f9e371
commit
2579dc6d82
4 changed files with 33 additions and 32 deletions
|
@ -17,23 +17,18 @@ use crate::{
|
|||
// Inlines a function or method body.
|
||||
//
|
||||
// ```
|
||||
// fn align(a: u32, b: u32) -> u32 {
|
||||
// (a + b - 1) & !(b - 1)
|
||||
// }
|
||||
// fn main() {
|
||||
// let x = align$0(1, 2);
|
||||
// # //- minicore: option
|
||||
// fn foo(name: Option<&str>) {
|
||||
// let name = name.unwrap$0();
|
||||
// }
|
||||
// ```
|
||||
// ->
|
||||
// ```
|
||||
// fn align(a: u32, b: u32) -> u32 {
|
||||
// (a + b - 1) & !(b - 1)
|
||||
// }
|
||||
// fn main() {
|
||||
// let x = {
|
||||
// let b = 2;
|
||||
// (1 + b - 1) & !(b - 1)
|
||||
// };
|
||||
// fn foo(name: Option<&str>) {
|
||||
// let name = match name {
|
||||
// Some(val) => val,
|
||||
// None => panic!("called `Option::unwrap()` on a `None` value"),
|
||||
// };
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
|
|
|
@ -923,22 +923,17 @@ fn doctest_inline_call() {
|
|||
check_doc_test(
|
||||
"inline_call",
|
||||
r#####"
|
||||
fn align(a: u32, b: u32) -> u32 {
|
||||
(a + b - 1) & !(b - 1)
|
||||
}
|
||||
fn main() {
|
||||
let x = align$0(1, 2);
|
||||
//- minicore: option
|
||||
fn foo(name: Option<&str>) {
|
||||
let name = name.unwrap$0();
|
||||
}
|
||||
"#####,
|
||||
r#####"
|
||||
fn align(a: u32, b: u32) -> u32 {
|
||||
(a + b - 1) & !(b - 1)
|
||||
}
|
||||
fn main() {
|
||||
let x = {
|
||||
let b = 2;
|
||||
(1 + b - 1) & !(b - 1)
|
||||
};
|
||||
fn foo(name: Option<&str>) {
|
||||
let name = match name {
|
||||
Some(val) => val,
|
||||
None => panic!("called `Option::unwrap()` on a `None` value"),
|
||||
};
|
||||
}
|
||||
"#####,
|
||||
)
|
||||
|
|
|
@ -161,6 +161,14 @@ fn ws_before(position: &Position, new: &SyntaxElement) -> Option<SyntaxToken> {
|
|||
}
|
||||
}
|
||||
|
||||
if prev.kind() == T!['{'] && ast::Stmt::can_cast(new.kind()) {
|
||||
if let Some(block_expr) = prev.parent().and_then(ast::BlockExpr::cast) {
|
||||
let mut indent = IndentLevel::from_element(&block_expr.syntax().clone().into());
|
||||
indent.0 += 1;
|
||||
return Some(make::tokens::whitespace(&format!("\n{}", indent)));
|
||||
}
|
||||
}
|
||||
|
||||
ws_between(prev, new)
|
||||
}
|
||||
fn ws_after(position: &Position, new: &SyntaxElement) -> Option<SyntaxToken> {
|
||||
|
@ -187,12 +195,6 @@ fn ws_between(left: &SyntaxElement, right: &SyntaxElement) -> Option<SyntaxToken
|
|||
return None;
|
||||
}
|
||||
|
||||
if left.kind() == T!['{'] && right.kind() == SyntaxKind::LET_STMT {
|
||||
let mut indent = IndentLevel::from_element(left);
|
||||
indent.0 += 1;
|
||||
return Some(make::tokens::whitespace(&format!("\n{}", indent)));
|
||||
}
|
||||
|
||||
if right.kind() == SyntaxKind::USE {
|
||||
let mut indent = IndentLevel::from_element(left);
|
||||
if left.kind() == SyntaxKind::USE {
|
||||
|
|
|
@ -330,6 +330,15 @@ pub mod option {
|
|||
#[lang = "Some"]
|
||||
Some(T),
|
||||
}
|
||||
|
||||
impl<T> Option<T> {
|
||||
pub const fn unwrap(self) -> T {
|
||||
match self {
|
||||
Some(val) => val,
|
||||
None => panic!("called `Option::unwrap()` on a `None` value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// endregion:option
|
||||
|
||||
|
|
Loading…
Reference in a new issue