aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-07 14:00:39 +0000
committerAleksey Kladov <[email protected]>2019-01-08 08:20:15 +0000
commitfe53b282500f32c2d0cc1dfee1d7ccddfedac583 (patch)
tree826967cd421105444382e408c792f8c32504f600
parentb88775af7fdfb06df922325ab48237592d5afecb (diff)
migrate ra_db to new rowan
-rw-r--r--crates/ra_db/src/lib.rs8
-rw-r--r--crates/ra_db/src/syntax_ptr.rs12
-rw-r--r--crates/ra_syntax/src/yellow.rs11
3 files changed, 20 insertions, 11 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}
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs
index 38e680a9c..f31efa174 100644
--- a/crates/ra_syntax/src/yellow.rs
+++ b/crates/ra_syntax/src/yellow.rs
@@ -20,7 +20,7 @@ impl Types for RaTypes {
20 20
21pub type GreenNode = rowan::GreenNode<RaTypes>; 21pub type GreenNode = rowan::GreenNode<RaTypes>;
22 22
23#[derive(Clone, PartialEq, Eq, Hash)] 23#[derive(PartialEq, Eq, Hash)]
24pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( 24pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>(
25 pub(crate) rowan::TreePtr<RaTypes, T>, 25 pub(crate) rowan::TreePtr<RaTypes, T>,
26); 26);
@@ -47,6 +47,15 @@ where
47 } 47 }
48} 48}
49 49
50impl<T> Clone for TreePtr<T>
51where
52 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
53{
54 fn clone(&self) -> TreePtr<T> {
55 TreePtr(self.0.clone())
56 }
57}
58
50impl<T> fmt::Debug for TreePtr<T> 59impl<T> fmt::Debug for TreePtr<T>
51where 60where
52 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, 61 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,