diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-30 10:16:22 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-30 10:16:22 +0000 |
commit | 8d1df9834c96bd464c309383afdd8edea0576ae0 (patch) | |
tree | 1836353cc58c9aeede832bb18872c37af312f377 /crates/ra_lsp_server/tests | |
parent | 75acc25c5a5df2ac0a8978be2972187ee974a754 (diff) | |
parent | 0cb270e75d9501dff9ac6633354ae12d9c0f4260 (diff) |
Merge #358
358: Add support for formatting entire document with rustfmt r=matklad a=aleksanb
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.
Part of https://github.com/rust-analyzer/rust-analyzer/issues/160.
Co-authored-by: Aleksander Vognild Burkow <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 58 |
1 files changed, 56 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..b0e1e65b6 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,60 @@ fn test_eggs() {} | |||
118 | ); | 118 | ); |
119 | } | 119 | } |
120 | 120 | ||
121 | use std::collections::HashMap; | ||
122 | #[test] | ||
123 | fn test_format_document() { | ||
124 | tools::install_rustfmt().unwrap(); | ||
125 | |||
126 | let server = project( | ||
127 | r#" | ||
128 | [package] | ||
129 | name = "foo" | ||
130 | version = "0.0.0" | ||
131 | |||
132 | //- src/lib.rs | ||
133 | mod bar; | ||
134 | |||
135 | fn main() { | ||
136 | } | ||
137 | |||
138 | pub use std::collections::HashMap; | ||
139 | "#, | ||
140 | ); | ||
141 | server.wait_for_feedback("workspace loaded"); | ||
142 | |||
143 | server.request::<Formatting>( | ||
144 | DocumentFormattingParams { | ||
145 | text_document: server.doc_id("src/lib.rs"), | ||
146 | options: FormattingOptions { | ||
147 | tab_size: 4, | ||
148 | insert_spaces: false, | ||
149 | properties: HashMap::new(), | ||
150 | }, | ||
151 | }, | ||
152 | json!([ | ||
153 | { | ||
154 | "newText": r#"mod bar; | ||
155 | |||
156 | fn main() {} | ||
157 | |||
158 | pub use std::collections::HashMap; | ||
159 | "#, | ||
160 | "range": { | ||
161 | "end": { | ||
162 | "character": 0, | ||
163 | "line": 6 | ||
164 | }, | ||
165 | "start": { | ||
166 | "character": 0, | ||
167 | "line": 0 | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | ]), | ||
172 | ); | ||
173 | } | ||
174 | |||
121 | #[test] | 175 | #[test] |
122 | fn test_missing_module_code_action() { | 176 | fn test_missing_module_code_action() { |
123 | let server = project( | 177 | let server = project( |