From 7b901f86cd1d0198994e5a2ab7eea18f444dd148 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Jan 2019 17:37:10 +0300 Subject: move SyntaxPtr to ra_syntax --- crates/ra_db/src/lib.rs | 2 -- crates/ra_db/src/syntax_ptr.rs | 52 ------------------------------------------ 2 files changed, 54 deletions(-) delete mode 100644 crates/ra_db/src/syntax_ptr.rs (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index dbeb9ec71..32d7e09b9 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -1,6 +1,5 @@ //! ra_db defines basic database traits. The concrete DB is defined by ra_ide_api. mod cancellation; -mod syntax_ptr; mod input; mod loc2id; pub mod mock; @@ -12,7 +11,6 @@ use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc}; pub use ::salsa as salsa; pub use crate::{ cancellation::Canceled, - syntax_ptr::LocalSyntaxPtr, input::{ FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, FileTextQuery, FileSourceRootQuery, SourceRootQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery, diff --git a/crates/ra_db/src/syntax_ptr.rs b/crates/ra_db/src/syntax_ptr.rs deleted file mode 100644 index 5270826da..000000000 --- a/crates/ra_db/src/syntax_ptr.rs +++ /dev/null @@ -1,52 +0,0 @@ -use ra_syntax::{AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, TreeArc}; - -/// A pointer to a syntax node inside a file. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct LocalSyntaxPtr { - range: TextRange, - kind: SyntaxKind, -} - -impl LocalSyntaxPtr { - pub fn new(node: &SyntaxNode) -> LocalSyntaxPtr { - LocalSyntaxPtr { - range: node.range(), - kind: node.kind(), - } - } - - pub fn resolve(self, file: &SourceFile) -> TreeArc { - let mut curr = file.syntax(); - loop { - if curr.range() == self.range && curr.kind() == self.kind { - return curr.to_owned(); - } - curr = curr - .children() - .find(|it| self.range.is_subrange(&it.range())) - .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) - } - } - - pub fn range(self) -> TextRange { - self.range - } - - pub fn kind(self) -> SyntaxKind { - self.kind - } -} - -#[test] -fn test_local_syntax_ptr() { - use ra_syntax::{ast, AstNode}; - let file = SourceFile::parse("struct Foo { f: u32, }"); - let field = file - .syntax() - .descendants() - .find_map(ast::NamedFieldDef::cast) - .unwrap(); - let ptr = LocalSyntaxPtr::new(field.syntax()); - let field_syntax = ptr.resolve(&file); - assert_eq!(field.syntax(), &*field_syntax); -} -- cgit v1.2.3