From b1d5817dd18b7b5fc102a63b084b1ee7ff4f9996 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 24 Apr 2020 23:40:41 +0200 Subject: Convert code to text-size --- crates/ra_hir/src/semantics.rs | 18 +++++++++--------- crates/ra_hir/src/source_analyzer.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 5d6edc45c..e09cf3185 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -14,7 +14,7 @@ use ra_db::{FileId, FileRange}; use ra_prof::profile; use ra_syntax::{ algo::{find_node_at_offset, skip_trivia_token}, - ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextUnit, + ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, }; use rustc_hash::{FxHashMap, FxHashSet}; @@ -95,7 +95,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { let token = successors(Some(parent.with_value(token)), |token| { let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; let tt = macro_call.token_tree()?; - if !token.value.text_range().is_subrange(&tt.syntax().text_range()) { + if !tt.syntax().text_range().contains_range(token.value.text_range()) { return None; } let file_id = sa.expand(self.db, token.with_value(¯o_call))?; @@ -114,7 +114,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { pub fn descend_node_at_offset( &self, node: &SyntaxNode, - offset: TextUnit, + offset: TextSize, ) -> Option { // Handle macro token cases node.token_at_offset(offset) @@ -142,7 +142,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { pub fn ancestors_at_offset_with_macros( &self, node: &SyntaxNode, - offset: TextUnit, + offset: TextSize, ) -> impl Iterator + '_ { node.token_at_offset(offset) .map(|token| self.ancestors_with_macros(token.parent())) @@ -154,7 +154,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { pub fn find_node_at_offset_with_macros( &self, node: &SyntaxNode, - offset: TextUnit, + offset: TextSize, ) -> Option { self.ancestors_at_offset_with_macros(node, offset).find_map(N::cast) } @@ -164,7 +164,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { pub fn find_node_at_offset_with_descend( &self, node: &SyntaxNode, - offset: TextUnit, + offset: TextSize, ) -> Option { if let Some(it) = find_node_at_offset(&node, offset) { return Some(it); @@ -255,7 +255,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { SemanticsScope { db: self.db, resolver } } - pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextUnit) -> SemanticsScope<'db, DB> { + pub fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db, DB> { let node = self.find_file(node.clone()); let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; SemanticsScope { db: self.db, resolver } @@ -271,7 +271,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.analyze2(src.as_ref(), None) } - fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option) -> SourceAnalyzer { + fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option) -> SourceAnalyzer { let _p = profile("Semantics::analyze2"); let container = match self.with_ctx(|ctx| ctx.find_container(src)) { @@ -463,7 +463,7 @@ fn original_range_opt( return None; } - Some(first.with_value(first.value.text_range().extend_to(&last.value.text_range()))) + Some(first.with_value(first.value.text_range().cover(last.value.text_range()))) })?) } diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 0ed6d0958..59a3a17d2 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs @@ -23,7 +23,7 @@ use hir_ty::{ }; use ra_syntax::{ ast::{self, AstNode}, - SyntaxNode, TextRange, TextUnit, + SyntaxNode, TextRange, TextSize, }; use crate::{ @@ -50,7 +50,7 @@ impl SourceAnalyzer { db: &dyn HirDatabase, def: DefWithBodyId, node: InFile<&SyntaxNode>, - offset: Option, + offset: Option, ) -> SourceAnalyzer { let (body, source_map) = db.body_with_source_map(def); let scopes = db.expr_scopes(def); @@ -318,7 +318,7 @@ fn scope_for_offset( db: &dyn HirDatabase, scopes: &ExprScopes, source_map: &BodySourceMap, - offset: InFile, + offset: InFile, ) -> Option { scopes .scope_by_expr() @@ -354,7 +354,7 @@ fn adjust( source_map: &BodySourceMap, expr_range: TextRange, file_id: HirFileId, - offset: TextUnit, + offset: TextSize, ) -> Option { let child_scopes = scopes .scope_by_expr() @@ -369,15 +369,15 @@ fn adjust( let node = source.value.to_node(&root); Some((node.syntax().text_range(), scope)) }) - .filter(|(range, _)| { - range.start() <= offset && range.is_subrange(&expr_range) && *range != expr_range + .filter(|&(range, _)| { + range.start() <= offset && expr_range.contains_range(range) && range != expr_range }); child_scopes - .max_by(|(r1, _), (r2, _)| { - if r2.is_subrange(&r1) { + .max_by(|&(r1, _), &(r2, _)| { + if r1.contains_range(r2) { std::cmp::Ordering::Greater - } else if r1.is_subrange(&r2) { + } else if r2.contains_range(r1) { std::cmp::Ordering::Less } else { r1.start().cmp(&r2.start()) -- cgit v1.2.3