From 830abe0c1b9fdbc20a78771d0b3df37d9eabdc3e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 2 Jan 2019 17:09:39 +0300 Subject: use navigation target in API --- crates/ra_analysis/src/imp.rs | 6 +++--- crates/ra_analysis/src/lib.rs | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 836fb89f5..b513736bb 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -205,7 +205,7 @@ impl AnalysisImpl { /// This returns `Vec` because a module may be included from several places. We /// don't handle this case yet though, so the Vec has length at most one. - pub fn parent_module(&self, position: FilePosition) -> Cancelable> { + pub fn parent_module(&self, position: FilePosition) -> Cancelable> { let descr = match source_binder::module_from_position(&*self.db, position)? { None => return Ok(Vec::new()), Some(it) => it, @@ -216,12 +216,12 @@ impl AnalysisImpl { }; let decl = decl.borrowed(); let decl_name = decl.name().unwrap(); - let sym = FileSymbol { + let symbol = FileSymbol { name: decl_name.text(), node_range: decl_name.syntax().range(), kind: MODULE, }; - Ok(vec![(file_id, sym)]) + Ok(vec![NavigationTarget { file_id, symbol }]) } /// Returns `Vec` for the same reason as `parent_module` pub fn crate_for(&self, file_id: FileId) -> Cancelable> { diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 4d8bdb61b..75867ee86 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -24,7 +24,7 @@ mod macros; use std::{fmt, sync::Arc}; use rustc_hash::FxHashMap; -use ra_syntax::{SourceFileNode, TextRange, TextUnit}; +use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind}; use ra_text_edit::TextEdit; use rayon::prelude::*; use relative_path::RelativePathBuf; @@ -251,6 +251,12 @@ pub struct NavigationTarget { } impl NavigationTarget { + pub fn name(&self) -> SmolStr { + self.symbol.name.clone() + } + pub fn kind(&self) -> SyntaxKind { + self.symbol.kind + } pub fn file_id(&self) -> FileId { self.file_id } @@ -337,8 +343,14 @@ impl Analysis { let file = self.imp.file_syntax(file_id); ra_editor::folding_ranges(&file) } - pub fn symbol_search(&self, query: Query) -> Cancelable> { - self.imp.world_symbols(query) + pub fn symbol_search(&self, query: Query) -> Cancelable> { + let res = self + .imp + .world_symbols(query)? + .into_iter() + .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) + .collect(); + Ok(res) } pub fn approximately_resolve_symbol( &self, @@ -352,7 +364,7 @@ impl Analysis { pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable> { self.imp.doc_text_for(nav) } - pub fn parent_module(&self, position: FilePosition) -> Cancelable> { + pub fn parent_module(&self, position: FilePosition) -> Cancelable> { self.imp.parent_module(position) } pub fn module_path(&self, position: FilePosition) -> Cancelable> { -- cgit v1.2.3