aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/tests
diff options
context:
space:
mode:
authorAleksander Vognild Burkow <[email protected]>2018-12-29 19:09:42 +0000
committerAleksander Vognild Burkow <[email protected]>2018-12-29 20:57:46 +0000
commit8b24f158f75e4496cfc7f8edf9aa41b10dbac9b3 (patch)
treeadd7a233ed590a2f66d0e702e968a4011c9d859e /crates/ra_lsp_server/tests
parent2aac6b0e34ad22374c87435cf125ed4833e9f6fc (diff)
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.
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs56
1 files changed, 54 insertions, 2 deletions
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 @@
1mod support; 1mod support;
2 2
3use serde_json::json; 3use serde_json::json;
4use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; 4use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams, Formatting};
5use languageserver_types::{Position, Range, CodeActionContext}; 5use languageserver_types::{Position, Range, CodeActionContext, DocumentFormattingParams, FormattingOptions};
6 6
7use crate::support::project; 7use crate::support::project;
8 8
@@ -118,6 +118,58 @@ fn test_eggs() {}
118 ); 118 );
119} 119}
120 120
121use std::collections::HashMap;
122#[test]
123fn test_format_document() {
124 let server = project(
125 r#"
126[package]
127name = "foo"
128version = "0.0.0"
129
130//- src/lib.rs
131mod bar;
132
133fn main() {
134}
135
136pub use std::collections::HashMap;
137"#,
138 );
139 server.wait_for_feedback("workspace loaded");
140
141 server.request::<Formatting>(
142 DocumentFormattingParams {
143 text_document: server.doc_id("src/lib.rs"),
144 options: FormattingOptions {
145 tab_size: 4,
146 insert_spaces: false,
147 properties: HashMap::new(),
148 },
149 },
150 json!([
151 {
152 "newText": r#"mod bar;
153
154fn main() {}
155
156pub use std::collections::HashMap;
157"#,
158 "range": {
159 "end": {
160 "character": 0,
161 "line": 6
162 },
163 "start": {
164 "character": 0,
165 "line": 0
166 }
167 }
168 }
169 ]),
170 );
171}
172
121#[test] 173#[test]
122fn test_missing_module_code_action() { 174fn test_missing_module_code_action() {
123 let server = project( 175 let server = project(