From 3da52d2e936bf797d7fe1a9c6c9fad78e19c7d83 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 15 May 2021 17:22:39 +0200 Subject: simplify --- crates/ide/src/matching_brace.rs | 12 ++++-------- crates/ide/src/parent_module.rs | 6 ++++-- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/matching_brace.rs b/crates/ide/src/matching_brace.rs index 261dcc255..011c8cc55 100644 --- a/crates/ide/src/matching_brace.rs +++ b/crates/ide/src/matching_brace.rs @@ -19,14 +19,10 @@ use syntax::{ pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option { const BRACES: &[SyntaxKind] = &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]]; - let (brace_token, brace_idx) = file - .syntax() - .token_at_offset(offset) - .filter_map(|node| { - let idx = BRACES.iter().position(|&brace| brace == node.kind())?; - Some((node, idx)) - }) - .next()?; + let (brace_token, brace_idx) = file.syntax().token_at_offset(offset).find_map(|node| { + let idx = BRACES.iter().position(|&brace| brace == node.kind())?; + Some((node, idx)) + })?; let parent = brace_token.parent()?; if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) { cov_mark::hit!(pipes_not_braces); diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 99365c8a7..9b1f48044 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -1,6 +1,8 @@ use hir::Semantics; -use ide_db::base_db::{CrateId, FileId, FilePosition}; -use ide_db::RootDatabase; +use ide_db::{ + base_db::{CrateId, FileId, FilePosition}, + RootDatabase, +}; use itertools::Itertools; use syntax::{ algo::find_node_at_offset, -- cgit v1.2.3 From 4b5b54279ad74316837bcdc7daa195d82bd13d3a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 15 May 2021 17:23:20 +0200 Subject: Attach comments to ast::Impl --- .../syntax_highlighting/test_data/highlight_doctest.html | 14 +++++++++++++- crates/ide/src/syntax_highlighting/tests.rs | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 8d83ba206..921a956e6 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -37,13 +37,25 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
/// ```
+
//! This is a module to test doc injection.
+//! ```
+//! fn test() {}
+//! ```
+
+/// ```
 /// let _ = "early doctests should not go boom";
 /// ```
 struct Foo {
     bar: bool,
 }
 
+/// This is an impl with a code block.
+///
+/// ```
+/// fn foo() {
+///
+/// }
+/// ```
 impl Foo {
     /// ```
     /// let _ = "Call me
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 32f2d9038..95408dfb2 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -524,6 +524,11 @@ fn main() {
 fn test_highlight_doc_comment() {
     check_highlighting(
         r#"
+//! This is a module to test doc injection.
+//! ```
+//! fn test() {}
+//! ```
+
 /// ```
 /// let _ = "early doctests should not go boom";
 /// ```
@@ -531,6 +536,13 @@ struct Foo {
     bar: bool,
 }
 
+/// This is an impl with a code block.
+///
+/// ```
+/// fn foo() {
+///
+/// }
+/// ```
 impl Foo {
     /// ```
     /// let _ = "Call me
-- 
cgit v1.2.3