aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/code_model.rs7
-rw-r--r--crates/hir/src/lib.rs8
-rw-r--r--crates/hir/src/semantics.rs16
3 files changed, 26 insertions, 5 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 8ffb9e99b..5dc3ae3b1 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -883,6 +883,13 @@ where
883} 883}
884 884
885impl AssocItem { 885impl AssocItem {
886 pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
887 match self {
888 AssocItem::Function(it) => Some(it.name(db)),
889 AssocItem::Const(it) => it.name(db),
890 AssocItem::TypeAlias(it) => Some(it.name(db)),
891 }
892 }
886 pub fn module(self, db: &dyn HirDatabase) -> Module { 893 pub fn module(self, db: &dyn HirDatabase) -> Module {
887 match self { 894 match self {
888 AssocItem::Function(f) => f.module(db), 895 AssocItem::Function(f) => f.module(db),
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 24a0f6b4b..4ae2bd085 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -52,8 +52,12 @@ pub use hir_def::{
52 type_ref::{Mutability, TypeRef}, 52 type_ref::{Mutability, TypeRef},
53}; 53};
54pub use hir_expand::{ 54pub use hir_expand::{
55 hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, 55 name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, /* FIXME */ MacroDefId,
56 MacroDefId, /* FIXME */
57 MacroFile, Origin, 56 MacroFile, Origin,
58}; 57};
59pub use hir_ty::display::HirDisplay; 58pub use hir_ty::display::HirDisplay;
59
60// These are negative re-exports: pub using these names is forbidden, they
61// should remain private to hir internals.
62#[allow(unused)]
63use hir_expand::hygiene::Hygiene;
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 1467d825d..d8beac98a 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -502,18 +502,19 @@ impl<'db> SemanticsImpl<'db> {
502 fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> { 502 fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
503 let node = self.find_file(node.clone()); 503 let node = self.find_file(node.clone());
504 let resolver = self.analyze2(node.as_ref(), None).resolver; 504 let resolver = self.analyze2(node.as_ref(), None).resolver;
505 SemanticsScope { db: self.db, resolver } 505 SemanticsScope { db: self.db, file_id: node.file_id, resolver }
506 } 506 }
507 507
508 fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> { 508 fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
509 let node = self.find_file(node.clone()); 509 let node = self.find_file(node.clone());
510 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver; 510 let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
511 SemanticsScope { db: self.db, resolver } 511 SemanticsScope { db: self.db, file_id: node.file_id, resolver }
512 } 512 }
513 513
514 fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> { 514 fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
515 let file_id = self.db.lookup_intern_trait(def.id).id.file_id;
515 let resolver = def.id.resolver(self.db.upcast()); 516 let resolver = def.id.resolver(self.db.upcast());
516 SemanticsScope { db: self.db, resolver } 517 SemanticsScope { db: self.db, file_id, resolver }
517 } 518 }
518 519
519 fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer { 520 fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer {
@@ -709,6 +710,7 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
709#[derive(Debug)] 710#[derive(Debug)]
710pub struct SemanticsScope<'a> { 711pub struct SemanticsScope<'a> {
711 pub db: &'a dyn HirDatabase, 712 pub db: &'a dyn HirDatabase,
713 file_id: HirFileId,
712 resolver: Resolver, 714 resolver: Resolver,
713} 715}
714 716
@@ -752,6 +754,14 @@ impl<'a> SemanticsScope<'a> {
752 }) 754 })
753 } 755 }
754 756
757 /// Resolve a path as-if it was written at the given scope. This is
758 /// necessary a heuristic, as it doesn't take hygiene into account.
759 pub fn resolve_hypothetical(&self, path: &ast::Path) -> Option<PathResolution> {
760 let hygiene = Hygiene::new(self.db.upcast(), self.file_id);
761 let path = Path::from_src(path.clone(), &hygiene)?;
762 self.resolve_hir_path(&path)
763 }
764
755 pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> { 765 pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> {
756 resolve_hir_path(self.db, &self.resolver, path) 766 resolve_hir_path(self.db, &self.resolver, path)
757 } 767 }