aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/Cargo.toml1
-rw-r--r--crates/ra_hir/src/code_model.rs7
-rw-r--r--crates/ra_hir/src/code_model/src.rs12
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs7
5 files changed, 17 insertions, 12 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index e79361e7c..6ca9cc2e7 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -10,6 +10,7 @@ doctest = false
10[dependencies] 10[dependencies]
11log = "0.4.5" 11log = "0.4.5"
12rustc-hash = "1.0" 12rustc-hash = "1.0"
13either = "1.5"
13 14
14ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
15ra_db = { path = "../ra_db" } 16ra_db = { path = "../ra_db" }
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index dddac915b..5877afefa 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -4,6 +4,7 @@ pub(crate) mod src;
4 4
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use either::Either;
7use hir_def::{ 8use hir_def::{
8 adt::VariantData, 9 adt::VariantData,
9 body::{Body, BodySourceMap}, 10 body::{Body, BodySourceMap},
@@ -30,7 +31,7 @@ use crate::{
30 db::{DefDatabase, HirDatabase}, 31 db::{DefDatabase, HirDatabase},
31 ty::display::HirFormatter, 32 ty::display::HirFormatter,
32 ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, 33 ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk},
33 CallableDef, Either, HirDisplay, InFile, Name, 34 CallableDef, HirDisplay, InFile, Name,
34}; 35};
35 36
36/// hir::Crate describes a single crate. It's the main interface with which 37/// hir::Crate describes a single crate. It's the main interface with which
@@ -905,7 +906,9 @@ impl Local {
905 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 906 let (_body, source_map) = db.body_with_source_map(self.parent.into());
906 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... 907 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
907 let root = src.file_syntax(db); 908 let root = src.file_syntax(db);
908 src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) 909 src.map(|ast| {
910 ast.map_left(|it| it.cast().unwrap().to_node(&root)).map_right(|it| it.to_node(&root))
911 })
909 } 912 }
910} 913}
911 914
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 2cf210349..36cfbc8f1 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -1,10 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use either::Either;
3use hir_def::{ 4use hir_def::{
4 src::{HasChildSource, HasSource as _}, 5 src::{HasChildSource, HasSource as _},
5 AstItemDef, Lookup, VariantId, 6 AstItemDef, Lookup, VariantId,
6}; 7};
7use hir_expand::either::Either;
8use ra_syntax::ast; 8use ra_syntax::ast;
9 9
10use crate::{ 10use crate::{
@@ -27,8 +27,8 @@ impl Module {
27 let def_map = db.crate_def_map(self.id.krate); 27 let def_map = db.crate_def_map(self.id.krate);
28 let src = def_map[self.id.local_id].definition_source(db); 28 let src = def_map[self.id.local_id].definition_source(db);
29 src.map(|it| match it { 29 src.map(|it| match it {
30 Either::A(it) => ModuleSource::SourceFile(it), 30 Either::Left(it) => ModuleSource::SourceFile(it),
31 Either::B(it) => ModuleSource::Module(it), 31 Either::Right(it) => ModuleSource::Module(it),
32 }) 32 })
33 } 33 }
34 34
@@ -46,8 +46,8 @@ impl HasSource for StructField {
46 let var = VariantId::from(self.parent); 46 let var = VariantId::from(self.parent);
47 let src = var.child_source(db); 47 let src = var.child_source(db);
48 src.map(|it| match it[self.id].clone() { 48 src.map(|it| match it[self.id].clone() {
49 Either::A(it) => FieldSource::Pos(it), 49 Either::Left(it) => FieldSource::Pos(it),
50 Either::B(it) => FieldSource::Named(it), 50 Either::Right(it) => FieldSource::Named(it),
51 }) 51 })
52 } 52 }
53} 53}
@@ -126,6 +126,6 @@ impl HasSource for Import {
126 let (_, source_map) = db.raw_items_with_source_map(src.file_id); 126 let (_, source_map) = db.raw_items_with_source_map(src.file_id);
127 let root = db.parse_or_expand(src.file_id).unwrap(); 127 let root = db.parse_or_expand(src.file_id).unwrap();
128 let ptr = source_map.get(self.id); 128 let ptr = source_map.get(self.id);
129 src.with_value(ptr.map(|it| it.to_node(&root), |it| it.to_node(&root))) 129 src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root)))
130 } 130 }
131} 131}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 88d2f6e02..853760cb1 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -63,5 +63,5 @@ pub use hir_def::{
63 type_ref::Mutability, 63 type_ref::Mutability,
64}; 64};
65pub use hir_expand::{ 65pub use hir_expand::{
66 either::Either, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, 66 name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile,
67}; 67};
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 0df7a7cb4..28d41b647 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -7,6 +7,7 @@
7//! purely for "IDE needs". 7//! purely for "IDE needs".
8use std::sync::Arc; 8use std::sync::Arc;
9 9
10use either::Either;
10use hir_def::{ 11use hir_def::{
11 body::{ 12 body::{
12 scope::{ExprScopes, ScopeId}, 13 scope::{ExprScopes, ScopeId},
@@ -33,8 +34,8 @@ use crate::{
33 method_resolution::{self, implements_trait}, 34 method_resolution::{self, implements_trait},
34 InEnvironment, TraitEnvironment, Ty, 35 InEnvironment, TraitEnvironment, Ty,
35 }, 36 },
36 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 37 Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam,
37 GenericParam, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, 38 Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
38}; 39};
39 40
40fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { 41fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
@@ -349,7 +350,7 @@ impl SourceAnalyzer {
349 // should switch to general reference search infra there. 350 // should switch to general reference search infra there.
350 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { 351 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
351 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); 352 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
352 let ptr = Either::A(AstPtr::new(&ast::Pat::from(pat.clone()))); 353 let ptr = Either::Left(AstPtr::new(&ast::Pat::from(pat.clone())));
353 fn_def 354 fn_def
354 .syntax() 355 .syntax()
355 .descendants() 356 .descendants()