diff --git a/src/main.rs b/src/main.rs index 78b9d9e..822da2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ impl Backend { }) .collect(); - if dependency_with_versions.len() == 0 { + if dependency_with_versions.is_empty() { return Vec::new(); } @@ -61,36 +61,33 @@ impl Backend { // Produce diagnostic hints for each crate where we might be helpful. let diagnostics: Vec<_> = dependency_with_versions .into_iter() - .filter_map(|dependency| { + .map(|dependency| { if let Some(Some(newest_version)) = newest_packages.get(&dependency.name) { match &dependency.version { DependencyVersion::Complete { range, version } => { if !version.matches(newest_version) { - return Some(Diagnostic::new_simple( - range.clone(), + Diagnostic::new_simple( + *range, format!("{}: {newest_version}", &dependency.name), - )); + ) } else { let range = Range { start: Position::new(range.start.line, 0), end: Position::new(range.start.line, 0), }; - - return Some(Diagnostic::new_simple(range, "✓".to_string())); + Diagnostic::new_simple(range, "✓".to_string()) } } - DependencyVersion::Partial { range, .. } => { - return Some(Diagnostic::new_simple( - range.clone(), - format!("{}: {newest_version}", &dependency.name), - )); - } + DependencyVersion::Partial { range, .. } => Diagnostic::new_simple( + *range, + format!("{}: {newest_version}", &dependency.name), + ), } } else { - return Some(Diagnostic::new_simple( + Diagnostic::new_simple( dependency.version.range(), format!("{}: Unknown crate", &dependency.name), - )); + ) } }) .collect(); @@ -194,22 +191,11 @@ impl LanguageServer for Backend { let Some(dependency) = dependencies .into_iter() .find(|dependency| match dependency { - Dependency::Partial { line, .. } => { - if *line == cursor.line { - true - } else { - false - } - } + Dependency::Partial { line, .. } => *line == cursor.line, Dependency::WithVersion(dep) => { - if dep.version.range().start.line == cursor.line + dep.version.range().start.line == cursor.line && dep.version.range().start.character <= cursor.character && dep.version.range().end.character >= cursor.character - { - true - } else { - false - } } Dependency::Other { .. } => false, }) diff --git a/src/parse.rs b/src/parse.rs index 108d96f..438bb5b 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -384,7 +384,7 @@ impl ManifestTracker { if let Some(mut dependency) = Line::parse(line, i) { if dependency .name() - .and_then(|x| Some(x != "version")) + .map(|x| x != "version") .unwrap_or_default() { continue; @@ -392,7 +392,9 @@ impl ManifestTracker { // Rename to the package section, since the dependency is currently // named "version" because of the Line::parse logic assuming this is // a regular dependencies section. - dependency.name_mut().and_then(|x| Some(*x = name.clone())); + if let Some(x) = dependency.name_mut() { + *x = name.clone() + } } // Line::parse assumes line 0, modify so we have to fix this manually. if let Some(version) = dependency.version_mut() {