diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-26 21:18:52 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-26 21:18:52 +0000 |
commit | 691ffd2dcb687658b99f5968dbccca71e826b6a5 (patch) | |
tree | 3349722543bfee64b009db3c29b90ab546be4207 /crates/ra_lsp_server/src/main_loop | |
parent | 0974e6abeb9c3f047e21c3e23769b93c9e7dcaf3 (diff) | |
parent | 9fbbb8f6096836642704e34e42c9b9ea82807e7c (diff) |
Merge #681
681: Use the correct working directory for cargo metadata and rustfmt r=matklad a=DJMcNab
Fixes maybe #670. @bjorn3, is that true?
(Awkward wording due to GitHub's eager 'fixes' finding)
Co-authored-by: DJMcNab <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 28 |
1 files changed, 20 insertions, 8 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..ace3da020 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -520,21 +520,33 @@ 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 | ||
530 | let output = rustfmt.wait_with_output()?; | 537 | let output = rustfmt.wait_with_output()?; |
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 | return Err(LspError::new( |
534 | "rustfmt exited with error code {}: {}.", | 541 | -32900, |
535 | output.status, | 542 | format!( |
536 | captured_stdout, | 543 | r#"rustfmt exited with: |
537 | ); | 544 | Status: {} |
545 | stdout: {}"#, | ||
546 | output.status, captured_stdout, | ||
547 | ), | ||
548 | ) | ||
549 | .into()); | ||
538 | } | 550 | } |
539 | 551 | ||
540 | Ok(Some(vec![TextEdit { | 552 | Ok(Some(vec![TextEdit { |