aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/hir/function/mod.rs17
-rw-r--r--crates/ra_analysis/src/hir/mod.rs3
-rw-r--r--crates/ra_analysis/src/imp.rs12
-rw-r--r--crates/ra_analysis/src/lib.rs4
4 files changed, 21 insertions, 15 deletions
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 {
42 pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { 42 pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
43 db.fn_scopes(self.fn_id) 43 db.fn_scopes(self.fn_id)
44 } 44 }
45
46 pub(crate) fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
47 let syntax = db.fn_syntax(self.fn_id);
48 FnSignatureInfo::new(syntax.borrowed())
49 }
45} 50}
46 51
47#[derive(Debug, Clone)] 52#[derive(Debug, Clone)]
48pub struct FnDescriptor { 53pub struct FnSignatureInfo {
49 pub name: String, 54 pub name: String,
50 pub label: String, 55 pub label: String,
51 pub ret_type: Option<String>, 56 pub ret_type: Option<String>,
@@ -53,8 +58,8 @@ pub struct FnDescriptor {
53 pub doc: Option<String>, 58 pub doc: Option<String>,
54} 59}
55 60
56impl FnDescriptor { 61impl FnSignatureInfo {
57 pub fn new(node: ast::FnDef) -> Option<Self> { 62 fn new(node: ast::FnDef) -> Option<Self> {
58 let name = node.name()?.text().to_string(); 63 let name = node.name()?.text().to_string();
59 64
60 let mut doc = None; 65 let mut doc = None;
@@ -73,7 +78,7 @@ impl FnDescriptor {
73 node.syntax().text().to_string() 78 node.syntax().text().to_string()
74 }; 79 };
75 80
76 if let Some((comment_range, docs)) = FnDescriptor::extract_doc_comments(node) { 81 if let Some((comment_range, docs)) = FnSignatureInfo::extract_doc_comments(node) {
77 let comment_range = comment_range 82 let comment_range = comment_range
78 .checked_sub(node.syntax().range().start()) 83 .checked_sub(node.syntax().range().start())
79 .unwrap(); 84 .unwrap();
@@ -105,10 +110,10 @@ impl FnDescriptor {
105 } 110 }
106 } 111 }
107 112
108 let params = FnDescriptor::param_list(node); 113 let params = FnSignatureInfo::param_list(node);
109 let ret_type = node.ret_type().map(|r| r.syntax().text().to_string()); 114 let ret_type = node.ret_type().map(|r| r.syntax().text().to_string());
110 115
111 Some(FnDescriptor { 116 Some(FnSignatureInfo {
112 name, 117 name,
113 ret_type, 118 ret_type,
114 params, 119 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::{
29 function::{FunctionDescriptor, FnScopes}, 29 function::{FunctionDescriptor, FnScopes},
30}; 30};
31 31
32//TODO: FIXME 32pub use self::function::FnSignatureInfo;
33pub use self::function::FnDescriptor;
34 33
35pub(crate) enum Def { 34pub(crate) enum Def {
36 Module(ModuleDescriptor), 35 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::{
20 completion::{completions, CompletionItem}, 20 completion::{completions, CompletionItem},
21 db::{self, FileSyntaxQuery, SyntaxDatabase}, 21 db::{self, FileSyntaxQuery, SyntaxDatabase},
22 hir::{ 22 hir::{
23 FnDescriptor, FunctionDescriptor, ModuleDescriptor, 23 FunctionDescriptor, FnSignatureInfo, ModuleDescriptor,
24 Problem, 24 Problem,
25 DeclarationDescriptor, 25 DeclarationDescriptor,
26 }, 26 },
@@ -445,7 +445,7 @@ impl AnalysisImpl {
445 pub fn resolve_callable( 445 pub fn resolve_callable(
446 &self, 446 &self,
447 position: FilePosition, 447 position: FilePosition,
448 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { 448 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
449 let file = self.db.file_syntax(position.file_id); 449 let file = self.db.file_syntax(position.file_id);
450 let syntax = file.syntax(); 450 let syntax = file.syntax();
451 451
@@ -455,11 +455,13 @@ impl AnalysisImpl {
455 455
456 // Resolve the function's NameRef (NOTE: this isn't entirely accurate). 456 // Resolve the function's NameRef (NOTE: this isn't entirely accurate).
457 let file_symbols = self.index_resolve(name_ref)?; 457 let file_symbols = self.index_resolve(name_ref)?;
458 for (fn_fiel_id, fs) in file_symbols { 458 for (fn_file_id, fs) in file_symbols {
459 if fs.kind == FN_DEF { 459 if fs.kind == FN_DEF {
460 let fn_file = self.db.file_syntax(fn_fiel_id); 460 let fn_file = self.db.file_syntax(fn_file_id);
461 if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { 461 if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) {
462 if let Some(descriptor) = FnDescriptor::new(fn_def) { 462 let descr =
463 FunctionDescriptor::guess_from_source(&*self.db, fn_file_id, fn_def);
464 if let Some(descriptor) = descr.signature_info(&*self.db) {
463 // If we have a calling expression let's find which argument we are on 465 // If we have a calling expression let's find which argument we are on
464 let mut current_parameter = None; 466 let mut current_parameter = None;
465 467
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::{
42 42
43pub use crate::{ 43pub use crate::{
44 completion::CompletionItem, 44 completion::CompletionItem,
45 hir::FnDescriptor, 45 hir::FnSignatureInfo,
46 input::{CrateGraph, CrateId, FileId, FileResolver}, 46 input::{CrateGraph, CrateId, FileId, FileResolver},
47}; 47};
48pub use ra_editor::{ 48pub use ra_editor::{
@@ -305,7 +305,7 @@ impl Analysis {
305 pub fn resolve_callable( 305 pub fn resolve_callable(
306 &self, 306 &self,
307 position: FilePosition, 307 position: FilePosition,
308 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { 308 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
309 self.imp.resolve_callable(position) 309 self.imp.resolve_callable(position)
310 } 310 }
311} 311}