diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-08 09:05:55 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-08 09:05:55 +0000 |
commit | 3f4be819125ce4a22edd86721fa56b5caba99c2e (patch) | |
tree | be93895ddc08c911585d9f7bc64623a3741f32c6 /crates/ra_db/src | |
parent | 4e444d2bc24d16284401444fd2154f63e0f96070 (diff) | |
parent | 122410d7aa34a32d468a3173858cbc8a2bbc68f5 (diff) |
Merge #449
449: switch to new rowan API r=matklad a=matklad
closes https://github.com/rust-analyzer/rust-analyzer/issues/448
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r-- | crates/ra_db/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_db/src/syntax_ptr.rs | 12 |
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; | |||
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 | } |