From 8b24f158f75e4496cfc7f8edf9aa41b10dbac9b3 Mon Sep 17 00:00:00 2001 From: Aleksander Vognild Burkow Date: Sat, 29 Dec 2018 20:09:42 +0100 Subject: Add support for formatting entire document with rustfmt Attempting to format a document when rustfmt isn't installed will result in an error being returned to the frontend. An alternative implementation would be returning zero replacements. --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 56 +++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'crates/ra_lsp_server/tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 1f5cc5e8b..e9f02a6e4 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -1,8 +1,8 @@ mod support; use serde_json::json; -use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; -use languageserver_types::{Position, Range, CodeActionContext}; +use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams, Formatting}; +use languageserver_types::{Position, Range, CodeActionContext, DocumentFormattingParams, FormattingOptions}; use crate::support::project; @@ -118,6 +118,58 @@ fn test_eggs() {} ); } +use std::collections::HashMap; +#[test] +fn test_format_document() { + let server = project( + r#" +[package] +name = "foo" +version = "0.0.0" + +//- src/lib.rs +mod bar; + +fn main() { +} + +pub use std::collections::HashMap; +"#, + ); + server.wait_for_feedback("workspace loaded"); + + server.request::( + DocumentFormattingParams { + text_document: server.doc_id("src/lib.rs"), + options: FormattingOptions { + tab_size: 4, + insert_spaces: false, + properties: HashMap::new(), + }, + }, + json!([ + { + "newText": r#"mod bar; + +fn main() {} + +pub use std::collections::HashMap; +"#, + "range": { + "end": { + "character": 0, + "line": 6 + }, + "start": { + "character": 0, + "line": 0 + } + } + } + ]), + ); +} + #[test] fn test_missing_module_code_action() { let server = project( -- cgit v1.2.3