From d3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Aug 2018 22:00:13 +0300 Subject: Borrowed AST --- crates/libanalysis/src/lib.rs | 26 +++++++++++++------------- crates/libanalysis/src/symbol_index.rs | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/libanalysis/src') diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index ae96a0d62..15a433afc 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs @@ -26,8 +26,8 @@ use std::{ }; use libsyntax2::{ - TextUnit, TextRange, RefRoot, - ast::{self, AstNode, NameOwner}, + TextUnit, TextRange, + ast::{self, AstNode, NameOwner, ParsedFile}, SyntaxKind::*, }; use libeditor::{LineIndex, FileSymbol, find_node}; @@ -109,7 +109,7 @@ impl WorldState { impl World { - pub fn file_syntax(&self, file_id: FileId) -> Result { + pub fn file_syntax(&self, file_id: FileId) -> Result { let data = self.file_data(file_id)?; Ok(data.syntax().clone()) } @@ -137,11 +137,11 @@ impl World { offset: TextUnit, ) -> Result> { let file = self.file_syntax(id)?; - let syntax = file.syntax_ref(); - if let Some(name_ref) = find_node::>(syntax, offset) { + let syntax = file.syntax(); + if let Some(name_ref) = find_node::(syntax, offset) { return Ok(self.index_resolve(name_ref)); } - if let Some(name) = find_node::>(syntax, offset) { + if let Some(name) = find_node::(syntax, offset) { if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { if module.has_semi() { return Ok(self.resolve_module(id, module)); @@ -151,7 +151,7 @@ impl World { Ok(vec![]) } - fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> { + fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> { let name = name_ref.text(); let mut query = Query::new(name.to_string()); query.exact(); @@ -159,7 +159,7 @@ impl World { self.world_symbols(query) } - fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<(FileId, FileSymbol)> { + fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<(FileId, FileSymbol)> { let name = match module.name() { Some(name) => name.text(), None => return Vec::new(), @@ -220,7 +220,7 @@ struct WorldData { struct FileData { text: String, symbols: OnceCell, - syntax: OnceCell, + syntax: OnceCell, lines: OnceCell, } @@ -234,14 +234,14 @@ impl FileData { } } - fn syntax(&self) -> &ast::File { + fn syntax(&self) -> &ParsedFile { self.syntax - .get_or_init(|| ast::File::parse(&self.text)) + .get_or_init(|| ParsedFile::parse(&self.text)) } - fn syntax_transient(&self) -> ast::File { + fn syntax_transient(&self) -> ParsedFile { self.syntax.get().map(|s| s.clone()) - .unwrap_or_else(|| ast::File::parse(&self.text)) + .unwrap_or_else(|| ParsedFile::parse(&self.text)) } fn symbols(&self) -> &FileSymbols { diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 3c3252956..426de4c76 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs @@ -1,6 +1,6 @@ use libeditor::{FileSymbol, file_symbols}; use libsyntax2::{ - ast, + ParsedFile, SyntaxKind::{self, *}, }; use fst::{self, IntoStreamer, Streamer}; @@ -12,7 +12,7 @@ pub(crate) struct FileSymbols { } impl FileSymbols { - pub(crate) fn new(file: &ast::File) -> FileSymbols { + pub(crate) fn new(file: &ParsedFile) -> FileSymbols { let mut symbols = file_symbols(file) .into_iter() .map(|s| (s.name.as_str().to_lowercase(), s)) -- cgit v1.2.3