From fe53b282500f32c2d0cc1dfee1d7ccddfedac583 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 7 Jan 2019 17:00:39 +0300 Subject: migrate ra_db to new rowan --- crates/ra_db/src/lib.rs | 8 ++++---- crates/ra_db/src/syntax_ptr.rs | 12 ++++++------ 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; use std::sync::Arc; use ra_editor::LineIndex; -use ra_syntax::{TextUnit, TextRange, SourceFileNode}; +use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; pub use crate::{ cancelation::{Canceled, Cancelable}, @@ -47,7 +47,7 @@ pub trait BaseDatabase: salsa::Database { salsa::query_group! { pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase { - fn source_file(file_id: FileId) -> SourceFileNode { + fn source_file(file_id: FileId) -> TreePtr { type SourceFileQuery; } fn file_lines(file_id: FileId) -> Arc { @@ -56,9 +56,9 @@ salsa::query_group! { } } -fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { +fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreePtr { let text = db.file_text(file_id); - SourceFileNode::parse(&*text) + SourceFile::parse(&*text) } fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc { 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 @@ -use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange}; +use ra_syntax::{AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, TreePtr}; /// A pointer to a syntax node inside a file. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -8,18 +8,18 @@ pub struct LocalSyntaxPtr { } impl LocalSyntaxPtr { - pub fn new(node: SyntaxNodeRef) -> LocalSyntaxPtr { + pub fn new(node: &SyntaxNode) -> LocalSyntaxPtr { LocalSyntaxPtr { range: node.range(), kind: node.kind(), } } - pub fn resolve(self, file: &SourceFileNode) -> SyntaxNode { + pub fn resolve(self, file: &SourceFile) -> TreePtr { let mut curr = file.syntax(); loop { if curr.range() == self.range && curr.kind() == self.kind { - return curr.owned(); + return curr.to_owned(); } curr = curr .children() @@ -40,7 +40,7 @@ impl LocalSyntaxPtr { #[test] fn test_local_syntax_ptr() { use ra_syntax::{ast, AstNode}; - let file = SourceFileNode::parse("struct Foo { f: u32, }"); + let file = SourceFile::parse("struct Foo { f: u32, }"); let field = file .syntax() .descendants() @@ -48,5 +48,5 @@ fn test_local_syntax_ptr() { .unwrap(); let ptr = LocalSyntaxPtr::new(field.syntax()); let field_syntax = ptr.resolve(&file); - assert_eq!(field.syntax(), field_syntax); + assert_eq!(field.syntax(), &*field_syntax); } 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 { pub type GreenNode = rowan::GreenNode; -#[derive(Clone, PartialEq, Eq, Hash)] +#[derive(PartialEq, Eq, Hash)] pub struct TreePtr>>( pub(crate) rowan::TreePtr, ); @@ -47,6 +47,15 @@ where } } +impl Clone for TreePtr +where + T: TransparentNewType>, +{ + fn clone(&self) -> TreePtr { + TreePtr(self.0.clone()) + } +} + impl fmt::Debug for TreePtr where T: TransparentNewType>, -- cgit v1.2.3