diff options
author | Aleksey Kladov <[email protected]> | 2019-01-07 14:00:39 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 08:20:15 +0000 |
commit | fe53b282500f32c2d0cc1dfee1d7ccddfedac583 (patch) | |
tree | 826967cd421105444382e408c792f8c32504f600 /crates | |
parent | b88775af7fdfb06df922325ab48237592d5afecb (diff) |
migrate ra_db to new rowan
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_db/src/syntax_ptr.rs | 12 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 11 |
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; | |||
8 | use std::sync::Arc; | 8 | use std::sync::Arc; |
9 | 9 | ||
10 | use ra_editor::LineIndex; | 10 | use ra_editor::LineIndex; |
11 | use ra_syntax::{TextUnit, TextRange, SourceFileNode}; | 11 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; |
12 | 12 | ||
13 | pub use crate::{ | 13 | pub use crate::{ |
14 | cancelation::{Canceled, Cancelable}, | 14 | cancelation::{Canceled, Cancelable}, |
@@ -47,7 +47,7 @@ pub trait BaseDatabase: salsa::Database { | |||
47 | 47 | ||
48 | salsa::query_group! { | 48 | salsa::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 | ||
59 | fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { | 59 | fn 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 | } |
63 | fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { | 63 | fn 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 @@ | |||
1 | use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; | 1 | use 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 | ||
10 | impl LocalSyntaxPtr { | 10 | impl 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] |
41 | fn test_local_syntax_ptr() { | 41 | fn 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 | ||
21 | pub type GreenNode = rowan::GreenNode<RaTypes>; | 21 | pub type GreenNode = rowan::GreenNode<RaTypes>; |
22 | 22 | ||
23 | #[derive(Clone, PartialEq, Eq, Hash)] | 23 | #[derive(PartialEq, Eq, Hash)] |
24 | pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( | 24 | pub 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 | ||
50 | impl<T> Clone for TreePtr<T> | ||
51 | where | ||
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
53 | { | ||
54 | fn clone(&self) -> TreePtr<T> { | ||
55 | TreePtr(self.0.clone()) | ||
56 | } | ||
57 | } | ||
58 | |||
50 | impl<T> fmt::Debug for TreePtr<T> | 59 | impl<T> fmt::Debug for TreePtr<T> |
51 | where | 60 | where |
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 61 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, |