aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index c81fa7f67..39eb3df3e 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -1,4 +1,5 @@
1//! FIXME: write short doc here 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 3
3use std::{fmt::Write as _, io::Write as _}; 4use std::{fmt::Write as _, io::Write as _};
4 5
@@ -164,7 +165,7 @@ pub fn handle_on_type_formatting(
164 165
165 // in `ra_ide`, the `on_type` invariant is that 166 // in `ra_ide`, the `on_type` invariant is that
166 // `text.char_at(position) == typed_char`. 167 // `text.char_at(position) == typed_char`.
167 position.offset = position.offset - TextUnit::of_char('.'); 168 position.offset -= TextUnit::of_char('.');
168 let char_typed = params.ch.chars().next().unwrap_or('\0'); 169 let char_typed = params.ch.chars().next().unwrap_or('\0');
169 170
170 // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`, 171 // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
@@ -480,8 +481,6 @@ pub fn handle_prepare_rename(
480 let _p = profile("handle_prepare_rename"); 481 let _p = profile("handle_prepare_rename");
481 let position = params.try_conv_with(&world)?; 482 let position = params.try_conv_with(&world)?;
482 483
483 // We support renaming references like handle_rename does.
484 // In the future we may want to reject the renaming of things like keywords here too.
485 let optional_change = world.analysis().rename(position, "dummy")?; 484 let optional_change = world.analysis().rename(position, "dummy")?;
486 let range = match optional_change { 485 let range = match optional_change {
487 None => return Ok(None), 486 None => return Ok(None),
@@ -557,12 +556,18 @@ pub fn handle_formatting(
557 let _p = profile("handle_formatting"); 556 let _p = profile("handle_formatting");
558 let file_id = params.text_document.try_conv_with(&world)?; 557 let file_id = params.text_document.try_conv_with(&world)?;
559 let file = world.analysis().file_text(file_id)?; 558 let file = world.analysis().file_text(file_id)?;
559 let crate_ids = world.analysis().crate_for(file_id)?;
560 560
561 let file_line_index = world.analysis().file_line_index(file_id)?; 561 let file_line_index = world.analysis().file_line_index(file_id)?;
562 let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); 562 let end_position = TextUnit::of_str(&file).conv_with(&file_line_index);
563 563
564 use std::process; 564 use std::process;
565 let mut rustfmt = process::Command::new("rustfmt"); 565 let mut rustfmt = process::Command::new("rustfmt");
566 if let Some(&crate_id) = crate_ids.first() {
567 // Assume all crates are in the same edition
568 let edition = world.analysis().crate_edition(crate_id)?;
569 rustfmt.args(&["--edition", &edition.to_string()]);
570 }
566 rustfmt.stdin(process::Stdio::piped()).stdout(process::Stdio::piped()); 571 rustfmt.stdin(process::Stdio::piped()).stdout(process::Stdio::piped());
567 572
568 if let Ok(path) = params.text_document.uri.to_file_path() { 573 if let Ok(path) = params.text_document.uri.to_file_path() {
@@ -644,6 +649,7 @@ pub fn handle_code_action(
644 diagnostics: None, 649 diagnostics: None,
645 edit: None, 650 edit: None,
646 command: Some(command), 651 command: Some(command),
652 is_preferred: None,
647 }; 653 };
648 res.push(action.into()); 654 res.push(action.into());
649 } 655 }
@@ -666,6 +672,7 @@ pub fn handle_code_action(
666 diagnostics: None, 672 diagnostics: None,
667 edit: None, 673 edit: None,
668 command: Some(command), 674 command: Some(command),
675 is_preferred: None,
669 }; 676 };
670 res.push(action.into()); 677 res.push(action.into());
671 } 678 }
@@ -824,9 +831,10 @@ pub fn publish_diagnostics(
824 source: Some("rust-analyzer".to_string()), 831 source: Some("rust-analyzer".to_string()),
825 message: d.message, 832 message: d.message,
826 related_information: None, 833 related_information: None,
834 tags: None,
827 }) 835 })
828 .collect(); 836 .collect();
829 Ok(req::PublishDiagnosticsParams { uri, diagnostics }) 837 Ok(req::PublishDiagnosticsParams { uri, diagnostics, version: None })
830} 838}
831 839
832pub fn publish_decorations( 840pub fn publish_decorations(