diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 25 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/function.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 23 |
7 files changed, 23 insertions, 67 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 036e284bf..b072a5eba 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -91,7 +91,6 @@ salsa::database_storage! { | |||
91 | fn file_item() for hir::db::FileItemQuery; | 91 | fn file_item() for hir::db::FileItemQuery; |
92 | fn input_module_items() for hir::db::InputModuleItemsQuery; | 92 | fn input_module_items() for hir::db::InputModuleItemsQuery; |
93 | fn item_map() for hir::db::ItemMapQuery; | 93 | fn item_map() for hir::db::ItemMapQuery; |
94 | fn fn_syntax() for hir::db::FnSyntaxQuery; | ||
95 | fn submodules() for hir::db::SubmodulesQuery; | 94 | fn submodules() for hir::db::SubmodulesQuery; |
96 | fn infer() for hir::db::InferQuery; | 95 | fn infer() for hir::db::InferQuery; |
97 | fn type_for_def() for hir::db::TypeForDefQuery; | 96 | fn type_for_def() for hir::db::TypeForDefQuery; |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 0471a2fca..e6663810d 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -7,10 +7,7 @@ use rayon::prelude::*; | |||
7 | use salsa::{Database, ParallelDatabase}; | 7 | use salsa::{Database, ParallelDatabase}; |
8 | 8 | ||
9 | use hir::{ | 9 | use hir::{ |
10 | self, | 10 | self, FnSignatureInfo, Problem, source_binder, |
11 | FnSignatureInfo, | ||
12 | Problem, | ||
13 | source_binder, | ||
14 | }; | 11 | }; |
15 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; | 12 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; |
16 | use ra_editor::{self, FileSymbol, find_node_at_offset, LineIndex, LocalEdit, Severity}; | 13 | use ra_editor::{self, FileSymbol, find_node_at_offset, LineIndex, LocalEdit, Severity}; |
@@ -123,9 +120,6 @@ impl AnalysisHostImpl { | |||
123 | .query(ra_db::SourceFileQuery) | 120 | .query(ra_db::SourceFileQuery) |
124 | .sweep(salsa::SweepStrategy::default().discard_values()); | 121 | .sweep(salsa::SweepStrategy::default().discard_values()); |
125 | self.db | 122 | self.db |
126 | .query(hir::db::FnSyntaxQuery) | ||
127 | .sweep(salsa::SweepStrategy::default().discard_values()); | ||
128 | self.db | ||
129 | .query(hir::db::SourceFileItemsQuery) | 123 | .query(hir::db::SourceFileItemsQuery) |
130 | .sweep(salsa::SweepStrategy::default().discard_values()); | 124 | .sweep(salsa::SweepStrategy::default().discard_values()); |
131 | self.db | 125 | self.db |
@@ -332,16 +326,6 @@ impl AnalysisImpl { | |||
332 | Ok(Some((binding, descr))) | 326 | Ok(Some((binding, descr))) |
333 | } | 327 | } |
334 | } | 328 | } |
335 | |||
336 | pub fn doc_comment_for( | ||
337 | &self, | ||
338 | file_id: FileId, | ||
339 | symbol: FileSymbol, | ||
340 | ) -> Cancelable<Option<String>> { | ||
341 | let file = self.db.source_file(file_id); | ||
342 | |||
343 | Ok(symbol.docs(&file)) | ||
344 | } | ||
345 | pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { | 329 | pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { |
346 | let file = self.db.source_file(file_id); | 330 | let file = self.db.source_file(file_id); |
347 | let result = match (symbol.description(&file), symbol.docs(&file)) { | 331 | let result = match (symbol.description(&file), symbol.docs(&file)) { |
@@ -507,12 +491,7 @@ impl AnalysisImpl { | |||
507 | let file = self.db.source_file(file_id); | 491 | let file = self.db.source_file(file_id); |
508 | let syntax = file.syntax(); | 492 | let syntax = file.syntax(); |
509 | let node = find_covering_node(syntax, range); | 493 | let node = find_covering_node(syntax, range); |
510 | let parent_fn = node.ancestors().filter_map(FnDef::cast).next(); | 494 | let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast)); |
511 | let parent_fn = if let Some(p) = parent_fn { | ||
512 | p | ||
513 | } else { | ||
514 | return Ok(None); | ||
515 | }; | ||
516 | let function = ctry!(source_binder::function_from_source( | 495 | let function = ctry!(source_binder::function_from_source( |
517 | &*self.db, file_id, parent_fn | 496 | &*self.db, file_id, parent_fn |
518 | )?); | 497 | )?); |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 476d1b438..65c3eb3ec 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -323,13 +323,6 @@ impl Analysis { | |||
323 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 323 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
324 | self.imp.find_all_refs(position) | 324 | self.imp.find_all_refs(position) |
325 | } | 325 | } |
326 | pub fn doc_comment_for( | ||
327 | &self, | ||
328 | file_id: FileId, | ||
329 | symbol: FileSymbol, | ||
330 | ) -> Cancelable<Option<String>> { | ||
331 | self.imp.doc_comment_for(file_id, symbol) | ||
332 | } | ||
333 | pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { | 326 | pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { |
334 | self.imp.doc_text_for(file_id, symbol) | 327 | self.imp.doc_text_for(file_id, symbol) |
335 | } | 328 | } |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index e7f9afa77..ba43a4502 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -3,7 +3,6 @@ use std::sync::Arc; | |||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | SmolStr, | 4 | SmolStr, |
5 | SyntaxNode, | 5 | SyntaxNode, |
6 | ast::FnDefNode, | ||
7 | }; | 6 | }; |
8 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable}; | 7 | use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable}; |
9 | 8 | ||
@@ -12,7 +11,6 @@ use crate::{ | |||
12 | SourceFileItems, SourceItemId, | 11 | SourceFileItems, SourceItemId, |
13 | query_definitions, | 12 | query_definitions, |
14 | FnScopes, | 13 | FnScopes, |
15 | function::FnId, | ||
16 | module::{ModuleId, ModuleTree, ModuleSource, | 14 | module::{ModuleId, ModuleTree, ModuleSource, |
17 | nameres::{ItemMap, InputModuleItems}}, | 15 | nameres::{ItemMap, InputModuleItems}}, |
18 | ty::{InferenceResult, Ty}, | 16 | ty::{InferenceResult, Ty}, |
@@ -24,14 +22,10 @@ salsa::query_group! { | |||
24 | pub trait HirDatabase: SyntaxDatabase | 22 | pub trait HirDatabase: SyntaxDatabase |
25 | + AsRef<LocationIntener<DefLoc, DefId>> | 23 | + AsRef<LocationIntener<DefLoc, DefId>> |
26 | { | 24 | { |
27 | fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> { | 25 | fn fn_scopes(def_id: DefId) -> Arc<FnScopes> { |
28 | type FnScopesQuery; | 26 | type FnScopesQuery; |
29 | use fn query_definitions::fn_scopes; | 27 | use fn query_definitions::fn_scopes; |
30 | } | 28 | } |
31 | fn fn_syntax(fn_id: FnId) -> FnDefNode { | ||
32 | type FnSyntaxQuery; | ||
33 | use fn query_definitions::fn_syntax; | ||
34 | } | ||
35 | 29 | ||
36 | fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> { | 30 | fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> { |
37 | type StructDataQuery; | 31 | type StructDataQuery; |
@@ -43,7 +37,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
43 | use fn query_definitions::enum_data; | 37 | use fn query_definitions::enum_data; |
44 | } | 38 | } |
45 | 39 | ||
46 | fn infer(fn_id: FnId) -> Cancelable<Arc<InferenceResult>> { | 40 | fn infer(def_id: DefId) -> Cancelable<Arc<InferenceResult>> { |
47 | type InferQuery; | 41 | type InferQuery; |
48 | use fn query_definitions::infer; | 42 | use fn query_definitions::infer; |
49 | } | 43 | } |
diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs index d4159cee2..5a44132fc 100644 --- a/crates/ra_hir/src/function.rs +++ b/crates/ra_hir/src/function.rs | |||
@@ -11,43 +11,42 @@ use ra_syntax::{ | |||
11 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, | 11 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | use crate::{ DefId, HirDatabase, ty::InferenceResult, Module }; | 14 | use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module}; |
15 | 15 | ||
16 | pub use self::scope::FnScopes; | 16 | pub use self::scope::FnScopes; |
17 | 17 | ||
18 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
19 | pub struct FnId(pub(crate) DefId); | ||
20 | |||
21 | #[derive(Debug)] | 18 | #[derive(Debug)] |
22 | pub struct Function { | 19 | pub struct Function { |
23 | pub(crate) fn_id: FnId, | 20 | def_id: DefId, |
24 | } | 21 | } |
25 | 22 | ||
26 | impl Function { | 23 | impl Function { |
27 | pub(crate) fn new(def_id: DefId) -> Function { | 24 | pub(crate) fn new(def_id: DefId) -> Function { |
28 | let fn_id = FnId(def_id); | 25 | Function { def_id } |
29 | Function { fn_id } | ||
30 | } | 26 | } |
31 | 27 | ||
32 | pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { | 28 | pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { |
33 | db.fn_syntax(self.fn_id) | 29 | let def_loc = self.def_id.loc(db); |
30 | assert!(def_loc.kind == DefKind::Function); | ||
31 | let syntax = db.file_item(def_loc.source_item_id); | ||
32 | ast::FnDef::cast(syntax.borrowed()).unwrap().owned() | ||
34 | } | 33 | } |
35 | 34 | ||
36 | pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> { | 35 | pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> { |
37 | db.fn_scopes(self.fn_id) | 36 | db.fn_scopes(self.def_id) |
38 | } | 37 | } |
39 | 38 | ||
40 | pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { | 39 | pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { |
41 | let syntax = db.fn_syntax(self.fn_id); | 40 | let syntax = self.syntax(db); |
42 | FnSignatureInfo::new(syntax.borrowed()) | 41 | FnSignatureInfo::new(syntax.borrowed()) |
43 | } | 42 | } |
44 | 43 | ||
45 | pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { | 44 | pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { |
46 | db.infer(self.fn_id) | 45 | db.infer(self.def_id) |
47 | } | 46 | } |
48 | 47 | ||
49 | pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> { | 48 | pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> { |
50 | self.fn_id.0.module(db) | 49 | self.def_id.module(db) |
51 | } | 50 | } |
52 | } | 51 | } |
53 | 52 | ||
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index f6882cb77..a2507c9b5 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -189,7 +189,6 @@ salsa::database_storage! { | |||
189 | fn file_item() for db::FileItemQuery; | 189 | fn file_item() for db::FileItemQuery; |
190 | fn input_module_items() for db::InputModuleItemsQuery; | 190 | fn input_module_items() for db::InputModuleItemsQuery; |
191 | fn item_map() for db::ItemMapQuery; | 191 | fn item_map() for db::ItemMapQuery; |
192 | fn fn_syntax() for db::FnSyntaxQuery; | ||
193 | fn submodules() for db::SubmodulesQuery; | 192 | fn submodules() for db::SubmodulesQuery; |
194 | fn infer() for db::InferQuery; | 193 | fn infer() for db::InferQuery; |
195 | fn type_for_def() for db::TypeForDefQuery; | 194 | fn type_for_def() for db::TypeForDefQuery; |
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index e6241342a..56e3f7e9d 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -5,15 +5,15 @@ use std::{ | |||
5 | 5 | ||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | AstNode, SyntaxNode, SmolStr, | 8 | AstNode, SyntaxNode, SmolStr, |
9 | ast::{self, FnDef, FnDefNode, NameOwner, ModuleItemOwner} | 9 | ast::{self, NameOwner, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, FileId, Cancelable,}; | 11 | use ra_db::{SourceRootId, FileId, Cancelable,}; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, | 14 | SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, |
15 | db::HirDatabase, | 15 | db::HirDatabase, |
16 | function::{FnScopes, FnId}, | 16 | function::FnScopes, |
17 | module::{ | 17 | module::{ |
18 | ModuleSource, ModuleSourceNode, ModuleId, | 18 | ModuleSource, ModuleSourceNode, ModuleId, |
19 | imp::Submodule, | 19 | imp::Submodule, |
@@ -23,22 +23,15 @@ use crate::{ | |||
23 | adt::{StructData, EnumData}, | 23 | adt::{StructData, EnumData}, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | /// Resolve `FnId` to the corresponding `SyntaxNode` | 26 | pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> { |
27 | pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { | 27 | let function = Function::new(def_id); |
28 | let def_loc = fn_id.0.loc(db); | 28 | let syntax = function.syntax(db); |
29 | assert!(def_loc.kind == DefKind::Function); | ||
30 | let syntax = db.file_item(def_loc.source_item_id); | ||
31 | FnDef::cast(syntax.borrowed()).unwrap().owned() | ||
32 | } | ||
33 | |||
34 | pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> { | ||
35 | let syntax = db.fn_syntax(fn_id); | ||
36 | let res = FnScopes::new(syntax.borrowed()); | 29 | let res = FnScopes::new(syntax.borrowed()); |
37 | Arc::new(res) | 30 | Arc::new(res) |
38 | } | 31 | } |
39 | 32 | ||
40 | pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable<Arc<InferenceResult>> { | 33 | pub(super) fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { |
41 | let function = Function { fn_id }; | 34 | let function = Function::new(def_id); |
42 | ty::infer(db, function).map(Arc::new) | 35 | ty::infer(db, function).map(Arc::new) |
43 | } | 36 | } |
44 | 37 | ||