diff options
author | Aleksey Kladov <[email protected]> | 2019-01-08 08:28:42 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 08:28:42 +0000 |
commit | da0b348ae9f629c5cbe4a836a90ed85e36ca18e5 (patch) | |
tree | 614fd83f614632e3c87130117421708a7a028c13 /crates/ra_hir/src/ids.rs | |
parent | d6020f516f2826dac7188171241e9a72d6248cf8 (diff) |
migrate ra_hir to rowan 2.0
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index c7391ee05..730a3e542 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; | 1 | use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; |
2 | use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; | 2 | use ra_syntax::{TreePtr, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; |
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | 4 | ||
5 | use crate::{HirDatabase, PerNs, ModuleId, Def, Function, Struct, Enum, ImplBlock, Crate}; | 5 | use crate::{HirDatabase, PerNs, ModuleId, Def, Function, Struct, Enum, ImplBlock, Crate}; |
@@ -55,7 +55,10 @@ impl HirFileId { | |||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | pub(crate) fn hir_source_file(db: &impl HirDatabase, file_id: HirFileId) -> SourceFileNode { | 58 | pub(crate) fn hir_source_file( |
59 | db: &impl HirDatabase, | ||
60 | file_id: HirFileId, | ||
61 | ) -> TreePtr<SourceFile> { | ||
59 | match file_id.0 { | 62 | match file_id.0 { |
60 | HirFileIdRepr::File(file_id) => db.source_file(file_id), | 63 | HirFileIdRepr::File(file_id) => db.source_file(file_id), |
61 | HirFileIdRepr::Macro(m) => { | 64 | HirFileIdRepr::Macro(m) => { |
@@ -63,7 +66,7 @@ impl HirFileId { | |||
63 | return exp.file(); | 66 | return exp.file(); |
64 | } | 67 | } |
65 | // returning an empty string looks fishy... | 68 | // returning an empty string looks fishy... |
66 | SourceFileNode::parse("") | 69 | SourceFile::parse("") |
67 | } | 70 | } |
68 | } | 71 | } |
69 | } | 72 | } |
@@ -233,11 +236,11 @@ pub struct SourceItemId { | |||
233 | #[derive(Debug, PartialEq, Eq)] | 236 | #[derive(Debug, PartialEq, Eq)] |
234 | pub struct SourceFileItems { | 237 | pub struct SourceFileItems { |
235 | file_id: HirFileId, | 238 | file_id: HirFileId, |
236 | arena: Arena<SourceFileItemId, SyntaxNode>, | 239 | arena: Arena<SourceFileItemId, TreePtr<SyntaxNode>>, |
237 | } | 240 | } |
238 | 241 | ||
239 | impl SourceFileItems { | 242 | impl SourceFileItems { |
240 | pub(crate) fn new(file_id: HirFileId, source_file: SourceFile) -> SourceFileItems { | 243 | pub(crate) fn new(file_id: HirFileId, source_file: &SourceFile) -> SourceFileItems { |
241 | let mut res = SourceFileItems { | 244 | let mut res = SourceFileItems { |
242 | file_id, | 245 | file_id, |
243 | arena: Arena::default(), | 246 | arena: Arena::default(), |
@@ -246,20 +249,20 @@ impl SourceFileItems { | |||
246 | res | 249 | res |
247 | } | 250 | } |
248 | 251 | ||
249 | fn init(&mut self, source_file: SourceFile) { | 252 | fn init(&mut self, source_file: &SourceFile) { |
250 | source_file.syntax().descendants().for_each(|it| { | 253 | source_file.syntax().descendants().for_each(|it| { |
251 | if let Some(module_item) = ast::ModuleItem::cast(it) { | 254 | if let Some(module_item) = ast::ModuleItem::cast(it) { |
252 | self.alloc(module_item.syntax().owned()); | 255 | self.alloc(module_item.syntax().to_owned()); |
253 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { | 256 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { |
254 | self.alloc(macro_call.syntax().owned()); | 257 | self.alloc(macro_call.syntax().to_owned()); |
255 | } | 258 | } |
256 | }); | 259 | }); |
257 | } | 260 | } |
258 | 261 | ||
259 | fn alloc(&mut self, item: SyntaxNode) -> SourceFileItemId { | 262 | fn alloc(&mut self, item: TreePtr<SyntaxNode>) -> SourceFileItemId { |
260 | self.arena.alloc(item) | 263 | self.arena.alloc(item) |
261 | } | 264 | } |
262 | pub(crate) fn id_of(&self, file_id: HirFileId, item: SyntaxNodeRef) -> SourceFileItemId { | 265 | pub(crate) fn id_of(&self, file_id: HirFileId, item: &SyntaxNode) -> SourceFileItemId { |
263 | assert_eq!( | 266 | assert_eq!( |
264 | self.file_id, file_id, | 267 | self.file_id, file_id, |
265 | "SourceFileItems: wrong file, expected {:?}, got {:?}", | 268 | "SourceFileItems: wrong file, expected {:?}, got {:?}", |
@@ -267,8 +270,8 @@ impl SourceFileItems { | |||
267 | ); | 270 | ); |
268 | self.id_of_unchecked(item) | 271 | self.id_of_unchecked(item) |
269 | } | 272 | } |
270 | pub(crate) fn id_of_unchecked(&self, item: SyntaxNodeRef) -> SourceFileItemId { | 273 | pub(crate) fn id_of_unchecked(&self, item: &SyntaxNode) -> SourceFileItemId { |
271 | if let Some((id, _)) = self.arena.iter().find(|(_id, i)| i.borrowed() == item) { | 274 | if let Some((id, _)) = self.arena.iter().find(|(_id, i)| *i == item) { |
272 | return id; | 275 | return id; |
273 | } | 276 | } |
274 | // This should not happen. Let's try to give a sensible diagnostics. | 277 | // This should not happen. Let's try to give a sensible diagnostics. |