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

chore: Upgrade cargo #1764

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ rls-vfs = "0.8"
rls-ipc = { version = "0.1.0", path = "rls-ipc", optional = true }

anyhow = "1.0.26"
cargo = { git = "https://github.com/rust-lang/cargo", rev = "06b9d31743210b788b130c8a484c2838afa6fc27" }
cargo-util = { git = "https://github.com/rust-lang/cargo", rev = "06b9d31743210b788b130c8a484c2838afa6fc27" }
cargo = { git = "https://github.com/rust-lang/cargo", rev = "1c034752de0df744fcd7788fcbca158830b8bf85" }
cargo-util = { git = "https://github.com/rust-lang/cargo", rev = "1c034752de0df744fcd7788fcbca158830b8bf85" }
cargo_metadata = "0.14"
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", version = "0.1.60", optional = true }
env_logger = "0.9"
Expand All @@ -58,6 +58,7 @@ regex = "1"
ordslice = "0.3"
crossbeam-channel = "0.5"
toml = "0.5"
toml_edit = { version = "0.13.1", features = ["easy"] }
heck = "0.3"

# A noop dependency that changes in the Rust repository, it's a bit of a hack.
Expand Down
28 changes: 19 additions & 9 deletions rls/src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(super) fn cargo(

let (manifest_path, manifest_error_range) = {
let mae = error.downcast_ref::<ManifestAwareError>();
(mae.map(|e| e.manifest_path().clone()), mae.map(|e| e.manifest_error_range()))
(mae.map(|e| e.manifest_path().clone()), mae.and_then(|e| e.manifest_error_range()))
};
BuildResult::CargoError { error, stdout, manifest_path, manifest_error_range }
}
Expand Down Expand Up @@ -805,15 +805,15 @@ pub struct ManifestAwareError {
cause: anyhow::Error,
/// The path to a manifest file within the project that seems the closest to the error's origin.
nearest_project_manifest: PathBuf,
manifest_error_range: Range,
manifest_error_range: Option<Range>,
}

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

if let Some(manifest_err) = cause.downcast_ref::<ManifestError>() {
// Scan through any manifest errors to pin the error more precisely.
Expand All @@ -828,15 +828,25 @@ impl ManifestAwareError {
fn find_toml_error(
err: &(dyn std::error::Error + 'static),
) -> Option<(usize, usize)> {
match err.downcast_ref::<toml::de::Error>() {
Some(toml_err) => toml_err.line_col(),
None => find_toml_error(err.source()?),
if let Some(toml_err) = err.downcast_ref::<toml_edit::TomlError>() {
toml_err.line_col()
} else if let Some(toml_err) = err.downcast_ref::<toml_edit::de::Error>() {
toml_err.line_col()
} else if let Some(toml_err) = err.downcast_ref::<toml::de::Error>() {
toml_err.line_col()
} else {
find_toml_error(err.source()?)
}
}
if let Some((line, col)) = find_toml_error(last_cause) {
let line = line as _;
let start_col = col as _;
let end_col = start_col + 1;
// Use TOML deserializiation error position.
err_range.start = Position::new(line as _, col as _);
err_range.end = Position::new(line as _, col as u64 + 1);
err_range = Some(Range {
start: Position::new(line, start_col),
end: Position::new(line, end_col),
});
}
} else {
let nearest_cause = manifest_err
Expand Down Expand Up @@ -868,7 +878,7 @@ impl ManifestAwareError {
&self.nearest_project_manifest
}

pub fn manifest_error_range(&self) -> Range {
pub fn manifest_error_range(&self) -> Option<Range> {
self.manifest_error_range
}
}
Expand Down