aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r--crates/server/src/main_loop/handlers.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index 350eda7df..583af0900 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -204,6 +204,56 @@ pub fn handle_code_action(
204 return Ok(Some(res)); 204 return Ok(Some(res));
205} 205}
206 206
207pub fn handle_runnables(
208 world: ServerWorld,
209 params: req::RunnablesParams,
210) -> Result<Vec<req::Runnable>> {
211 let file_id = params.text_document.try_conv_with(&world)?;
212 let file = world.analysis().file_syntax(file_id)?;
213 let line_index = world.analysis().file_line_index(file_id)?;
214 let offset = params.position.map(|it| it.conv_with(&line_index));
215 let mut res = Vec::new();
216 for runnable in libeditor::runnables(&file) {
217 if let Some(offset) = offset {
218 if !contains_offset_nonstrict(runnable.range, offset) {
219 continue;
220 }
221 }
222
223 let r = req::Runnable {
224 range: runnable.range.conv_with(&line_index),
225 label: match &runnable.kind {
226 libeditor::RunnableKind::Test { name } =>
227 format!("test {}", name),
228 libeditor::RunnableKind::Bin =>
229 "run binary".to_string(),
230 },
231 bin: "cargo".to_string(),
232 args: match runnable.kind {
233 libeditor::RunnableKind::Test { name } => {
234 vec![
235 "test".to_string(),
236 "--".to_string(),
237 name,
238 "--nocapture".to_string(),
239 ]
240 }
241 libeditor::RunnableKind::Bin => vec!["run".to_string()]
242 },
243 env: {
244 let mut m = HashMap::new();
245 m.insert(
246 "RUST_BACKTRACE".to_string(),
247 "short".to_string(),
248 );
249 m
250 }
251 };
252 res.push(r);
253 }
254 return Ok(res);
255}
256
207pub fn handle_workspace_symbol( 257pub fn handle_workspace_symbol(
208 world: ServerWorld, 258 world: ServerWorld,
209 params: req::WorkspaceSymbolParams, 259 params: req::WorkspaceSymbolParams,