From d689fd30bc8be66bda9b9a2d787bbc236a1ba587 Mon Sep 17 00:00:00 2001 From: DropDemBits Date: Fri, 31 Mar 2023 14:43:24 -0400 Subject: [PATCH 1/3] Remove outdated comment in sourcegen `CommentBlock::extract` does handle blank lines in comment blocks --- crates/ide-assists/src/tests/sourcegen.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/ide-assists/src/tests/sourcegen.rs b/crates/ide-assists/src/tests/sourcegen.rs index b4f50c7fb2..3da90e9052 100644 --- a/crates/ide-assists/src/tests/sourcegen.rs +++ b/crates/ide-assists/src/tests/sourcegen.rs @@ -90,8 +90,6 @@ impl Assist { let comment_blocks = sourcegen::CommentBlock::extract("Assist", &text); for block in comment_blocks { - // FIXME: doesn't support blank lines yet, need to tweak - // `extract_comment_blocks` for that. let id = block.id; assert!( id.chars().all(|it| it.is_ascii_lowercase() || it == '_'), From afe3dcd3ff6a5d64fc27311c2768070300c055d1 Mon Sep 17 00:00:00 2001 From: DropDemBits Date: Fri, 31 Mar 2023 17:41:40 -0400 Subject: [PATCH 2/3] Use `retain_mut` in `CommentBlock::extract` --- crates/sourcegen/src/lib.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/sourcegen/src/lib.rs b/crates/sourcegen/src/lib.rs index 72d26635c3..c5da6ceb4d 100644 --- a/crates/sourcegen/src/lib.rs +++ b/crates/sourcegen/src/lib.rs @@ -58,21 +58,19 @@ impl CommentBlock { assert!(tag.starts_with(char::is_uppercase)); let tag = format!("{tag}:"); - // Would be nice if we had `.retain_mut` here! - CommentBlock::extract_untagged(text) - .into_iter() - .filter_map(|mut block| { - let first = block.contents.remove(0); - first.strip_prefix(&tag).map(|id| { - if block.is_doc { - panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}"); - } + let mut blocks = CommentBlock::extract_untagged(text); + blocks.retain_mut(|block| { + let first = block.contents.remove(0); + let Some(id) = first.strip_prefix(&tag) else { return false; }; - block.id = id.trim().to_string(); - block - }) - }) - .collect() + if block.is_doc { + panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}"); + } + + block.id = id.trim().to_string(); + true + }); + blocks } pub fn extract_untagged(text: &str) -> Vec { From 0a144f7fffda62e2d4fe52dca41a8c39a96cce36 Mon Sep 17 00:00:00 2001 From: DropDemBits Date: Fri, 31 Mar 2023 17:48:59 -0400 Subject: [PATCH 3/3] Use bind by-move to get the parent from the match --- crates/ide/src/syntax_highlighting/highlight.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 2111baad74..936362914a 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -675,14 +675,12 @@ fn is_consumed_lvalue(node: &SyntaxNode, local: &hir::Local, db: &RootDatabase) /// Returns true if the parent nodes of `node` all match the `SyntaxKind`s in `kinds` exactly. fn parents_match(mut node: NodeOrToken, mut kinds: &[SyntaxKind]) -> bool { - while let (Some(parent), [kind, rest @ ..]) = (&node.parent(), kinds) { + while let (Some(parent), [kind, rest @ ..]) = (node.parent(), kinds) { if parent.kind() != *kind { return false; } - // FIXME: Would be nice to get parent out of the match, but binding by-move and by-value - // in the same pattern is unstable: rust-lang/rust#68354. - node = node.parent().unwrap().into(); + node = parent.into(); kinds = rest; }