diff options
Diffstat (limited to 'crates/ra_lsp_server/tests')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 65 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 6 |
2 files changed, 69 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 1c099a78f..41c240139 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs | |||
@@ -12,8 +12,9 @@ use ra_lsp_server::req::{ | |||
12 | CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion, | 12 | CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion, |
13 | }; | 13 | }; |
14 | use serde_json::json; | 14 | use serde_json::json; |
15 | use tempfile::TempDir; | ||
15 | 16 | ||
16 | use crate::support::project; | 17 | use crate::support::{project, project_with_tmpdir}; |
17 | 18 | ||
18 | const LOG: &'static str = ""; | 19 | const LOG: &'static str = ""; |
19 | 20 | ||
@@ -258,3 +259,65 @@ fn main() {} | |||
258 | json!([]), | 259 | json!([]), |
259 | ); | 260 | ); |
260 | } | 261 | } |
262 | |||
263 | #[test] | ||
264 | fn test_missing_module_code_action_in_json_project() { | ||
265 | let tmp_dir = TempDir::new().unwrap(); | ||
266 | let code = format!( | ||
267 | r#" | ||
268 | //- rust-project.json | ||
269 | {{ | ||
270 | "roots": [ "{PATH}" ], | ||
271 | "crates": [ {{ "root_module": "{PATH}/src/lib.rs", "deps": [], "edition": "2015" }} ] | ||
272 | }} | ||
273 | |||
274 | //- src/lib.rs | ||
275 | mod bar; | ||
276 | |||
277 | fn main() {} | ||
278 | "#, | ||
279 | PATH = tmp_dir.path().display() | ||
280 | ); | ||
281 | let server = project_with_tmpdir(tmp_dir, &code); | ||
282 | server.wait_for_message("workspace loaded"); | ||
283 | let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; | ||
284 | server.request::<CodeActionRequest>( | ||
285 | CodeActionParams { | ||
286 | text_document: server.doc_id("src/lib.rs"), | ||
287 | range: Range::new(Position::new(0, 4), Position::new(0, 7)), | ||
288 | context: empty_context(), | ||
289 | }, | ||
290 | json!([ | ||
291 | { | ||
292 | "command": { | ||
293 | "arguments": [ | ||
294 | { | ||
295 | "cursorPosition": null, | ||
296 | "label": "create module", | ||
297 | "workspaceEdit": { | ||
298 | "documentChanges": [ | ||
299 | { | ||
300 | "kind": "create", | ||
301 | "uri": "file:///[..]/src/bar.rs" | ||
302 | } | ||
303 | ] | ||
304 | } | ||
305 | } | ||
306 | ], | ||
307 | "command": "rust-analyzer.applySourceChange", | ||
308 | "title": "create module" | ||
309 | }, | ||
310 | "title": "create module" | ||
311 | } | ||
312 | ]), | ||
313 | ); | ||
314 | |||
315 | server.request::<CodeActionRequest>( | ||
316 | CodeActionParams { | ||
317 | text_document: server.doc_id("src/lib.rs"), | ||
318 | range: Range::new(Position::new(2, 4), Position::new(2, 7)), | ||
319 | context: empty_context(), | ||
320 | }, | ||
321 | json!([]), | ||
322 | ); | ||
323 | } | ||
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 8bfc8d622..e02d7858e 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -27,12 +27,16 @@ use ra_lsp_server::{ | |||
27 | }; | 27 | }; |
28 | 28 | ||
29 | pub fn project(fixture: &str) -> Server { | 29 | pub fn project(fixture: &str) -> Server { |
30 | let tmp_dir = TempDir::new().unwrap(); | ||
31 | project_with_tmpdir(tmp_dir, fixture) | ||
32 | } | ||
33 | |||
34 | pub fn project_with_tmpdir(tmp_dir: TempDir, fixture: &str) -> Server { | ||
30 | static INIT: Once = Once::new(); | 35 | static INIT: Once = Once::new(); |
31 | INIT.call_once(|| { | 36 | INIT.call_once(|| { |
32 | let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); | 37 | let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); |
33 | }); | 38 | }); |
34 | 39 | ||
35 | let tmp_dir = TempDir::new().unwrap(); | ||
36 | let mut paths = vec![]; | 40 | let mut paths = vec![]; |
37 | 41 | ||
38 | for entry in parse_fixture(fixture) { | 42 | for entry in parse_fixture(fixture) { |