diff options
author | Aleksey Kladov <[email protected]> | 2020-01-31 12:34:44 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-01-31 12:34:44 +0000 |
commit | 9d5a5211a4ab83fb891c6eb32f6ed6d63b6b027f (patch) | |
tree | 30b6673dd36269294611b295721a603c82fbd3ce /crates/ra_lsp_server | |
parent | e48033d066b26cb9e85c94cf47e6b8e388176e0a (diff) |
Small cleanup
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 666f2ee29..9aa1e7eea 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -1,7 +1,11 @@ | |||
1 | //! This module is responsible for implementing handlers for Lanuage Server Protocol. | 1 | //! This module is responsible for implementing handlers for Lanuage Server Protocol. |
2 | //! The majority of requests are fulfilled by calling into the `ra_ide` crate. | 2 | //! The majority of requests are fulfilled by calling into the `ra_ide` crate. |
3 | 3 | ||
4 | use std::{fmt::Write as _, io::Write as _}; | 4 | use std::{ |
5 | fmt::Write as _, | ||
6 | io::Write as _, | ||
7 | process::{self, Stdio}, | ||
8 | }; | ||
5 | 9 | ||
6 | use either::Either; | 10 | use either::Either; |
7 | use lsp_server::ErrorCode; | 11 | use lsp_server::ErrorCode; |
@@ -582,21 +586,19 @@ pub fn handle_formatting( | |||
582 | let file_line_index = world.analysis().file_line_index(file_id)?; | 586 | let file_line_index = world.analysis().file_line_index(file_id)?; |
583 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); | 587 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); |
584 | 588 | ||
585 | use std::process; | ||
586 | let mut rustfmt = process::Command::new("rustfmt"); | 589 | let mut rustfmt = process::Command::new("rustfmt"); |
587 | if let Some(&crate_id) = crate_ids.first() { | 590 | if let Some(&crate_id) = crate_ids.first() { |
588 | // Assume all crates are in the same edition | 591 | // Assume all crates are in the same edition |
589 | let edition = world.analysis().crate_edition(crate_id)?; | 592 | let edition = world.analysis().crate_edition(crate_id)?; |
590 | rustfmt.args(&["--edition", &edition.to_string()]); | 593 | rustfmt.args(&["--edition", &edition.to_string()]); |
591 | } | 594 | } |
592 | rustfmt.stdin(process::Stdio::piped()).stdout(process::Stdio::piped()); | ||
593 | 595 | ||
594 | if let Ok(path) = params.text_document.uri.to_file_path() { | 596 | if let Ok(path) = params.text_document.uri.to_file_path() { |
595 | if let Some(parent) = path.parent() { | 597 | if let Some(parent) = path.parent() { |
596 | rustfmt.current_dir(parent); | 598 | rustfmt.current_dir(parent); |
597 | } | 599 | } |
598 | } | 600 | } |
599 | let mut rustfmt = rustfmt.spawn()?; | 601 | let mut rustfmt = rustfmt.stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?; |
600 | 602 | ||
601 | rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?; | 603 | rustfmt.stdin.as_mut().unwrap().write_all(file.as_bytes())?; |
602 | 604 | ||