diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 25 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide_api/src/marks.rs | 1 |
3 files changed, 23 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 3267fff96..ee1e13799 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | use test_utils::tested_by; | ||
1 | use ra_db::SourceDatabase; | 2 | use ra_db::SourceDatabase; |
2 | use ra_syntax::{ | 3 | use ra_syntax::{ |
3 | AstNode, SyntaxNode, TextUnit, TextRange, | 4 | AstNode, SyntaxNode, TextUnit, TextRange, |
@@ -41,7 +42,12 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
41 | // where offset is in that list (or beyond). | 42 | // where offset is in that list (or beyond). |
42 | // Revisit this after we get documentation comments in. | 43 | // Revisit this after we get documentation comments in. |
43 | if let Some(ref arg_list) = calling_node.arg_list() { | 44 | if let Some(ref arg_list) = calling_node.arg_list() { |
44 | let start = arg_list.syntax().range().start(); | 45 | let arg_list_range = arg_list.syntax().range(); |
46 | if !arg_list_range.contains_inclusive(position.offset) { | ||
47 | tested_by!(call_info_bad_offset); | ||
48 | return None; | ||
49 | } | ||
50 | let start = arg_list_range.start(); | ||
45 | 51 | ||
46 | let range_search = TextRange::from_to(start, position.offset); | 52 | let range_search = TextRange::from_to(start, position.offset); |
47 | let mut commas: usize = arg_list | 53 | let mut commas: usize = arg_list |
@@ -120,8 +126,7 @@ impl CallInfo { | |||
120 | }; | 126 | }; |
121 | 127 | ||
122 | let mut doc = None; | 128 | let mut doc = None; |
123 | let docs = node.doc_comment_text(); | 129 | if let Some(docs) = node.doc_comment_text() { |
124 | if !docs.is_empty() { | ||
125 | // Massage markdown | 130 | // Massage markdown |
126 | let mut processed_lines = Vec::new(); | 131 | let mut processed_lines = Vec::new(); |
127 | let mut in_code_block = false; | 132 | let mut in_code_block = false; |
@@ -172,10 +177,12 @@ fn param_list(node: &ast::FnDef) -> Vec<String> { | |||
172 | 177 | ||
173 | #[cfg(test)] | 178 | #[cfg(test)] |
174 | mod tests { | 179 | mod tests { |
175 | use super::*; | 180 | use test_utils::covers; |
176 | 181 | ||
177 | use crate::mock_analysis::single_file_with_position; | 182 | use crate::mock_analysis::single_file_with_position; |
178 | 183 | ||
184 | use super::*; | ||
185 | |||
179 | fn call_info(text: &str) -> CallInfo { | 186 | fn call_info(text: &str) -> CallInfo { |
180 | let (analysis, position) = single_file_with_position(text); | 187 | let (analysis, position) = single_file_with_position(text); |
181 | analysis.call_info(position).unwrap().unwrap() | 188 | analysis.call_info(position).unwrap().unwrap() |
@@ -417,4 +424,14 @@ By default this method stops actor's `Context`."# | |||
417 | ); | 424 | ); |
418 | } | 425 | } |
419 | 426 | ||
427 | #[test] | ||
428 | fn call_info_bad_offset() { | ||
429 | covers!(call_info_bad_offset); | ||
430 | let (analysis, position) = single_file_with_position( | ||
431 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} | ||
432 | fn bar() { foo <|> (3, ); }"#, | ||
433 | ); | ||
434 | let call_info = analysis.call_info(position).unwrap(); | ||
435 | assert!(call_info.is_none()); | ||
436 | } | ||
420 | } | 437 | } |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index ff9ae2d9c..f993a461c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -100,12 +100,7 @@ impl NavigationTarget { | |||
100 | fn docs(&self, db: &RootDatabase) -> Option<String> { | 100 | fn docs(&self, db: &RootDatabase) -> Option<String> { |
101 | let node = self.node(db)?; | 101 | let node = self.node(db)?; |
102 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { | 102 | fn doc_comments<N: ast::DocCommentsOwner>(node: &N) -> Option<String> { |
103 | let comments = node.doc_comment_text(); | 103 | node.doc_comment_text() |
104 | if comments.is_empty() { | ||
105 | None | ||
106 | } else { | ||
107 | Some(comments) | ||
108 | } | ||
109 | } | 104 | } |
110 | 105 | ||
111 | visitor() | 106 | visitor() |
diff --git a/crates/ra_ide_api/src/marks.rs b/crates/ra_ide_api/src/marks.rs index e33bf6c91..21ce7289d 100644 --- a/crates/ra_ide_api/src/marks.rs +++ b/crates/ra_ide_api/src/marks.rs | |||
@@ -2,4 +2,5 @@ test_utils::marks!( | |||
2 | inserts_parens_for_function_calls | 2 | inserts_parens_for_function_calls |
3 | goto_definition_works_for_methods | 3 | goto_definition_works_for_methods |
4 | goto_definition_works_for_fields | 4 | goto_definition_works_for_fields |
5 | call_info_bad_offset | ||
5 | ); | 6 | ); |