diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_lsp_server/src/main_loop | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 18 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/pending_requests.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/subscriptions.rs | 2 |
3 files changed, 15 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 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 | ||
3 | use std::{fmt::Write as _, io::Write as _}; | 4 | use 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 | ||
832 | pub fn publish_decorations( | 840 | pub fn publish_decorations( |
diff --git a/crates/ra_lsp_server/src/main_loop/pending_requests.rs b/crates/ra_lsp_server/src/main_loop/pending_requests.rs index e7ea7aa5b..2d2213464 100644 --- a/crates/ra_lsp_server/src/main_loop/pending_requests.rs +++ b/crates/ra_lsp_server/src/main_loop/pending_requests.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Datastructures that keep track of inflight requests. |
2 | 2 | ||
3 | use std::time::{Duration, Instant}; | 3 | use std::time::{Duration, Instant}; |
4 | 4 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/subscriptions.rs b/crates/ra_lsp_server/src/main_loop/subscriptions.rs index 609b2adcc..b0bae90f5 100644 --- a/crates/ra_lsp_server/src/main_loop/subscriptions.rs +++ b/crates/ra_lsp_server/src/main_loop/subscriptions.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Keeps track of file subscriptions. |
2 | 2 | ||
3 | use ra_ide::FileId; | 3 | use ra_ide::FileId; |
4 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |