From f848aa97ab9d9789f72828d28619dd4227c352b9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 12:53:16 +0300 Subject: group feature modules --- crates/ra_ide_api/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 65d21d899..f2439bfd7 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -18,14 +18,14 @@ macro_rules! ctry { }; } -mod completion; mod db; -mod goto_definition; mod imp; pub mod mock_analysis; -mod runnables; mod symbol_index; +mod completion; +mod runnables; +mod goto_definition; mod extend_selection; mod hover; mod call_info; -- cgit v1.2.3 From 2aa125251ebd74c0e2a119b351caec27a9e1da46 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 13:01:35 +0300 Subject: move nav to a separate file --- crates/ra_ide_api/src/lib.rs | 75 ++------------------------------------------ 1 file changed, 2 insertions(+), 73 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index f2439bfd7..2e1768951 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -22,6 +22,7 @@ mod db; mod imp; pub mod mock_analysis; mod symbol_index; +mod navigation_target; mod completion; mod runnables; @@ -33,8 +34,7 @@ mod syntax_highlighting; use std::{fmt, sync::Arc}; -use hir::{Def, ModuleSource, Name}; -use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, SyntaxNode, TextRange, TextUnit, AstNode}; +use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; use ra_text_edit::TextEdit; use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr, BaseDatabase}; use rayon::prelude::*; @@ -259,77 +259,6 @@ pub struct NavigationTarget { } impl NavigationTarget { - fn from_symbol(symbol: FileSymbol) -> NavigationTarget { - NavigationTarget { - file_id: symbol.file_id, - name: symbol.name.clone(), - kind: symbol.ptr.kind(), - range: symbol.ptr.range(), - ptr: Some(symbol.ptr.clone()), - } - } - - fn from_syntax(name: Option, file_id: FileId, node: &SyntaxNode) -> NavigationTarget { - NavigationTarget { - file_id, - name: name.map(|n| n.to_string().into()).unwrap_or("".into()), - kind: node.kind(), - range: node.range(), - ptr: Some(LocalSyntaxPtr::new(node)), - } - } - // TODO once Def::Item is gone, this should be able to always return a NavigationTarget - fn from_def(db: &db::RootDatabase, def: Def) -> Cancelable> { - Ok(match def { - Def::Struct(s) => { - let (file_id, node) = s.source(db)?; - Some(NavigationTarget::from_syntax( - s.name(db)?, - file_id.original_file(db), - node.syntax(), - )) - } - Def::Enum(e) => { - let (file_id, node) = e.source(db)?; - Some(NavigationTarget::from_syntax( - e.name(db)?, - file_id.original_file(db), - node.syntax(), - )) - } - Def::EnumVariant(ev) => { - let (file_id, node) = ev.source(db)?; - Some(NavigationTarget::from_syntax( - ev.name(db)?, - file_id.original_file(db), - node.syntax(), - )) - } - Def::Function(f) => { - let (file_id, node) = f.source(db)?; - let name = f.signature(db).name().clone(); - Some(NavigationTarget::from_syntax( - Some(name), - file_id.original_file(db), - node.syntax(), - )) - } - Def::Module(m) => { - let (file_id, source) = m.definition_source(db)?; - let name = m.name(db)?; - match source { - ModuleSource::SourceFile(node) => { - Some(NavigationTarget::from_syntax(name, file_id, node.syntax())) - } - ModuleSource::Module(node) => { - Some(NavigationTarget::from_syntax(name, file_id, node.syntax())) - } - } - } - Def::Item => None, - }) - } - pub fn name(&self) -> &SmolStr { &self.name } -- cgit v1.2.3 From df6bbc6e420e869c4a3a6effb21170c952727d04 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 13:05:45 +0300 Subject: Make from_syntax private --- crates/ra_ide_api/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 2e1768951..9c5a82187 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -243,7 +243,7 @@ impl Query { } } -/// `NavigationTarget` represents and element in the editor's UI whihc you can +/// `NavigationTarget` represents and element in the editor's UI which you can /// click on to navigate to a particular piece of code. /// /// Typically, a `NavigationTarget` corresponds to some element in the source -- cgit v1.2.3 From f9ed8d4d23cd210f24ca303c72b436bfbe84741f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 14:00:54 +0300 Subject: envapsulate navigation target better --- crates/ra_ide_api/src/lib.rs | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 9c5a82187..2873bab36 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -34,9 +34,9 @@ mod syntax_highlighting; use std::{fmt, sync::Arc}; -use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; +use ra_syntax::{SourceFile, TreePtr, TextRange, TextUnit}; use ra_text_edit::TextEdit; -use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr, BaseDatabase}; +use ra_db::{SyntaxDatabase, FilesDatabase, BaseDatabase}; use rayon::prelude::*; use relative_path::RelativePathBuf; use rustc_hash::FxHashMap; @@ -50,6 +50,7 @@ use crate::{ pub use crate::{ completion::{CompletionItem, CompletionItemKind, InsertText}, runnables::{Runnable, RunnableKind}, + navigation_target::NavigationTarget, }; pub use ra_ide_api_light::{ Fold, FoldKind, HighlightedRange, Severity, StructureNode, @@ -243,39 +244,6 @@ impl Query { } } -/// `NavigationTarget` represents and element in the editor's UI which you can -/// click on to navigate to a particular piece of code. -/// -/// Typically, a `NavigationTarget` corresponds to some element in the source -/// code, like a function or a struct, but this is not strictly required. -#[derive(Debug, Clone)] -pub struct NavigationTarget { - file_id: FileId, - name: SmolStr, - kind: SyntaxKind, - range: TextRange, - // Should be DefId ideally - ptr: Option, -} - -impl NavigationTarget { - pub fn name(&self) -> &SmolStr { - &self.name - } - - pub fn kind(&self) -> SyntaxKind { - self.kind - } - - pub fn file_id(&self) -> FileId { - self.file_id - } - - pub fn range(&self) -> TextRange { - self.range - } -} - #[derive(Debug)] pub struct RangeInfo { pub range: TextRange, -- cgit v1.2.3 From 3aaf20bd6ec75a572b13d020520d4df563a2891c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 14:14:09 +0300 Subject: return ref ranges from gotodef --- crates/ra_ide_api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 2873bab36..2b02dab2a 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -251,7 +251,7 @@ pub struct RangeInfo { } impl RangeInfo { - fn new(range: TextRange, info: T) -> RangeInfo { + pub fn new(range: TextRange, info: T) -> RangeInfo { RangeInfo { range, info } } } @@ -391,7 +391,7 @@ impl Analysis { pub fn goto_definition( &self, position: FilePosition, - ) -> Cancelable>> { + ) -> Cancelable>>> { self.db .catch_canceled(|db| goto_definition::goto_definition(db, position))? } -- cgit v1.2.3 From dda916bc4d51383fcf84f736bd12c7a77c445fb0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 18:17:20 +0300 Subject: fix tests --- crates/ra_ide_api/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src/lib.rs') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 2b02dab2a..6155d903a 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -31,6 +31,7 @@ mod extend_selection; mod hover; mod call_info; mod syntax_highlighting; +mod parent_module; use std::{fmt, sync::Arc}; @@ -414,7 +415,7 @@ impl Analysis { /// Returns a `mod name;` declaration which created the current module. pub fn parent_module(&self, position: FilePosition) -> Cancelable> { - self.with_db(|db| db.parent_module(position))? + self.with_db(|db| parent_module::parent_module(db, position))? } /// Returns crates this file belongs too. -- cgit v1.2.3