Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit b3a092d

Browse files
committed
refactor: Clarify when no error
1 parent e9bdaba commit b3a092d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

rls/src/build/cargo.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(super) fn cargo(
8484

8585
let (manifest_path, manifest_error_range) = {
8686
let mae = error.downcast_ref::<ManifestAwareError>();
87-
(mae.map(|e| e.manifest_path().clone()), mae.map(|e| e.manifest_error_range()))
87+
(mae.map(|e| e.manifest_path().clone()), mae.and_then(|e| e.manifest_error_range()))
8888
};
8989
BuildResult::CargoError { error, stdout, manifest_path, manifest_error_range }
9090
}
@@ -805,15 +805,15 @@ pub struct ManifestAwareError {
805805
cause: anyhow::Error,
806806
/// The path to a manifest file within the project that seems the closest to the error's origin.
807807
nearest_project_manifest: PathBuf,
808-
manifest_error_range: Range,
808+
manifest_error_range: Option<Range>,
809809
}
810810

811811
impl ManifestAwareError {
812812
fn new(cause: anyhow::Error, root_manifest: &Path, ws: Option<&Workspace<'_>>) -> Self {
813813
let project_dir = root_manifest.parent().unwrap();
814814
let mut err_path = root_manifest;
815815
// Cover whole manifest if we haven't any better idea.
816-
let mut err_range = Range { start: Position::new(0, 0), end: Position::new(9999, 0) };
816+
let mut err_range = None;
817817

818818
if let Some(manifest_err) = cause.downcast_ref::<ManifestError>() {
819819
// Scan through any manifest errors to pin the error more precisely.
@@ -834,9 +834,14 @@ impl ManifestAwareError {
834834
}
835835
}
836836
if let Some((line, col)) = find_toml_error(last_cause) {
837+
let line = line as _;
838+
let start_col = col as _;
839+
let end_col = start_col + 1;
837840
// Use TOML deserializiation error position.
838-
err_range.start = Position::new(line as _, col as _);
839-
err_range.end = Position::new(line as _, col as u64 + 1);
841+
err_range = Some(Range {
842+
start: Position::new(line, start_col),
843+
end: Position::new(line, end_col),
844+
});
840845
}
841846
} else {
842847
let nearest_cause = manifest_err
@@ -868,7 +873,7 @@ impl ManifestAwareError {
868873
&self.nearest_project_manifest
869874
}
870875

871-
pub fn manifest_error_range(&self) -> Range {
876+
pub fn manifest_error_range(&self) -> Option<Range> {
872877
self.manifest_error_range
873878
}
874879
}

0 commit comments

Comments
 (0)