From 29793e7de978c9f0fa2d46bad624fc49d2506b11 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 6 Dec 2018 21:26:23 +0100 Subject: Add test for code actions --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 63d53fb01..26f5e3f20 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -2,7 +2,9 @@ mod support; use serde_json::json; -use ra_lsp_server::req::{Runnables, RunnablesParams}; +use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; + +use languageserver_types::{Position, Range, CodeActionContext}; use crate::support::project; @@ -116,3 +118,60 @@ fn test_eggs() {} ]) ); } + +#[test] +fn test_missing_module_code_action() { + let server = project( + r#" +//- Cargo.toml +[package] +name = "foo" +version = "0.0.0" + +//- src/lib.rs +mod bar; + +fn main() {} +"#, + ); + server.wait_for_feedback("workspace loaded"); + let empty_context = || CodeActionContext { + diagnostics: Vec::new(), + only: None, + }; + server.request::( + CodeActionParams { + text_document: server.doc_id("src/lib.rs"), + range: Range::new(Position::new(0, 0), Position::new(0, 7)), + context: empty_context(), + }, + json!([ + { + "arguments": [ + { + "cursorPosition": null, + "fileSystemEdits": [ + { + "type": "createFile", + "uri": "file:///[..]/src/bar.rs" + } + ], + "label": "create module", + "sourceFileEdits": [] + } + ], + "command": "ra-lsp.applySourceChange", + "title": "create module" + } + ]), + ); + + server.request::( + CodeActionParams { + text_document: server.doc_id("src/lib.rs"), + range: Range::new(Position::new(2, 0), Position::new(2, 7)), + context: empty_context(), + }, + json!([]), + ); +} -- cgit v1.2.3