diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 17 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/project_model/cargo_workspace.rs | 10 |
2 files changed, 20 insertions, 7 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 8ea9edc84..3f58e3c93 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -520,10 +520,17 @@ pub fn handle_formatting( | |||
520 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); | 520 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); |
521 | 521 | ||
522 | use std::process; | 522 | use std::process; |
523 | let mut rustfmt = process::Command::new("rustfmt") | 523 | let mut rustfmt = process::Command::new("rustfmt"); |
524 | rustfmt | ||
524 | .stdin(process::Stdio::piped()) | 525 | .stdin(process::Stdio::piped()) |
525 | .stdout(process::Stdio::piped()) | 526 | .stdout(process::Stdio::piped()); |
526 | .spawn()?; | 527 | |
528 | if let Ok(path) = params.text_document.uri.to_file_path() { | ||
529 | if let Some(parent) = path.parent() { | ||
530 | rustfmt.current_dir(parent); | ||
531 | } | ||
532 | } | ||
533 | let mut rustfmt = rustfmt.spawn()?; | ||
527 | 534 | ||
528 | rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?; | 535 | rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?; |
529 | 536 | ||
@@ -531,7 +538,9 @@ pub fn handle_formatting( | |||
531 | let captured_stdout = String::from_utf8(output.stdout)?; | 538 | let captured_stdout = String::from_utf8(output.stdout)?; |
532 | if !output.status.success() { | 539 | if !output.status.success() { |
533 | failure::bail!( | 540 | failure::bail!( |
534 | "rustfmt exited with error code {}: {}.", | 541 | r#"rustfmt exited with: |
542 | Status: {} | ||
543 | stdout: {}"#, | ||
535 | output.status, | 544 | output.status, |
536 | captured_stdout, | 545 | captured_stdout, |
537 | ); | 546 | ); |
diff --git a/crates/ra_lsp_server/src/project_model/cargo_workspace.rs b/crates/ra_lsp_server/src/project_model/cargo_workspace.rs index 75ae78bca..8cf99d586 100644 --- a/crates/ra_lsp_server/src/project_model/cargo_workspace.rs +++ b/crates/ra_lsp_server/src/project_model/cargo_workspace.rs | |||
@@ -117,9 +117,13 @@ impl Target { | |||
117 | 117 | ||
118 | impl CargoWorkspace { | 118 | impl CargoWorkspace { |
119 | pub fn from_cargo_metadata(cargo_toml: &Path) -> Result<CargoWorkspace> { | 119 | pub fn from_cargo_metadata(cargo_toml: &Path) -> Result<CargoWorkspace> { |
120 | let meta = MetadataCommand::new() | 120 | let mut meta = MetadataCommand::new(); |
121 | .manifest_path(cargo_toml) | 121 | meta.manifest_path(cargo_toml) |
122 | .features(CargoOpt::AllFeatures) | 122 | .features(CargoOpt::AllFeatures); |
123 | if let Some(parent) = cargo_toml.parent() { | ||
124 | meta.current_dir(parent); | ||
125 | } | ||
126 | let meta = meta | ||
123 | .exec() | 127 | .exec() |
124 | .map_err(|e| format_err!("cargo metadata failed: {}", e))?; | 128 | .map_err(|e| format_err!("cargo metadata failed: {}", e))?; |
125 | let mut pkg_by_id = FxHashMap::default(); | 129 | let mut pkg_by_id = FxHashMap::default(); |