diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 22 | ||||
-rw-r--r-- | crates/ra_ide_api/src/marks.rs | 1 |
2 files changed, 21 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 3267fff96..f203a6bf1 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 |
@@ -172,10 +178,12 @@ fn param_list(node: &ast::FnDef) -> Vec<String> { | |||
172 | 178 | ||
173 | #[cfg(test)] | 179 | #[cfg(test)] |
174 | mod tests { | 180 | mod tests { |
175 | use super::*; | 181 | use test_utils::covers; |
176 | 182 | ||
177 | use crate::mock_analysis::single_file_with_position; | 183 | use crate::mock_analysis::single_file_with_position; |
178 | 184 | ||
185 | use super::*; | ||
186 | |||
179 | fn call_info(text: &str) -> CallInfo { | 187 | fn call_info(text: &str) -> CallInfo { |
180 | let (analysis, position) = single_file_with_position(text); | 188 | let (analysis, position) = single_file_with_position(text); |
181 | analysis.call_info(position).unwrap().unwrap() | 189 | analysis.call_info(position).unwrap().unwrap() |
@@ -417,4 +425,14 @@ By default this method stops actor's `Context`."# | |||
417 | ); | 425 | ); |
418 | } | 426 | } |
419 | 427 | ||
428 | #[test] | ||
429 | fn call_info_bad_offset() { | ||
430 | covers!(call_info_bad_offset); | ||
431 | let (analysis, position) = single_file_with_position( | ||
432 | r#"fn foo(x: u32, y: u32) -> u32 {x + y} | ||
433 | fn bar() { foo <|> (3, ); }"#, | ||
434 | ); | ||
435 | let call_info = analysis.call_info(position).unwrap(); | ||
436 | assert!(call_info.is_none()); | ||
437 | } | ||
420 | } | 438 | } |
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 | ); |