aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs50
1 files changed, 39 insertions, 11 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 45fa4cd11..624c25c4d 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -1,8 +1,7 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use relative_path::RelativePathBuf;
4use ra_db::{CrateId, SourceRootId, Edition}; 3use ra_db::{CrateId, SourceRootId, Edition};
5use ra_syntax::{ast::self, TreeArc, SyntaxNode}; 4use ra_syntax::{ast::self, TreeArc};
6 5
7use crate::{ 6use crate::{
8 Name, ScopesWithSourceMap, Ty, HirFileId, 7 Name, ScopesWithSourceMap, Ty, HirFileId,
@@ -14,9 +13,11 @@ use crate::{
14 adt::{EnumVariantId, StructFieldId, VariantDef}, 13 adt::{EnumVariantId, StructFieldId, VariantDef},
15 generics::GenericParams, 14 generics::GenericParams,
16 docs::{Documentation, Docs, docs_from_ast}, 15 docs::{Documentation, Docs, docs_from_ast},
17 ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeId}, 16 ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeAliasId},
18 impl_block::ImplBlock, 17 impl_block::ImplBlock,
19 resolve::Resolver, 18 resolve::Resolver,
19 diagnostics::DiagnosticSink,
20 traits::{TraitItem, TraitData},
20}; 21};
21 22
22/// hir::Crate describes a single crate. It's the main interface with which 23/// hir::Crate describes a single crate. It's the main interface with which
@@ -95,11 +96,6 @@ pub enum ModuleSource {
95 Module(TreeArc<ast::Module>), 96 Module(TreeArc<ast::Module>),
96} 97}
97 98
98#[derive(Clone, Debug, Hash, PartialEq, Eq)]
99pub enum Problem {
100 UnresolvedModule { candidate: RelativePathBuf },
101}
102
103impl Module { 99impl Module {
104 /// Name of this module. 100 /// Name of this module.
105 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { 101 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
@@ -171,8 +167,24 @@ impl Module {
171 db.crate_def_map(self.krate)[self.module_id].scope.clone() 167 db.crate_def_map(self.krate)[self.module_id].scope.clone()
172 } 168 }
173 169
174 pub fn problems(&self, db: &impl HirDatabase) -> Vec<(TreeArc<SyntaxNode>, Problem)> { 170 pub fn diagnostics(&self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
175 self.problems_impl(db) 171 db.crate_def_map(self.krate).add_diagnostics(db, self.module_id, sink);
172 for decl in self.declarations(db) {
173 match decl {
174 crate::ModuleDef::Function(f) => f.diagnostics(db, sink),
175 crate::ModuleDef::Module(f) => f.diagnostics(db, sink),
176 _ => (),
177 }
178 }
179
180 for impl_block in self.impl_blocks(db) {
181 for item in impl_block.items(db) {
182 match item {
183 crate::ImplItem::Method(f) => f.diagnostics(db, sink),
184 _ => (),
185 }
186 }
187 }
176 } 188 }
177 189
178 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 190 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
@@ -519,6 +531,10 @@ impl Function {
519 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; 531 let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
520 r 532 r
521 } 533 }
534
535 pub fn diagnostics(&self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
536 self.infer(db).add_diagnostics(db, *self, sink);
537 }
522} 538}
523 539
524impl Docs for Function { 540impl Docs for Function {
@@ -634,6 +650,18 @@ impl Trait {
634 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> { 650 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
635 db.generic_params((*self).into()) 651 db.generic_params((*self).into())
636 } 652 }
653
654 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
655 self.trait_data(db).name().clone()
656 }
657
658 pub fn items(self, db: &impl DefDatabase) -> Vec<TraitItem> {
659 self.trait_data(db).items().to_vec()
660 }
661
662 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> {
663 db.trait_data(self)
664 }
637} 665}
638 666
639impl Docs for Trait { 667impl Docs for Trait {
@@ -644,7 +672,7 @@ impl Docs for Trait {
644 672
645#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 673#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
646pub struct TypeAlias { 674pub struct TypeAlias {
647 pub(crate) id: TypeId, 675 pub(crate) id: TypeAliasId,
648} 676}
649 677
650impl TypeAlias { 678impl TypeAlias {