aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/attribute.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-05-29 16:19:49 +0100
committerLukas Wirth <[email protected]>2021-05-29 16:19:49 +0100
commitc9598a4cbfdf4b0d0d993043dca48c1615b63145 (patch)
treeb889e39b10c90f253bb23aeb2fdde8c8da8e55e8 /crates/ide_completion/src/completions/attribute.rs
parent247faf271b9098624cb0b09dd4914da66497dd5a (diff)
Add some lint completion tests
Diffstat (limited to 'crates/ide_completion/src/completions/attribute.rs')
-rw-r--r--crates/ide_completion/src/completions/attribute.rs26
1 files changed, 12 insertions, 14 deletions
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 @@
3//! This module uses a bit of static metadata to provide completions 3//! This module uses a bit of static metadata to provide completions
4//! for built-in attributes. 4//! for built-in attributes.
5 5
6use std::mem;
7
8use once_cell::sync::Lazy; 6use once_cell::sync::Lazy;
9use rustc_hash::{FxHashMap, FxHashSet}; 7use rustc_hash::{FxHashMap, FxHashSet};
10use syntax::{ast, AstNode, NodeOrToken, SyntaxKind, T}; 8use syntax::{ast, AstNode, NodeOrToken, SyntaxKind, T};
@@ -272,27 +270,27 @@ const ATTRIBUTES: &[AttrCompletion] = &[
272fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Option<FxHashSet<String>> { 270fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Option<FxHashSet<String>> {
273 let (l_paren, r_paren) = derive_input.l_paren_token().zip(derive_input.r_paren_token())?; 271 let (l_paren, r_paren) = derive_input.l_paren_token().zip(derive_input.r_paren_token())?;
274 let mut input_derives = FxHashSet::default(); 272 let mut input_derives = FxHashSet::default();
275 let mut current_derive = String::new(); 273 let mut tokens = derive_input
276 for token in derive_input
277 .syntax() 274 .syntax()
278 .children_with_tokens() 275 .children_with_tokens()
279 .filter_map(NodeOrToken::into_token) 276 .filter_map(NodeOrToken::into_token)
280 .skip_while(|token| token != &l_paren) 277 .skip_while(|token| token != &l_paren)
281 .skip(1) 278 .skip(1)
282 .take_while(|token| token != &r_paren) 279 .take_while(|token| token != &r_paren)
283 { 280 .peekable();
284 if token.kind() == T![,] { 281 let mut input = String::new();
285 if !current_derive.is_empty() { 282 while tokens.peek().is_some() {
286 input_derives.insert(mem::take(&mut current_derive)); 283 for token in tokens.by_ref().take_while(|t| t.kind() != T![,]) {
287 } 284 input.push_str(token.text());
288 } else {
289 current_derive.push_str(token.text().trim());
290 } 285 }
291 }
292 286
293 if !current_derive.is_empty() { 287 if !input.is_empty() {
294 input_derives.insert(current_derive); 288 input_derives.insert(input.trim().to_owned());
289 }
290
291 input.clear();
295 } 292 }
293
296 Some(input_derives) 294 Some(input_derives)
297} 295}
298 296