aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-30 10:25:53 +0000
committerAleksey Kladov <[email protected]>2019-04-01 10:06:24 +0100
commit9e213385c9d06db3c8ca20812779e2b8f8ad2c71 (patch)
treefe57697b54ccfb791fe96c13cb553a8570516270 /crates/ra_hir/src
parentdec9bde10868b5e459535449476d17a6a0987b3e (diff)
switch to new rowan
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/expr.rs12
-rw-r--r--crates/ra_hir/src/source_binder.rs8
-rw-r--r--crates/ra_hir/src/ty/tests.rs14
3 files changed, 12 insertions, 22 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index a85422955..2ff4139f9 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -726,13 +726,7 @@ impl ExprCollector {
726 self.alloc_expr(Expr::Array { exprs }, syntax_ptr) 726 self.alloc_expr(Expr::Array { exprs }, syntax_ptr)
727 } 727 }
728 ast::ExprKind::Literal(e) => { 728 ast::ExprKind::Literal(e) => {
729 let child = if let Some(child) = e.literal_expr() { 729 let lit = match e.flavor() {
730 child
731 } else {
732 return self.alloc_expr(Expr::Missing, syntax_ptr);
733 };
734
735 let lit = match child.flavor() {
736 LiteralFlavor::IntNumber { suffix } => { 730 LiteralFlavor::IntNumber { suffix } => {
737 let known_name = suffix 731 let known_name = suffix
738 .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known)); 732 .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known));
@@ -874,9 +868,7 @@ impl ExprCollector {
874 fn collect_fn_body(&mut self, node: &ast::FnDef) { 868 fn collect_fn_body(&mut self, node: &ast::FnDef) {
875 if let Some(param_list) = node.param_list() { 869 if let Some(param_list) = node.param_list() {
876 if let Some(self_param) = param_list.self_param() { 870 if let Some(self_param) = param_list.self_param() {
877 let self_param = SyntaxNodePtr::new( 871 let self_param = SyntaxNodePtr::new(self_param.syntax());
878 self_param.self_kw().expect("self param without self keyword").syntax(),
879 );
880 let param_pat = self.alloc_pat( 872 let param_pat = self.alloc_pat(
881 Pat::Bind { 873 Pat::Bind {
882 name: Name::self_param(), 874 name: Name::self_param(),
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 9dae4c3d1..54dc27399 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -9,7 +9,7 @@ use ra_db::{FileId, FilePosition};
9use ra_syntax::{ 9use ra_syntax::{
10 SyntaxNode, 10 SyntaxNode,
11 ast::{self, AstNode, NameOwner}, 11 ast::{self, AstNode, NameOwner},
12 algo::{find_node_at_offset, find_leaf_at_offset}, 12 algo::{find_node_at_offset, find_token_at_offset},
13}; 13};
14 14
15use crate::{ 15use crate::{
@@ -155,9 +155,9 @@ pub fn trait_from_module(
155pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { 155pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver {
156 let file_id = position.file_id; 156 let file_id = position.file_id;
157 let file = db.parse(file_id); 157 let file = db.parse(file_id);
158 find_leaf_at_offset(file.syntax(), position.offset) 158 find_token_at_offset(file.syntax(), position.offset)
159 .find_map(|node| { 159 .find_map(|token| {
160 node.ancestors().find_map(|node| { 160 token.parent().ancestors().find_map(|node| {
161 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { 161 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() {
162 if let Some(func) = function_from_child_node(db, file_id, node) { 162 if let Some(func) = function_from_child_node(db, file_id, node) {
163 let scopes = func.scopes(db); 163 let scopes = func.scopes(db);
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 655f3c522..943c5499b 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2251,14 +2251,12 @@ fn infer(content: &str) -> String {
2251 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); 2251 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end()));
2252 for (syntax_ptr, ty) in &types { 2252 for (syntax_ptr, ty) in &types {
2253 let node = syntax_ptr.to_node(&source_file); 2253 let node = syntax_ptr.to_node(&source_file);
2254 write!( 2254 let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) {
2255 acc, 2255 (self_param.self_kw_token().range(), "self".to_string())
2256 "{} '{}': {}\n", 2256 } else {
2257 syntax_ptr.range(), 2257 (syntax_ptr.range(), node.text().to_string().replace("\n", " "))
2258 ellipsize(node.text().to_string().replace("\n", " "), 15), 2258 };
2259 ty.display(&db) 2259 write!(acc, "{} '{}': {}\n", range, ellipsize(text, 15), ty.display(&db)).unwrap();
2260 )
2261 .unwrap();
2262 } 2260 }
2263 } 2261 }
2264 acc.truncate(acc.trim_end().len()); 2262 acc.truncate(acc.trim_end().len());