aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r--crates/ra_db/src/lib.rs8
-rw-r--r--crates/ra_db/src/syntax_ptr.rs12
2 files changed, 10 insertions, 10 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index 7181f2950..3c41ee56d 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -8,7 +8,7 @@ pub mod mock;
8use std::sync::Arc; 8use std::sync::Arc;
9 9
10use ra_editor::LineIndex; 10use ra_editor::LineIndex;
11use ra_syntax::{TextUnit, TextRange, SourceFileNode}; 11use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr};
12 12
13pub use crate::{ 13pub use crate::{
14 cancelation::{Canceled, Cancelable}, 14 cancelation::{Canceled, Cancelable},
@@ -47,7 +47,7 @@ pub trait BaseDatabase: salsa::Database {
47 47
48salsa::query_group! { 48salsa::query_group! {
49 pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase { 49 pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase {
50 fn source_file(file_id: FileId) -> SourceFileNode { 50 fn source_file(file_id: FileId) -> TreePtr<SourceFile> {
51 type SourceFileQuery; 51 type SourceFileQuery;
52 } 52 }
53 fn file_lines(file_id: FileId) -> Arc<LineIndex> { 53 fn file_lines(file_id: FileId) -> Arc<LineIndex> {
@@ -56,9 +56,9 @@ salsa::query_group! {
56 } 56 }
57} 57}
58 58
59fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { 59fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreePtr<SourceFile> {
60 let text = db.file_text(file_id); 60 let text = db.file_text(file_id);
61 SourceFileNode::parse(&*text) 61 SourceFile::parse(&*text)
62} 62}
63fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { 63fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
64 let text = db.file_text(file_id); 64 let text = db.file_text(file_id);
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}