From 503f9498cd469c6467250c02bd8f6dbce973dd57 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 29 Jun 2020 01:18:50 +0300 Subject: Follow matklad suggestions - Move vis_offset() to utils.rs - Shorten explicit ra_syntax::ast -> ast - Undo refactoring exhaustive pattern to non-exhaustive --- crates/ra_assists/src/utils.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/ra_assists/src/utils.rs') diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index b7c45a619..02de902d6 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs @@ -7,7 +7,9 @@ use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type}; use ra_ide_db::RootDatabase; use ra_syntax::{ ast::{self, make, NameOwner}, - AstNode, SyntaxNode, T, + AstNode, + SyntaxKind::*, + SyntaxNode, TextSize, T, }; use rustc_hash::FxHashSet; @@ -120,6 +122,13 @@ pub(crate) fn resolve_target_trait( } } +pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize { + node.children_with_tokens() + .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) + .map(|it| it.text_range().start()) + .unwrap_or_else(|| node.text_range().start()) +} + pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { if let Some(expr) = invert_special_case(&expr) { return expr; -- cgit v1.2.3