diff options
author | Aleksander Vognild Burkow <[email protected]> | 2018-12-29 19:09:42 +0000 |
---|---|---|
committer | Aleksander Vognild Burkow <[email protected]> | 2018-12-29 20:57:46 +0000 |
commit | 8b24f158f75e4496cfc7f8edf9aa41b10dbac9b3 (patch) | |
tree | add7a233ed590a2f66d0e702e968a4011c9d859e /crates/ra_lsp_server/tests | |
parent | 2aac6b0e34ad22374c87435cf125ed4833e9f6fc (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.rs | 56 |
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 @@ | |||
1 | mod support; | 1 | mod support; |
2 | 2 | ||
3 | use serde_json::json; | 3 | use serde_json::json; |
4 | use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; | 4 | use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams, Formatting}; |
5 | use languageserver_types::{Position, Range, CodeActionContext}; | 5 | use languageserver_types::{Position, Range, CodeActionContext, DocumentFormattingParams, FormattingOptions}; |
6 | 6 | ||
7 | use crate::support::project; | 7 | use crate::support::project; |
8 | 8 | ||
@@ -118,6 +118,58 @@ fn test_eggs() {} | |||
118 | ); | 118 | ); |
119 | } | 119 | } |
120 | 120 | ||
121 | use std::collections::HashMap; | ||
122 | #[test] | ||
123 | fn test_format_document() { | ||
124 | let server = project( | ||
125 | r#" | ||
126 | [package] | ||
127 | name = "foo" | ||
128 | version = "0.0.0" | ||
129 | |||
130 | //- src/lib.rs | ||
131 | mod bar; | ||
132 | |||
133 | fn main() { | ||
134 | } | ||
135 | |||
136 | pub 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 | |||
154 | fn main() {} | ||
155 | |||
156 | pub 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] |
122 | fn test_missing_module_code_action() { | 174 | fn test_missing_module_code_action() { |
123 | let server = project( | 175 | let server = project( |