From c9598a4cbfdf4b0d0d993043dca48c1615b63145 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 29 May 2021 17:19:49 +0200 Subject: Add some lint completion tests --- crates/ide_completion/src/completions/attribute.rs | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'crates/ide_completion/src/completions/attribute.rs') diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 610fec65a..13d5b90c9 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs @@ -3,8 +3,6 @@ //! This module uses a bit of static metadata to provide completions //! for built-in attributes. -use std::mem; - use once_cell::sync::Lazy; use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ast, AstNode, NodeOrToken, SyntaxKind, T}; @@ -272,27 +270,27 @@ const ATTRIBUTES: &[AttrCompletion] = &[ fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Option> { let (l_paren, r_paren) = derive_input.l_paren_token().zip(derive_input.r_paren_token())?; let mut input_derives = FxHashSet::default(); - let mut current_derive = String::new(); - for token in derive_input + let mut tokens = derive_input .syntax() .children_with_tokens() .filter_map(NodeOrToken::into_token) .skip_while(|token| token != &l_paren) .skip(1) .take_while(|token| token != &r_paren) - { - if token.kind() == T![,] { - if !current_derive.is_empty() { - input_derives.insert(mem::take(&mut current_derive)); - } - } else { - current_derive.push_str(token.text().trim()); + .peekable(); + let mut input = String::new(); + while tokens.peek().is_some() { + for token in tokens.by_ref().take_while(|t| t.kind() != T![,]) { + input.push_str(token.text()); } - } - if !current_derive.is_empty() { - input_derives.insert(current_derive); + if !input.is_empty() { + input_derives.insert(input.trim().to_owned()); + } + + input.clear(); } + Some(input_derives) } -- cgit v1.2.3