673: minor cleanups r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-01-26 13:26:56 +00:00
commit 5af7b2f4af

View file

@ -1,8 +1,9 @@
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use ra_syntax::{ use ra_syntax::{
ast, AstNode, Direction, SourceFile, SyntaxNode, TextRange, AstNode, Direction, SourceFile, SyntaxNode, TextRange,
SyntaxKind::{self, *}, SyntaxKind::{self, *},
ast::{self, VisibilityOwner},
}; };
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -28,7 +29,7 @@ pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
for node in file.syntax().descendants() { for node in file.syntax().descendants() {
// Fold items that span multiple lines // Fold items that span multiple lines
if let Some(kind) = fold_kind(node.kind()) { if let Some(kind) = fold_kind(node.kind()) {
if has_newline(node) { if node.text().contains('\n') {
res.push(Fold { res.push(Fold {
range: node.range(), range: node.range(),
kind, kind,
@ -83,27 +84,9 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
} }
fn has_visibility(node: &SyntaxNode) -> bool { fn has_visibility(node: &SyntaxNode) -> bool {
use ast::VisibilityOwner; ast::Module::cast(node)
return ast::Module::cast(node)
.and_then(|m| m.visibility()) .and_then(|m| m.visibility())
.is_some(); .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
} }
fn contiguous_range_for_group<'a>( fn contiguous_range_for_group<'a>(