Add test for code actions

This commit is contained in:
Florian Diebold 2018-12-06 21:26:23 +01:00
parent 1dfd06fc8a
commit 29793e7de9

View file

@ -2,7 +2,9 @@ mod support;
use serde_json::json; 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; 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::<CodeActionRequest>(
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::<CodeActionRequest>(
CodeActionParams {
text_document: server.doc_id("src/lib.rs"),
range: Range::new(Position::new(2, 0), Position::new(2, 7)),
context: empty_context(),
},
json!([]),
);
}