aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src')
-rw-r--r--crates/server/src/main_loop/handlers.rs50
-rw-r--r--crates/server/src/main_loop/mod.rs4
-rw-r--r--crates/server/src/req.rs27
3 files changed, 81 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,
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index 5213ecc04..6d6ca6ae9 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -29,6 +29,7 @@ use {
29 handle_parent_module, 29 handle_parent_module,
30 handle_join_lines, 30 handle_join_lines,
31 handle_completion, 31 handle_completion,
32 handle_runnables,
32 }, 33 },
33}; 34};
34 35
@@ -138,6 +139,9 @@ fn on_request(
138 handle_request_on_threadpool::<req::CodeActionRequest>( 139 handle_request_on_threadpool::<req::CodeActionRequest>(
139 &mut req, pool, world, sender, handle_code_action, 140 &mut req, pool, world, sender, handle_code_action,
140 )?; 141 )?;
142 handle_request_on_threadpool::<req::Runnables>(
143 &mut req, pool, world, sender, handle_runnables,
144 )?;
141 handle_request_on_threadpool::<req::WorkspaceSymbol>( 145 handle_request_on_threadpool::<req::WorkspaceSymbol>(
142 &mut req, pool, world, sender, handle_workspace_symbol, 146 &mut req, pool, world, sender, handle_workspace_symbol,
143 )?; 147 )?;
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs
index 6d3466b66..e4138abba 100644
--- a/crates/server/src/req.rs
+++ b/crates/server/src/req.rs
@@ -1,3 +1,5 @@
1use std::collections::HashMap;
2
1use serde::{ser::Serialize, de::DeserializeOwned}; 3use serde::{ser::Serialize, de::DeserializeOwned};
2use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location}; 4use languageserver_types::{TextDocumentIdentifier, Range, Url, Position, Location};
3use url_serde; 5use url_serde;
@@ -134,3 +136,28 @@ pub struct JoinLinesParams {
134 pub text_document: TextDocumentIdentifier, 136 pub text_document: TextDocumentIdentifier,
135 pub range: Range, 137 pub range: Range,
136} 138}
139
140pub enum Runnables {}
141
142impl Request for Runnables {
143 type Params = RunnablesParams;
144 type Result = Vec<Runnable>;
145 const METHOD: &'static str = "m/joinLines";
146}
147
148#[derive(Deserialize, Debug)]
149#[serde(rename_all = "camelCase")]
150pub struct RunnablesParams {
151 pub text_document: TextDocumentIdentifier,
152 pub position: Option<Position>,
153}
154
155#[derive(Serialize, Debug)]
156#[serde(rename_all = "camelCase")]
157pub struct Runnable {
158 pub range: Range,
159 pub label: String,
160 pub bin: String,
161 pub args: Vec<String>,
162 pub env: HashMap<String, String>,
163}