From 16f67ee384d5b49358de167069535af727b87dba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 01:11:29 +0300 Subject: move resolve_local to Scopes --- crates/ra_analysis/src/syntax_ptr.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'crates/ra_analysis/src/syntax_ptr.rs') diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index e45934ce0..3168e82a7 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -56,11 +56,8 @@ impl LocalSyntaxPtr { } } - pub(crate) fn into_global(self, file_id: FileId) -> SyntaxPtr { - SyntaxPtr { - file_id, - local: self, - } + pub(crate) fn range(self) -> TextRange { + self.range } } -- cgit v1.2.3 From 3922503205e2798e21273a22112f584951f25623 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 02:09:09 +0300 Subject: ItemId based module source --- crates/ra_analysis/src/syntax_ptr.rs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'crates/ra_analysis/src/syntax_ptr.rs') diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index 3168e82a7..ca8efc9b2 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -22,10 +22,6 @@ impl SyntaxPtr { let local = LocalSyntaxPtr::new(node); SyntaxPtr { file_id, local } } - - pub(crate) fn file_id(self) -> FileId { - self.file_id - } } /// A pionter to a syntax node inside a file. -- cgit v1.2.3 From c2abd17f57fa14960e8a175bdabe49eb365a585f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 02:13:52 +0300 Subject: Use ItemPtr for id --- crates/ra_analysis/src/syntax_ptr.rs | 7 ------- 1 file changed, 7 deletions(-) (limited to 'crates/ra_analysis/src/syntax_ptr.rs') diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index ca8efc9b2..7bbf1fc33 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -17,13 +17,6 @@ pub(crate) struct SyntaxPtr { local: LocalSyntaxPtr, } -impl SyntaxPtr { - pub(crate) fn new(file_id: FileId, node: SyntaxNodeRef) -> SyntaxPtr { - let local = LocalSyntaxPtr::new(node); - SyntaxPtr { file_id, local } - } -} - /// A pionter to a syntax node inside a file. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct LocalSyntaxPtr { -- cgit v1.2.3 From 201aa7ea2ae75f9599dc74ad2f4d3f41c1540e73 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 02:15:21 +0300 Subject: remove syntax ptr --- crates/ra_analysis/src/syntax_ptr.rs | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'crates/ra_analysis/src/syntax_ptr.rs') diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs index 7bbf1fc33..f4b05fc19 100644 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ b/crates/ra_analysis/src/syntax_ptr.rs @@ -1,22 +1,5 @@ use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; -use crate::db::SyntaxDatabase; -use crate::FileId; - -pub(crate) fn resolve_syntax_ptr(db: &impl SyntaxDatabase, ptr: SyntaxPtr) -> SyntaxNode { - let syntax = db.file_syntax(ptr.file_id); - ptr.local.resolve(&syntax) -} - -/// SyntaxPtr is a cheap `Copy` id which identifies a particular syntax node, -/// without retaining syntax tree in memory. You need to explicitly `resolve` -/// `SyntaxPtr` to get a `SyntaxNode` -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct SyntaxPtr { - file_id: FileId, - local: LocalSyntaxPtr, -} - /// A pionter to a syntax node inside a file. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct LocalSyntaxPtr { -- cgit v1.2.3 From 11168c464cd962af3336a2cc68295496066edd6c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 03:25:20 +0300 Subject: move db basics to ra_db This should allow to move hir to a separate crate --- crates/ra_analysis/src/syntax_ptr.rs | 48 ------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 crates/ra_analysis/src/syntax_ptr.rs (limited to 'crates/ra_analysis/src/syntax_ptr.rs') diff --git a/crates/ra_analysis/src/syntax_ptr.rs b/crates/ra_analysis/src/syntax_ptr.rs deleted file mode 100644 index f4b05fc19..000000000 --- a/crates/ra_analysis/src/syntax_ptr.rs +++ /dev/null @@ -1,48 +0,0 @@ -use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; - -/// A pionter to a syntax node inside a file. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct LocalSyntaxPtr { - range: TextRange, - kind: SyntaxKind, -} - -impl LocalSyntaxPtr { - pub(crate) fn new(node: SyntaxNodeRef) -> LocalSyntaxPtr { - LocalSyntaxPtr { - range: node.range(), - kind: node.kind(), - } - } - - pub(crate) fn resolve(self, file: &SourceFileNode) -> SyntaxNode { - let mut curr = file.syntax(); - loop { - if curr.range() == self.range && curr.kind() == self.kind { - return curr.owned(); - } - curr = curr - .children() - .find(|it| self.range.is_subrange(&it.range())) - .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) - } - } - - pub(crate) fn range(self) -> TextRange { - self.range - } -} - -#[test] -fn test_local_syntax_ptr() { - use ra_syntax::{ast, AstNode}; - let file = SourceFileNode::parse("struct Foo { f: u32, }"); - let field = file - .syntax() - .descendants() - .find_map(ast::NamedFieldDef::cast) - .unwrap(); - let ptr = LocalSyntaxPtr::new(field.syntax()); - let field_syntax = ptr.resolve(&file); - assert_eq!(field.syntax(), field_syntax); -} -- cgit v1.2.3