diff options
author | Jesse Bakker <[email protected]> | 2020-12-31 12:05:19 +0000 |
---|---|---|
committer | Jesse Bakker <[email protected]> | 2020-12-31 14:33:20 +0000 |
commit | f355a6d8319408a3cc349be399d9e69985737c42 (patch) | |
tree | e527a3297191ab0a5d9450ecfb12f71f7a51e5ee /crates/rust-analyzer/src/handlers.rs | |
parent | 9bb9fbab3ab603150990ef8f2df12bddc7104058 (diff) |
Split textDocument/formatting TextEdit with diff
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 66f8bee99..ec37fba04 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -29,6 +29,7 @@ use serde_json::to_value; | |||
29 | use stdx::{format_to, split_once}; | 29 | use stdx::{format_to, split_once}; |
30 | use syntax::{algo, ast, AstNode, TextRange, TextSize}; | 30 | use syntax::{algo, ast, AstNode, TextRange, TextSize}; |
31 | 31 | ||
32 | use crate::diff::diff; | ||
32 | use crate::{ | 33 | use crate::{ |
33 | cargo_target_spec::CargoTargetSpec, | 34 | cargo_target_spec::CargoTargetSpec, |
34 | config::RustfmtConfig, | 35 | config::RustfmtConfig, |
@@ -799,7 +800,7 @@ pub(crate) fn handle_formatting( | |||
799 | let crate_ids = snap.analysis.crate_for(file_id)?; | 800 | let crate_ids = snap.analysis.crate_for(file_id)?; |
800 | 801 | ||
801 | let file_line_index = snap.analysis.file_line_index(file_id)?; | 802 | let file_line_index = snap.analysis.file_line_index(file_id)?; |
802 | let end_position = to_proto::position(&file_line_index, TextSize::of(file.as_str())); | 803 | let file_line_endings = snap.file_line_endings(file_id); |
803 | 804 | ||
804 | let mut rustfmt = match &snap.config.rustfmt { | 805 | let mut rustfmt = match &snap.config.rustfmt { |
805 | RustfmtConfig::Rustfmt { extra_args } => { | 806 | RustfmtConfig::Rustfmt { extra_args } => { |
@@ -858,10 +859,11 @@ pub(crate) fn handle_formatting( | |||
858 | // The document is already formatted correctly -- no edits needed. | 859 | // The document is already formatted correctly -- no edits needed. |
859 | Ok(None) | 860 | Ok(None) |
860 | } else { | 861 | } else { |
861 | Ok(Some(vec![lsp_types::TextEdit { | 862 | Ok(Some(to_proto::text_edit_vec( |
862 | range: Range::new(Position::new(0, 0), end_position), | 863 | &file_line_index, |
863 | new_text: captured_stdout, | 864 | file_line_endings, |
864 | }])) | 865 | diff(&file, &captured_stdout), |
866 | ))) | ||
865 | } | 867 | } |
866 | } | 868 | } |
867 | 869 | ||