mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +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.
|
// Inlines a function or method body.
|
||||||
//
|
//
|
||||||
// ```
|
// ```
|
||||||
// fn align(a: u32, b: u32) -> u32 {
|
// # //- minicore: option
|
||||||
// (a + b - 1) & !(b - 1)
|
// fn foo(name: Option<&str>) {
|
||||||
// }
|
// let name = name.unwrap$0();
|
||||||
// fn main() {
|
|
||||||
// let x = align$0(1, 2);
|
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
// ->
|
// ->
|
||||||
// ```
|
// ```
|
||||||
// fn align(a: u32, b: u32) -> u32 {
|
// fn foo(name: Option<&str>) {
|
||||||
// (a + b - 1) & !(b - 1)
|
// let name = match name {
|
||||||
// }
|
// Some(val) => val,
|
||||||
// fn main() {
|
// None => panic!("called `Option::unwrap()` on a `None` value"),
|
||||||
// let x = {
|
// };
|
||||||
// let b = 2;
|
|
||||||
// (1 + b - 1) & !(b - 1)
|
|
||||||
// };
|
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||||
|
|
|
@ -923,22 +923,17 @@ fn doctest_inline_call() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
"inline_call",
|
"inline_call",
|
||||||
r#####"
|
r#####"
|
||||||
fn align(a: u32, b: u32) -> u32 {
|
//- minicore: option
|
||||||
(a + b - 1) & !(b - 1)
|
fn foo(name: Option<&str>) {
|
||||||
}
|
let name = name.unwrap$0();
|
||||||
fn main() {
|
|
||||||
let x = align$0(1, 2);
|
|
||||||
}
|
}
|
||||||
"#####,
|
"#####,
|
||||||
r#####"
|
r#####"
|
||||||
fn align(a: u32, b: u32) -> u32 {
|
fn foo(name: Option<&str>) {
|
||||||
(a + b - 1) & !(b - 1)
|
let name = match name {
|
||||||
}
|
Some(val) => val,
|
||||||
fn main() {
|
None => panic!("called `Option::unwrap()` on a `None` value"),
|
||||||
let x = {
|
};
|
||||||
let b = 2;
|
|
||||||
(1 + b - 1) & !(b - 1)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
"#####,
|
"#####,
|
||||||
)
|
)
|
||||||
|
|
|
@ -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)
|
ws_between(prev, new)
|
||||||
}
|
}
|
||||||
fn ws_after(position: &Position, new: &SyntaxElement) -> Option<SyntaxToken> {
|
fn ws_after(position: &Position, new: &SyntaxElement) -> Option<SyntaxToken> {
|
||||||
|
@ -187,12 +195,6 @@ fn ws_between(left: &SyntaxElement, right: &SyntaxElement) -> Option<SyntaxToken
|
||||||
return None;
|
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 {
|
if right.kind() == SyntaxKind::USE {
|
||||||
let mut indent = IndentLevel::from_element(left);
|
let mut indent = IndentLevel::from_element(left);
|
||||||
if left.kind() == SyntaxKind::USE {
|
if left.kind() == SyntaxKind::USE {
|
||||||
|
|
|
@ -330,6 +330,15 @@ pub mod option {
|
||||||
#[lang = "Some"]
|
#[lang = "Some"]
|
||||||
Some(T),
|
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
|
// endregion:option
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue