From a82c679c97af1e0aabe9eb375573d5d23fc75391 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 13 Jan 2020 11:27:06 -0500 Subject: Some clippy lints --- crates/ra_ide/src/call_hierarchy.rs | 2 +- crates/ra_ide/src/call_info.rs | 59 ++++++++++++++------------- crates/ra_ide/src/completion/complete_path.rs | 2 +- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/references.rs | 13 +++--- crates/ra_ide/src/references/search_scope.rs | 3 +- 6 files changed, 40 insertions(+), 41 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index 1cb712e32..aa5d60c7b 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -121,7 +121,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio Some(macro_def.to_nav(db)) } } { - Some((func_target.clone(), name_ref.value.text_range())) + Some((func_target, name_ref.value.text_range())) } else { None } diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index a7023529b..14f5ead6b 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -1,10 +1,10 @@ //! FIXME: write short doc here - use hir::db::AstDatabase; use ra_syntax::{ ast::{self, ArgListOwner}, match_ast, AstNode, SyntaxNode, }; +use std::cmp::Ordering; use test_utils::tested_by; use crate::{ @@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option 1 { - // Count how many parameters into the call we are. - if let Some(arg_list) = calling_node.arg_list() { - // Number of arguments specified at the call site - let num_args_at_callsite = arg_list.args().count(); - - let arg_list_range = arg_list.syntax().text_range(); - if !arg_list_range.contains_inclusive(position.offset) { - tested_by!(call_info_bad_offset); - return None; + match num_params.cmp(&1) { + Ordering::Less => {} + Ordering::Equal => { + if !has_self { + call_info.active_parameter = Some(0); } + } + Ordering::Greater => { + if let Some(arg_list) = calling_node.arg_list() { + // Number of arguments specified at the call site + let num_args_at_callsite = arg_list.args().count(); + + let arg_list_range = arg_list.syntax().text_range(); + if !arg_list_range.contains_inclusive(position.offset) { + tested_by!(call_info_bad_offset); + return None; + } - let mut param = std::cmp::min( - num_args_at_callsite, - arg_list - .args() - .take_while(|arg| arg.syntax().text_range().end() < position.offset) - .count(), - ); - - // If we are in a method account for `self` - if has_self { - param += 1; - } + let mut param = std::cmp::min( + num_args_at_callsite, + arg_list + .args() + .take_while(|arg| arg.syntax().text_range().end() < position.offset) + .count(), + ); + + // If we are in a method account for `self` + if has_self { + param += 1; + } - call_info.active_parameter = Some(param); + call_info.active_parameter = Some(param); + } } } diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index cc1f7c830..0dce9dc2d 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs @@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { } if let ScopeDef::Unknown = def { if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { - if &name_ref.syntax().text() == name.to_string().as_str() { + if name_ref.syntax().text() == name.to_string().as_str() { // for `use self::foo<|>`, don't suggest `foo` as a completion tested_by!(dont_complete_current_use); continue; diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 70b6fde82..930e0c4c2 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -339,7 +339,7 @@ mod tests { let (cursor, before) = extract_offset(before); let (analysis, file_id) = single_file(&before); let range = TextRange::offset_len(cursor, 0.into()); - let mut frange = FileRange { file_id: file_id, range }; + let mut frange = FileRange { file_id, range }; for &after in afters { frange.range = analysis.extend_selection(frange).unwrap(); diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 4e52e0e7b..2c753dade 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -166,7 +166,7 @@ pub(crate) fn find_all_refs( Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references })) } -fn find_name<'a>( +fn find_name( db: &RootDatabase, syntax: &SyntaxNode, position: FilePosition, @@ -253,13 +253,10 @@ fn decl_access( let stmt = find_node_at_offset::(syntax, range.start())?; if let Some(_) = stmt.initializer() { let pat = stmt.pat()?; - match pat { - ast::Pat::BindPat(it) => { - if it.name()?.text().as_str() == name { - return Some(ReferenceAccess::Write); - } + if let ast::Pat::BindPat(it) = pat { + if it.name()?.text().as_str() == name { + return Some(ReferenceAccess::Write); } - _ => {} } } @@ -286,7 +283,7 @@ fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option {None} } diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs index 241dd358f..f8211a746 100644 --- a/crates/ra_ide/src/references/search_scope.rs +++ b/crates/ra_ide/src/references/search_scope.rs @@ -82,8 +82,7 @@ impl NameDefinition { return SearchScope::new(res); } - let vis = - self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or("".to_string()); + let vis = self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); if vis.as_str() == "pub(super)" { if let Some(parent_module) = self.container.parent(db) { -- cgit v1.2.3 From c5c5f4260b4ab1a03d2d3f7a616202369adc9ade Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 13 Jan 2020 11:38:53 -0500 Subject: Readability --- crates/ra_ide/src/call_info.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 14f5ead6b..72a68522e 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -4,7 +4,7 @@ use ra_syntax::{ ast::{self, ArgListOwner}, match_ast, AstNode, SyntaxNode, }; -use std::cmp::Ordering; + use test_utils::tested_by; use crate::{ @@ -51,14 +51,14 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option {} - Ordering::Equal => { + match num_params { + 0 => (), + 1 => { if !has_self { call_info.active_parameter = Some(0); } } - Ordering::Greater => { + _ => { if let Some(arg_list) = calling_node.arg_list() { // Number of arguments specified at the call site let num_args_at_callsite = arg_list.args().count(); -- cgit v1.2.3