aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-24 11:41:25 +0100
committerAleksey Kladov <[email protected]>2018-08-24 11:41:25 +0100
commit6cade3f6d8ad7bb5a11b1910689b25f709c12502 (patch)
tree96aea3209cc310462c37708d5623fe1f1d667634 /crates/server/src
parent89e56c364f3d0a9d5a12ae488185abc1ea69df4a (diff)
Runnig tests somehow
Diffstat (limited to 'crates/server/src')
-rw-r--r--crates/server/src/main_loop/handlers.rs61
1 files changed, 51 insertions, 10 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index ae362ddaa..b68e93e46 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -5,10 +5,13 @@ use languageserver_types::{
5 Command, TextDocumentIdentifier, WorkspaceEdit, 5 Command, TextDocumentIdentifier, WorkspaceEdit,
6 SymbolInformation, Position, Location, TextEdit, 6 SymbolInformation, Position, Location, TextEdit,
7}; 7};
8use serde_json::{to_value, from_value};
8use libanalysis::{Query}; 9use libanalysis::{Query};
9use libeditor; 10use libeditor;
10use libsyntax2::TextUnit; 11use libsyntax2::{
11use serde_json::{to_value, from_value}; 12 TextUnit,
13 text_utils::contains_offset_nonstrict,
14};
12 15
13use ::{ 16use ::{
14 req::{self, Decoration}, Result, 17 req::{self, Decoration}, Result,
@@ -117,7 +120,7 @@ pub fn handle_code_action(
117 let file = world.analysis().file_syntax(file_id)?; 120 let file = world.analysis().file_syntax(file_id)?;
118 let line_index = world.analysis().file_line_index(file_id)?; 121 let line_index = world.analysis().file_line_index(file_id)?;
119 let offset = params.range.conv_with(&line_index).start(); 122 let offset = params.range.conv_with(&line_index).start();
120 let mut ret = Vec::new(); 123 let mut res = Vec::new();
121 124
122 let actions = &[ 125 let actions = &[
123 (ActionId::FlipComma, libeditor::flip_comma(&file, offset).is_some()), 126 (ActionId::FlipComma, libeditor::flip_comma(&file, offset).is_some()),
@@ -128,10 +131,52 @@ pub fn handle_code_action(
128 for (id, edit) in actions { 131 for (id, edit) in actions {
129 if *edit { 132 if *edit {
130 let cmd = apply_code_action_cmd(*id, params.text_document.clone(), offset); 133 let cmd = apply_code_action_cmd(*id, params.text_document.clone(), offset);
131 ret.push(cmd); 134 res.push(cmd);
135 }
136 }
137 for runnable in libeditor::runnables(&file) {
138 if !contains_offset_nonstrict(runnable.range, offset) {
139 continue;
140 }
141
142 #[derive(Serialize)]
143 struct ProcessSpec {
144 bin: String,
145 args: Vec<String>,
146 env: HashMap<String, String>,
132 } 147 }
148
149 let spec = ProcessSpec {
150 bin: "cargo".to_string(),
151 args: match runnable.kind {
152 libeditor::RunnableKind::Test { name } => {
153 vec![
154 "test".to_string(),
155 "--".to_string(),
156 name,
157 "--nocapture".to_string(),
158 ]
159 }
160 libeditor::RunnableKind::Bin => vec!["run".to_string()]
161 },
162 env: {
163 let mut m = HashMap::new();
164 m.insert(
165 "RUST_BACKTRACE".to_string(),
166 "short".to_string(),
167 );
168 m
169 }
170 };
171
172 let cmd = Command {
173 title: "Run ...".to_string(),
174 command: "libsyntax-rust.run".to_string(),
175 arguments: Some(vec![to_value(spec).unwrap()]),
176 };
177 res.push(cmd);
133 } 178 }
134 return Ok(Some(ret)); 179 return Ok(Some(res));
135} 180}
136 181
137pub fn handle_workspace_symbol( 182pub fn handle_workspace_symbol(
@@ -257,11 +302,7 @@ struct ActionRequest {
257} 302}
258 303
259fn apply_code_action_cmd(id: ActionId, doc: TextDocumentIdentifier, offset: TextUnit) -> Command { 304fn apply_code_action_cmd(id: ActionId, doc: TextDocumentIdentifier, offset: TextUnit) -> Command {
260 let action_request = ActionRequest { 305 let action_request = ActionRequest { id, text_document: doc, offset };
261 id,
262 text_document: doc,
263 offset,
264 };
265 Command { 306 Command {
266 title: id.title().to_string(), 307 title: id.title().to_string(),
267 command: "apply_code_action".to_string(), 308 command: "apply_code_action".to_string(),