mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Support standalone comments
This commit is contained in:
parent
8d61216957
commit
4972cb759e
1 changed files with 65 additions and 16 deletions
|
@ -22,9 +22,8 @@ use syntax::{
|
||||||
edit::{AstNodeEdit, IndentLevel},
|
edit::{AstNodeEdit, IndentLevel},
|
||||||
AstNode,
|
AstNode,
|
||||||
},
|
},
|
||||||
match_ast, ted, SyntaxElement,
|
match_ast, ted, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
||||||
SyntaxKind::{self, COMMENT},
|
TokenAtOffset, WalkEvent, T,
|
||||||
SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, WalkEvent, T,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -63,13 +62,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = ctx.covering_element();
|
let node = match ctx.covering_element() {
|
||||||
if node.kind() == COMMENT {
|
|
||||||
cov_mark::hit!(extract_function_in_comment_is_not_applicable);
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let node = match node {
|
|
||||||
syntax::NodeOrToken::Node(n) => n,
|
syntax::NodeOrToken::Node(n) => n,
|
||||||
syntax::NodeOrToken::Token(t) => t.parent()?,
|
syntax::NodeOrToken::Token(t) => t.parent()?,
|
||||||
};
|
};
|
||||||
|
@ -2207,12 +2200,6 @@ fn $0fun_name(n: u32) -> u32 {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn in_comment_is_not_applicable() {
|
|
||||||
cov_mark::check!(extract_function_in_comment_is_not_applicable);
|
|
||||||
check_assist_not_applicable(extract_function, r"fn main() { 1 + /* $0comment$0 */ 1; }");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn part_of_expr_stmt() {
|
fn part_of_expr_stmt() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
@ -4572,6 +4559,68 @@ fn $0fun_name() {
|
||||||
/* a comment */
|
/* a comment */
|
||||||
let x = 0;
|
let x = 0;
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_function_long_form_comment_multiline() {
|
||||||
|
check_assist(
|
||||||
|
extract_function,
|
||||||
|
r#"
|
||||||
|
fn func() {
|
||||||
|
let i = 0;
|
||||||
|
$0/*
|
||||||
|
a
|
||||||
|
comment
|
||||||
|
*/
|
||||||
|
let x = 0;$0
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn func() {
|
||||||
|
let i = 0;
|
||||||
|
fun_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn $0fun_name() {
|
||||||
|
/*
|
||||||
|
a
|
||||||
|
comment
|
||||||
|
*/
|
||||||
|
let x = 0;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extract_function_long_form_comment_multiline_alone() {
|
||||||
|
check_assist(
|
||||||
|
extract_function,
|
||||||
|
r#"
|
||||||
|
fn func() {
|
||||||
|
let i = 0;
|
||||||
|
$0/*
|
||||||
|
a
|
||||||
|
comment
|
||||||
|
*/
|
||||||
|
$0let x = 0;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn func() {
|
||||||
|
let i = 0;
|
||||||
|
fun_name();
|
||||||
|
let x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn $0fun_name() {
|
||||||
|
/*
|
||||||
|
a
|
||||||
|
comment
|
||||||
|
*/
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue