From 7207eef716c0970df1b3523f8f4bb685518f8f73 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 27 Nov 2018 23:48:24 +0300 Subject: rename FnDescriptior -> FnSignatureInfo --- crates/ra_analysis/src/hir/function/mod.rs | 17 +++++++++++------ crates/ra_analysis/src/hir/mod.rs | 3 +-- crates/ra_analysis/src/imp.rs | 12 +++++++----- crates/ra_analysis/src/lib.rs | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs index 8161a604f..5e44a88a7 100644 --- a/crates/ra_analysis/src/hir/function/mod.rs +++ b/crates/ra_analysis/src/hir/function/mod.rs @@ -42,10 +42,15 @@ impl FunctionDescriptor { pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc { db.fn_scopes(self.fn_id) } + + pub(crate) fn signature_info(&self, db: &impl HirDatabase) -> Option { + let syntax = db.fn_syntax(self.fn_id); + FnSignatureInfo::new(syntax.borrowed()) + } } #[derive(Debug, Clone)] -pub struct FnDescriptor { +pub struct FnSignatureInfo { pub name: String, pub label: String, pub ret_type: Option, @@ -53,8 +58,8 @@ pub struct FnDescriptor { pub doc: Option, } -impl FnDescriptor { - pub fn new(node: ast::FnDef) -> Option { +impl FnSignatureInfo { + fn new(node: ast::FnDef) -> Option { let name = node.name()?.text().to_string(); let mut doc = None; @@ -73,7 +78,7 @@ impl FnDescriptor { node.syntax().text().to_string() }; - if let Some((comment_range, docs)) = FnDescriptor::extract_doc_comments(node) { + if let Some((comment_range, docs)) = FnSignatureInfo::extract_doc_comments(node) { let comment_range = comment_range .checked_sub(node.syntax().range().start()) .unwrap(); @@ -105,10 +110,10 @@ impl FnDescriptor { } } - let params = FnDescriptor::param_list(node); + let params = FnSignatureInfo::param_list(node); let ret_type = node.ret_type().map(|r| r.syntax().text().to_string()); - Some(FnDescriptor { + Some(FnSignatureInfo { name, ret_type, params, diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs index 1d37fae32..5a9086cef 100644 --- a/crates/ra_analysis/src/hir/mod.rs +++ b/crates/ra_analysis/src/hir/mod.rs @@ -29,8 +29,7 @@ pub(crate) use self::{ function::{FunctionDescriptor, FnScopes}, }; -//TODO: FIXME -pub use self::function::FnDescriptor; +pub use self::function::FnSignatureInfo; pub(crate) enum Def { Module(ModuleDescriptor), diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 347d44638..b16edb969 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -20,7 +20,7 @@ use crate::{ completion::{completions, CompletionItem}, db::{self, FileSyntaxQuery, SyntaxDatabase}, hir::{ - FnDescriptor, FunctionDescriptor, ModuleDescriptor, + FunctionDescriptor, FnSignatureInfo, ModuleDescriptor, Problem, DeclarationDescriptor, }, @@ -445,7 +445,7 @@ impl AnalysisImpl { pub fn resolve_callable( &self, position: FilePosition, - ) -> Cancelable)>> { + ) -> Cancelable)>> { let file = self.db.file_syntax(position.file_id); let syntax = file.syntax(); @@ -455,11 +455,13 @@ impl AnalysisImpl { // Resolve the function's NameRef (NOTE: this isn't entirely accurate). let file_symbols = self.index_resolve(name_ref)?; - for (fn_fiel_id, fs) in file_symbols { + for (fn_file_id, fs) in file_symbols { if fs.kind == FN_DEF { - let fn_file = self.db.file_syntax(fn_fiel_id); + let fn_file = self.db.file_syntax(fn_file_id); if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { - if let Some(descriptor) = FnDescriptor::new(fn_def) { + let descr = + FunctionDescriptor::guess_from_source(&*self.db, fn_file_id, fn_def); + if let Some(descriptor) = descr.signature_info(&*self.db) { // If we have a calling expression let's find which argument we are on let mut current_parameter = None; diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index a3088c5ad..c0e43544e 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -42,7 +42,7 @@ use crate::{ pub use crate::{ completion::CompletionItem, - hir::FnDescriptor, + hir::FnSignatureInfo, input::{CrateGraph, CrateId, FileId, FileResolver}, }; pub use ra_editor::{ @@ -305,7 +305,7 @@ impl Analysis { pub fn resolve_callable( &self, position: FilePosition, - ) -> Cancelable)>> { + ) -> Cancelable)>> { self.imp.resolve_callable(position) } } -- cgit v1.2.3