aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/lib.rs3
-rw-r--r--crates/ra_hir/src/semantics.rs17
-rw-r--r--crates/ra_hir/src/source_analyzer.rs25
3 files changed, 19 insertions, 26 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index e1cb12cca..9f59d590c 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -45,8 +45,7 @@ pub use crate::{
45 StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, 45 StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef,
46 }, 46 },
47 has_source::HasSource, 47 has_source::HasSource,
48 semantics::{original_range, Semantics, SemanticsScope}, 48 semantics::{original_range, PathResolution, Semantics, SemanticsScope},
49 source_analyzer::PathResolution,
50}; 49};
51 50
52pub use hir_def::{ 51pub use hir_def::{
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 7ce785791..965d185a4 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -20,10 +20,23 @@ use crate::{
20 db::HirDatabase, 20 db::HirDatabase,
21 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 21 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
22 source_analyzer::{resolve_hir_path, SourceAnalyzer}, 22 source_analyzer::{resolve_hir_path, SourceAnalyzer},
23 Function, HirFileId, InFile, Local, MacroDef, Module, ModuleDef, Name, Origin, Path, 23 AssocItem, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, Name,
24 PathResolution, ScopeDef, StructField, Trait, Type, TypeParam, VariantDef, 24 Origin, Path, ScopeDef, StructField, Trait, Type, TypeParam, VariantDef,
25}; 25};
26 26
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum PathResolution {
29 /// An item
30 Def(ModuleDef),
31 /// A local binding (only value namespace)
32 Local(Local),
33 /// A generic parameter
34 TypeParam(TypeParam),
35 SelfType(ImplDef),
36 Macro(MacroDef),
37 AssocItem(AssocItem),
38}
39
27/// Primary API to get semantic information, like types, from syntax trees. 40/// Primary API to get semantic information, like types, from syntax trees.
28pub struct Semantics<'db, DB> { 41pub struct Semantics<'db, DB> {
29 pub db: &'db DB, 42 pub db: &'db DB,
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 33c566025..f3f1ed05a 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -20,12 +20,12 @@ use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
20use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment}; 20use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment};
21use ra_syntax::{ 21use ra_syntax::{
22 ast::{self, AstNode}, 22 ast::{self, AstNode},
23 SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, 23 SyntaxNode, SyntaxNodePtr, TextUnit,
24}; 24};
25 25
26use crate::{ 26use crate::{
27 db::HirDatabase, Adt, Const, EnumVariant, Function, Local, MacroDef, ModPath, ModuleDef, Path, 27 db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Function, Local, MacroDef,
28 PathKind, Static, Struct, Trait, Type, TypeAlias, TypeParam, 28 ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias, TypeParam,
29}; 29};
30 30
31/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of 31/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
@@ -40,25 +40,6 @@ pub(crate) struct SourceAnalyzer {
40 scopes: Option<Arc<ExprScopes>>, 40 scopes: Option<Arc<ExprScopes>>,
41} 41}
42 42
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum PathResolution {
45 /// An item
46 Def(crate::ModuleDef),
47 /// A local binding (only value namespace)
48 Local(Local),
49 /// A generic parameter
50 TypeParam(TypeParam),
51 SelfType(crate::ImplDef),
52 Macro(MacroDef),
53 AssocItem(crate::AssocItem),
54}
55
56#[derive(Debug)]
57pub struct ReferenceDescriptor {
58 pub range: TextRange,
59 pub name: String,
60}
61
62impl SourceAnalyzer { 43impl SourceAnalyzer {
63 pub(crate) fn new_for_body( 44 pub(crate) fn new_for_body(
64 db: &impl HirDatabase, 45 db: &impl HirDatabase,