diff options
-rw-r--r-- | crates/ra_ide_api/src/runnables.rs | 5 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/cargo_target_spec.rs | 9 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 74 |
3 files changed, 53 insertions, 35 deletions
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 98b1d2d55..53e49da5b 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs | |||
@@ -17,6 +17,7 @@ pub struct Runnable { | |||
17 | pub enum RunnableKind { | 17 | pub enum RunnableKind { |
18 | Test { name: String }, | 18 | Test { name: String }, |
19 | TestMod { path: String }, | 19 | TestMod { path: String }, |
20 | Bench { name: String }, | ||
20 | Bin, | 21 | Bin, |
21 | } | 22 | } |
22 | 23 | ||
@@ -48,6 +49,10 @@ fn runnable_fn(fn_def: &ast::FnDef) -> Option<Runnable> { | |||
48 | RunnableKind::Test { | 49 | RunnableKind::Test { |
49 | name: name.to_string(), | 50 | name: name.to_string(), |
50 | } | 51 | } |
52 | } else if fn_def.has_atom_attr("bench") { | ||
53 | RunnableKind::Bench { | ||
54 | name: name.to_string(), | ||
55 | } | ||
51 | } else { | 56 | } else { |
52 | return None; | 57 | return None; |
53 | }; | 58 | }; |
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs index a66f14b82..db9496bbe 100644 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ b/crates/ra_lsp_server/src/cargo_target_spec.rs | |||
@@ -32,6 +32,15 @@ pub(crate) fn runnable_args( | |||
32 | res.push(path.to_string()); | 32 | res.push(path.to_string()); |
33 | res.push("--nocapture".to_string()); | 33 | res.push("--nocapture".to_string()); |
34 | } | 34 | } |
35 | RunnableKind::Bench { name } => { | ||
36 | res.push("bench".to_string()); | ||
37 | if let Some(spec) = spec { | ||
38 | spec.push_to(&mut res); | ||
39 | } | ||
40 | res.push("--".to_string()); | ||
41 | res.push(name.to_string()); | ||
42 | res.push("--nocapture".to_string()); | ||
43 | } | ||
35 | RunnableKind::Bin => { | 44 | RunnableKind::Bin => { |
36 | res.push("run".to_string()); | 45 | res.push("run".to_string()); |
37 | if let Some(spec) = spec { | 46 | if let Some(spec) = spec { |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a781df181..7326a727d 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -2,22 +2,23 @@ use std::collections::HashMap; | |||
2 | 2 | ||
3 | use gen_lsp_server::ErrorCode; | 3 | use gen_lsp_server::ErrorCode; |
4 | use languageserver_types::{ | 4 | use languageserver_types::{ |
5 | CodeActionResponse, Command, CodeLens, Diagnostic, DiagnosticSeverity, DocumentFormattingParams, | 5 | CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, |
6 | DocumentHighlight, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, | 6 | DocumentFormattingParams, DocumentHighlight, DocumentSymbol, Documentation, FoldingRange, |
7 | FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, | 7 | FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, |
8 | ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, RenameParams, | 8 | MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, |
9 | SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, | 9 | RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, |
10 | WorkspaceEdit, | ||
10 | }; | 11 | }; |
11 | use ra_ide_api::{ | 12 | use ra_ide_api::{ |
12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, RangeInfo, | 13 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, |
13 | }; | 14 | }; |
14 | use ra_syntax::{TextUnit, AstNode}; | 15 | use ra_syntax::{AstNode, TextUnit}; |
15 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
16 | use serde_json::to_value; | 17 | use serde_json::to_value; |
17 | use std::io::Write; | 18 | use std::io::Write; |
18 | 19 | ||
19 | use crate::{ | 20 | use crate::{ |
20 | cargo_target_spec::{CargoTargetSpec, runnable_args}, | 21 | cargo_target_spec::{runnable_args, CargoTargetSpec}, |
21 | conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, | 22 | conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, |
22 | req::{self, Decoration}, | 23 | req::{self, Decoration}, |
23 | server_world::ServerWorld, | 24 | server_world::ServerWorld, |
@@ -258,6 +259,7 @@ pub fn handle_runnables( | |||
258 | label: match &runnable.kind { | 259 | label: match &runnable.kind { |
259 | RunnableKind::Test { name } => format!("test {}", name), | 260 | RunnableKind::Test { name } => format!("test {}", name), |
260 | RunnableKind::TestMod { path } => format!("test-mod {}", path), | 261 | RunnableKind::TestMod { path } => format!("test-mod {}", path), |
262 | RunnableKind::Bench { name } => format!("bench {}", name), | ||
261 | RunnableKind::Bin => "run binary".to_string(), | 263 | RunnableKind::Bin => "run binary".to_string(), |
262 | }, | 264 | }, |
263 | bin: "cargo".to_string(), | 265 | bin: "cargo".to_string(), |
@@ -586,35 +588,37 @@ pub fn handle_code_lens( | |||
586 | let mut lenses: Vec<CodeLens> = Default::default(); | 588 | let mut lenses: Vec<CodeLens> = Default::default(); |
587 | 589 | ||
588 | for runnable in world.analysis().runnables(file_id)? { | 590 | for runnable in world.analysis().runnables(file_id)? { |
589 | match &runnable.kind { | 591 | let title = match &runnable.kind { |
590 | RunnableKind::Test { name: _ } | RunnableKind::TestMod { path: _ } => { | 592 | RunnableKind::Test { name: _ } | RunnableKind::TestMod { path: _ } => Some("Run Test"), |
591 | let args = runnable_args(&world, file_id, &runnable.kind)?; | 593 | RunnableKind::Bench { name: _ } => Some("Run Bench"), |
592 | 594 | _ => None, | |
593 | let range = runnable.range.conv_with(&line_index); | 595 | }; |
594 | |||
595 | // This represents the actual command that will be run. | ||
596 | let r: req::Runnable = req::Runnable { | ||
597 | range, | ||
598 | label: Default::default(), | ||
599 | bin: "cargo".into(), | ||
600 | args, | ||
601 | env: Default::default(), | ||
602 | }; | ||
603 | 596 | ||
604 | let lens = CodeLens { | 597 | if let Some(title) = title { |
605 | range, | 598 | let args = runnable_args(&world, file_id, &runnable.kind)?; |
606 | command: Some(Command { | 599 | let range = runnable.range.conv_with(&line_index); |
607 | title: "Run Test".into(), | 600 | |
608 | command: "ra-lsp.run-single".into(), | 601 | // This represents the actual command that will be run. |
609 | arguments: Some(vec![to_value(r).unwrap()]), | 602 | let r: req::Runnable = req::Runnable { |
610 | }), | 603 | range, |
611 | data: None, | 604 | label: Default::default(), |
612 | }; | 605 | bin: "cargo".into(), |
606 | args, | ||
607 | env: Default::default(), | ||
608 | }; | ||
613 | 609 | ||
614 | lenses.push(lens); | 610 | let lens = CodeLens { |
615 | } | 611 | range, |
616 | _ => continue, | 612 | command: Some(Command { |
617 | }; | 613 | title: title.into(), |
614 | command: "ra-lsp.run-single".into(), | ||
615 | arguments: Some(vec![to_value(r).unwrap()]), | ||
616 | }), | ||
617 | data: None, | ||
618 | }; | ||
619 | |||
620 | lenses.push(lens); | ||
621 | } | ||
618 | } | 622 | } |
619 | 623 | ||
620 | return Ok(Some(lenses)); | 624 | return Ok(Some(lenses)); |