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 | ||||
-rw-r--r-- | editors/code/src/commands/apply_source_change.ts | 4 | ||||
-rw-r--r-- | editors/code/src/commands/on_enter.ts | 1 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 14 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 6 |
7 files changed, 69 insertions, 44 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)); |
diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts index d96ace979..675a534c8 100644 --- a/editors/code/src/commands/apply_source_change.ts +++ b/editors/code/src/commands/apply_source_change.ts | |||
@@ -10,7 +10,9 @@ export interface SourceChange { | |||
10 | } | 10 | } |
11 | 11 | ||
12 | export async function handle(change: SourceChange) { | 12 | export async function handle(change: SourceChange) { |
13 | const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit(change.workspaceEdit); | 13 | const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit( |
14 | change.workspaceEdit | ||
15 | ); | ||
14 | let created; | 16 | let created; |
15 | let moved; | 17 | let moved; |
16 | if (change.workspaceEdit.documentChanges) { | 18 | if (change.workspaceEdit.documentChanges) { |
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 64401b684..bb376e3cb 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts | |||
@@ -6,7 +6,6 @@ import { | |||
6 | SourceChange | 6 | SourceChange |
7 | } from './apply_source_change'; | 7 | } from './apply_source_change'; |
8 | 8 | ||
9 | |||
10 | export async function handle(event: { text: string }): Promise<boolean> { | 9 | export async function handle(event: { text: string }): Promise<boolean> { |
11 | const editor = vscode.window.activeTextEditor; | 10 | const editor = vscode.window.activeTextEditor; |
12 | if ( | 11 | if ( |
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index f9a4e2fc9..aa5817c21 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -48,7 +48,11 @@ function createTask(spec: Runnable): vscode.Task { | |||
48 | cwd: '.', | 48 | cwd: '.', |
49 | env: definition.env | 49 | env: definition.env |
50 | }; | 50 | }; |
51 | const exec = new vscode.ShellExecution(definition.command, definition.args, execOption); | 51 | const exec = new vscode.ShellExecution( |
52 | definition.command, | ||
53 | definition.args, | ||
54 | execOption | ||
55 | ); | ||
52 | 56 | ||
53 | const f = vscode.workspace.workspaceFolders![0]; | 57 | const f = vscode.workspace.workspaceFolders![0]; |
54 | const t = new vscode.Task( | 58 | const t = new vscode.Task( |
@@ -59,7 +63,7 @@ function createTask(spec: Runnable): vscode.Task { | |||
59 | exec, | 63 | exec, |
60 | ['$rustc'] | 64 | ['$rustc'] |
61 | ); | 65 | ); |
62 | t.presentationOptions.clear = true | 66 | t.presentationOptions.clear = true; |
63 | return t; | 67 | return t; |
64 | } | 68 | } |
65 | 69 | ||
@@ -114,8 +118,8 @@ export async function handleSingle(runnable: Runnable) { | |||
114 | task.group = vscode.TaskGroup.Build; | 118 | task.group = vscode.TaskGroup.Build; |
115 | task.presentationOptions = { | 119 | task.presentationOptions = { |
116 | reveal: vscode.TaskRevealKind.Always, | 120 | reveal: vscode.TaskRevealKind.Always, |
117 | panel: vscode.TaskPanelKind.Dedicated, | 121 | panel: vscode.TaskPanelKind.Dedicated |
118 | }; | 122 | }; |
119 | 123 | ||
120 | return vscode.tasks.executeTask(task); | 124 | return vscode.tasks.executeTask(task); |
121 | } \ No newline at end of file | 125 | } |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 9edfb13b5..0098c9454 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -37,8 +37,10 @@ export function activate(context: vscode.ExtensionContext) { | |||
37 | return await original(...args); | 37 | return await original(...args); |
38 | } | 38 | } |
39 | }); | 39 | }); |
40 | } catch(_) { | 40 | } catch (_) { |
41 | vscode.window.showWarningMessage('Enhanced typing feature is disabled because of incompatibility with VIM extension'); | 41 | vscode.window.showWarningMessage( |
42 | 'Enhanced typing feature is disabled because of incompatibility with VIM extension' | ||
43 | ); | ||
42 | } | 44 | } |
43 | } | 45 | } |
44 | 46 | ||