aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/hir/db.rs4
-rw-r--r--crates/ra_analysis/src/hir/mod.rs7
-rw-r--r--crates/ra_analysis/src/hir/module/nameres.rs14
-rw-r--r--crates/ra_analysis/src/hir/query_definitions.rs10
-rw-r--r--crates/ra_analysis/src/loc2id.rs6
5 files changed, 24 insertions, 17 deletions
diff --git a/crates/ra_analysis/src/hir/db.rs b/crates/ra_analysis/src/hir/db.rs
index e74fcc8ad..0998295f5 100644
--- a/crates/ra_analysis/src/hir/db.rs
+++ b/crates/ra_analysis/src/hir/db.rs
@@ -8,7 +8,7 @@ use ra_syntax::{
8use crate::{ 8use crate::{
9 FileId, 9 FileId,
10 db::SyntaxDatabase, 10 db::SyntaxDatabase,
11 hir::{SourceFileItems, SourceFileItemId}, 11 hir::{SourceFileItems, SourceItemId},
12 hir::query_definitions, 12 hir::query_definitions,
13 hir::function::{FnId, FnScopes}, 13 hir::function::{FnId, FnScopes},
14 hir::module::{ 14 hir::module::{
@@ -39,7 +39,7 @@ pub(crate) trait HirDatabase: SyntaxDatabase {
39 use fn query_definitions::file_items; 39 use fn query_definitions::file_items;
40 } 40 }
41 41
42 fn file_item(file_id: FileId, file_item_id: SourceFileItemId) -> SyntaxNode { 42 fn file_item(source_item_id: SourceItemId) -> SyntaxNode {
43 type FileItemQuery; 43 type FileItemQuery;
44 storage dependencies; 44 storage dependencies;
45 use fn query_definitions::file_item; 45 use fn query_definitions::file_item;
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index aa416df20..9527cc33f 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -16,6 +16,7 @@ use std::ops::Index;
16use ra_syntax::{SyntaxNodeRef, SyntaxNode}; 16use ra_syntax::{SyntaxNodeRef, SyntaxNode};
17 17
18use crate::{ 18use crate::{
19 FileId,
19 hir::db::HirDatabase, 20 hir::db::HirDatabase,
20 loc2id::{DefId, DefLoc}, 21 loc2id::{DefId, DefLoc},
21 Cancelable, 22 Cancelable,
@@ -53,6 +54,12 @@ impl DefId {
53/// it's OK to use it as a salsa key/value. 54/// it's OK to use it as a salsa key/value.
54pub(crate) type SourceFileItemId = Id<SyntaxNode>; 55pub(crate) type SourceFileItemId = Id<SyntaxNode>;
55 56
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
58pub(crate) struct SourceItemId {
59 file_id: FileId,
60 item_id: SourceFileItemId,
61}
62
56/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back. 63/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back.
57#[derive(Debug, PartialEq, Eq, Default)] 64#[derive(Debug, PartialEq, Eq, Default)]
58pub(crate) struct SourceFileItems { 65pub(crate) struct SourceFileItems {
diff --git a/crates/ra_analysis/src/hir/module/nameres.rs b/crates/ra_analysis/src/hir/module/nameres.rs
index 9dc54f6c0..f22832eda 100644
--- a/crates/ra_analysis/src/hir/module/nameres.rs
+++ b/crates/ra_analysis/src/hir/module/nameres.rs
@@ -30,7 +30,7 @@ use crate::{
30 Cancelable, FileId, 30 Cancelable, FileId,
31 loc2id::{DefId, DefLoc}, 31 loc2id::{DefId, DefLoc},
32 hir::{ 32 hir::{
33 SourceFileItemId, SourceFileItems, 33 SourceItemId, SourceFileItemId, SourceFileItems,
34 Path, PathKind, 34 Path, PathKind,
35 HirDatabase, 35 HirDatabase,
36 module::{ModuleId, ModuleTree}, 36 module::{ModuleId, ModuleTree},
@@ -99,7 +99,11 @@ pub(crate) struct NamedImport {
99 99
100impl NamedImport { 100impl NamedImport {
101 pub(crate) fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange { 101 pub(crate) fn range(&self, db: &impl HirDatabase, file_id: FileId) -> TextRange {
102 let syntax = db.file_item(file_id, self.file_item_id); 102 let source_item_id = SourceItemId {
103 file_id,
104 item_id: self.file_item_id,
105 };
106 let syntax = db.file_item(source_item_id);
103 let offset = syntax.borrowed().range().start(); 107 let offset = syntax.borrowed().range().start();
104 self.relative_range + offset 108 self.relative_range + offset
105 } 109 }
@@ -247,8 +251,10 @@ where
247 continue; 251 continue;
248 } 252 }
249 let def_loc = DefLoc::Item { 253 let def_loc = DefLoc::Item {
250 file_id, 254 source_item_id: SourceItemId {
251 id: item.id, 255 file_id,
256 item_id: item.id,
257 },
252 }; 258 };
253 let def_id = self.db.id_maps().def_id(def_loc); 259 let def_id = self.db.id_maps().def_id(def_loc);
254 let resolution = Resolution { 260 let resolution = Resolution {
diff --git a/crates/ra_analysis/src/hir/query_definitions.rs b/crates/ra_analysis/src/hir/query_definitions.rs
index 53926cf16..ae292e964 100644
--- a/crates/ra_analysis/src/hir/query_definitions.rs
+++ b/crates/ra_analysis/src/hir/query_definitions.rs
@@ -12,7 +12,7 @@ use ra_syntax::{
12use crate::{ 12use crate::{
13 FileId, Cancelable, 13 FileId, Cancelable,
14 hir::{ 14 hir::{
15 SourceFileItems, SourceFileItemId, 15 SourceFileItems, SourceItemId,
16 db::HirDatabase, 16 db::HirDatabase,
17 function::{FnId, FnScopes}, 17 function::{FnId, FnScopes},
18 module::{ 18 module::{
@@ -52,12 +52,8 @@ pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFi
52 Arc::new(res) 52 Arc::new(res)
53} 53}
54 54
55pub(super) fn file_item( 55pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) -> SyntaxNode {
56 db: &impl HirDatabase, 56 db.file_items(source_item_id.file_id)[source_item_id.item_id].clone()
57 file_id: FileId,
58 file_item_id: SourceFileItemId,
59) -> SyntaxNode {
60 db.file_items(file_id)[file_item_id].clone()
61} 57}
62 58
63pub(crate) fn submodules( 59pub(crate) fn submodules(
diff --git a/crates/ra_analysis/src/loc2id.rs b/crates/ra_analysis/src/loc2id.rs
index 49af19c75..5b2c0f615 100644
--- a/crates/ra_analysis/src/loc2id.rs
+++ b/crates/ra_analysis/src/loc2id.rs
@@ -8,8 +8,7 @@ use std::{
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9 9
10use crate::{ 10use crate::{
11 FileId, 11 hir::{SourceItemId, ModuleId},
12 hir::{SourceFileItemId, ModuleId},
13 syntax_ptr::SyntaxPtr, 12 syntax_ptr::SyntaxPtr,
14 input::SourceRootId, 13 input::SourceRootId,
15}; 14};
@@ -103,8 +102,7 @@ pub(crate) enum DefLoc {
103 source_root: SourceRootId, 102 source_root: SourceRootId,
104 }, 103 },
105 Item { 104 Item {
106 file_id: FileId, 105 source_item_id: SourceItemId,
107 id: SourceFileItemId,
108 }, 106 },
109} 107}
110 108