mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
fix: Fix lint completions not working for unclosed attributes
This commit is contained in:
parent
03f6d92ae4
commit
0001a42570
3 changed files with 39 additions and 25 deletions
|
@ -305,20 +305,24 @@ pub fn lint_eq_or_in_group(lint: &str, lint_is: &str) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses the input token tree as comma separated paths.
|
||||
/// Parses the input token tree as comma separated plain paths.
|
||||
pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option<Vec<ast::Path>> {
|
||||
let r_paren = input.r_paren_token()?;
|
||||
let tokens = input
|
||||
.syntax()
|
||||
.children_with_tokens()
|
||||
.skip(1)
|
||||
.take_while(|it| it.as_token() != Some(&r_paren));
|
||||
let r_paren = input.r_paren_token();
|
||||
let tokens =
|
||||
input.syntax().children_with_tokens().skip(1).map_while(|it| match it.into_token() {
|
||||
// seeing a keyword means the attribute is unclosed so stop parsing here
|
||||
Some(tok) if tok.kind().is_keyword() => None,
|
||||
// don't include the right token tree parenthesis if it exists
|
||||
tok @ Some(_) if tok == r_paren => None,
|
||||
// only nodes that we can find are other TokenTrees, those are unexpected in this parse though
|
||||
None => None,
|
||||
Some(tok) => Some(tok),
|
||||
});
|
||||
let input_expressions = tokens.into_iter().group_by(|tok| tok.kind() == T![,]);
|
||||
Some(
|
||||
input_expressions
|
||||
.into_iter()
|
||||
.filter_map(|(is_sep, group)| (!is_sep).then(|| group))
|
||||
.filter_map(|mut tokens| ast::Path::parse(&tokens.join("")).ok())
|
||||
.collect::<Vec<ast::Path>>(),
|
||||
)
|
||||
let paths = input_expressions
|
||||
.into_iter()
|
||||
.filter_map(|(is_sep, group)| (!is_sep).then(|| group))
|
||||
.filter_map(|mut tokens| ast::Path::parse(&tokens.join("")).ok())
|
||||
.collect();
|
||||
Some(paths)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue