From bf7a0f43d0e5bd9875f56013edba2e9ce6c40e33 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Jan 2019 16:26:30 +0300 Subject: minor cleanups --- crates/ra_ide_api_light/src/folding_ranges.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/crates/ra_ide_api_light/src/folding_ranges.rs b/crates/ra_ide_api_light/src/folding_ranges.rs index 87feb9bd8..c73637323 100644 --- a/crates/ra_ide_api_light/src/folding_ranges.rs +++ b/crates/ra_ide_api_light/src/folding_ranges.rs @@ -1,8 +1,9 @@ use rustc_hash::FxHashSet; use ra_syntax::{ - ast, AstNode, Direction, SourceFile, SyntaxNode, TextRange, + AstNode, Direction, SourceFile, SyntaxNode, TextRange, SyntaxKind::{self, *}, + ast::{self, VisibilityOwner}, }; #[derive(Debug, PartialEq, Eq)] @@ -28,7 +29,7 @@ pub fn folding_ranges(file: &SourceFile) -> Vec { for node in file.syntax().descendants() { // Fold items that span multiple lines if let Some(kind) = fold_kind(node.kind()) { - if has_newline(node) { + if node.text().contains('\n') { res.push(Fold { range: node.range(), kind, @@ -83,27 +84,9 @@ fn fold_kind(kind: SyntaxKind) -> Option { } fn has_visibility(node: &SyntaxNode) -> bool { - use ast::VisibilityOwner; - - return ast::Module::cast(node) + ast::Module::cast(node) .and_then(|m| m.visibility()) - .is_some(); -} - -fn has_newline(node: &SyntaxNode) -> bool { - for descendant in node.descendants() { - if let Some(ws) = ast::Whitespace::cast(descendant) { - if ws.has_newlines() { - return true; - } - } else if let Some(comment) = ast::Comment::cast(descendant) { - if comment.has_newlines() { - return true; - } - } - } - - false + .is_some() } fn contiguous_range_for_group<'a>( -- cgit v1.2.3