aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/syntax_ptr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src/syntax_ptr.rs')
-rw-r--r--crates/ra_db/src/syntax_ptr.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/ra_db/src/syntax_ptr.rs b/crates/ra_db/src/syntax_ptr.rs
index 5bfcedf2b..be64d417c 100644
--- a/crates/ra_db/src/syntax_ptr.rs
+++ b/crates/ra_db/src/syntax_ptr.rs
@@ -1,4 +1,4 @@
1use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; 1use ra_syntax::{AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, TreePtr};
2 2
3/// A pointer to a syntax node inside a file. 3/// A pointer to a syntax node inside a file.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -8,18 +8,18 @@ pub struct LocalSyntaxPtr {
8} 8}
9 9
10impl LocalSyntaxPtr { 10impl LocalSyntaxPtr {
11 pub fn new(node: SyntaxNodeRef) -> LocalSyntaxPtr { 11 pub fn new(node: &SyntaxNode) -> LocalSyntaxPtr {
12 LocalSyntaxPtr { 12 LocalSyntaxPtr {
13 range: node.range(), 13 range: node.range(),
14 kind: node.kind(), 14 kind: node.kind(),
15 } 15 }
16 } 16 }
17 17
18 pub fn resolve(self, file: &SourceFileNode) -> SyntaxNode { 18 pub fn resolve(self, file: &SourceFile) -> TreePtr<SyntaxNode> {
19 let mut curr = file.syntax(); 19 let mut curr = file.syntax();
20 loop { 20 loop {
21 if curr.range() == self.range && curr.kind() == self.kind { 21 if curr.range() == self.range && curr.kind() == self.kind {
22 return curr.owned(); 22 return curr.to_owned();
23 } 23 }
24 curr = curr 24 curr = curr
25 .children() 25 .children()
@@ -40,7 +40,7 @@ impl LocalSyntaxPtr {
40#[test] 40#[test]
41fn test_local_syntax_ptr() { 41fn test_local_syntax_ptr() {
42 use ra_syntax::{ast, AstNode}; 42 use ra_syntax::{ast, AstNode};
43 let file = SourceFileNode::parse("struct Foo { f: u32, }"); 43 let file = SourceFile::parse("struct Foo { f: u32, }");
44 let field = file 44 let field = file
45 .syntax() 45 .syntax()
46 .descendants() 46 .descendants()
@@ -48,5 +48,5 @@ fn test_local_syntax_ptr() {
48 .unwrap(); 48 .unwrap();
49 let ptr = LocalSyntaxPtr::new(field.syntax()); 49 let ptr = LocalSyntaxPtr::new(field.syntax());
50 let field_syntax = ptr.resolve(&file); 50 let field_syntax = ptr.resolve(&file);
51 assert_eq!(field.syntax(), field_syntax); 51 assert_eq!(field.syntax(), &*field_syntax);
52} 52}