diff options
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/cargo_watch.ts | 41 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 4 |
2 files changed, 36 insertions, 9 deletions
diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index e51cac78a..9864ce01a 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as child_process from 'child_process'; | 1 | import * as child_process from 'child_process'; |
2 | import * as path from 'path'; | 2 | import * as path from 'path'; |
3 | import * as vscode from 'vscode'; | 3 | import * as vscode from 'vscode'; |
4 | import { Server } from '../server'; | ||
4 | import { terminate } from '../utils/processes'; | 5 | import { terminate } from '../utils/processes'; |
5 | import { StatusDisplay } from './watch_status'; | 6 | import { StatusDisplay } from './watch_status'; |
6 | 7 | ||
@@ -10,6 +11,7 @@ export class CargoWatchProvider { | |||
10 | private cargoProcess?: child_process.ChildProcess; | 11 | private cargoProcess?: child_process.ChildProcess; |
11 | private outBuffer: string = ''; | 12 | private outBuffer: string = ''; |
12 | private statusDisplay?: StatusDisplay; | 13 | private statusDisplay?: StatusDisplay; |
14 | private outputChannel?: vscode.OutputChannel; | ||
13 | 15 | ||
14 | public activate(subscriptions: vscode.Disposable[]) { | 16 | public activate(subscriptions: vscode.Disposable[]) { |
15 | subscriptions.push(this); | 17 | subscriptions.push(this); |
@@ -18,7 +20,10 @@ export class CargoWatchProvider { | |||
18 | ); | 20 | ); |
19 | 21 | ||
20 | this.statusDisplay = new StatusDisplay(subscriptions); | 22 | this.statusDisplay = new StatusDisplay(subscriptions); |
21 | 23 | this.outputChannel = vscode.window.createOutputChannel( | |
24 | 'Cargo Watch Trace' | ||
25 | ); | ||
26 | |||
22 | // Start the cargo watch with json message | 27 | // Start the cargo watch with json message |
23 | this.cargoProcess = child_process.spawn( | 28 | this.cargoProcess = child_process.spawn( |
24 | 'cargo', | 29 | 'cargo', |
@@ -31,17 +36,23 @@ export class CargoWatchProvider { | |||
31 | ); | 36 | ); |
32 | 37 | ||
33 | this.cargoProcess.stdout.on('data', (s: string) => { | 38 | this.cargoProcess.stdout.on('data', (s: string) => { |
34 | this.processOutput(s); | 39 | this.processOutput(s, (line) => { |
35 | console.log(s); | 40 | this.logInfo(line); |
41 | this.parseLine(line); | ||
42 | }); | ||
36 | }); | 43 | }); |
37 | 44 | ||
38 | this.cargoProcess.stderr.on('data', (s: string) => { | 45 | this.cargoProcess.stderr.on('data', (s: string) => { |
39 | console.error('Error on cargo watch : ' + s); | 46 | this.processOutput(s, (line) => { |
47 | this.logError('Error on cargo-watch : {\n' + line + '}\n' ); | ||
48 | }); | ||
40 | }); | 49 | }); |
41 | 50 | ||
42 | this.cargoProcess.on('error', (err: Error) => { | 51 | this.cargoProcess.on('error', (err: Error) => { |
43 | console.error('Error on spawn cargo process : ' + err); | 52 | this.logError('Error on cargo-watch process : {\n' + err.message + '}\n'); |
44 | }); | 53 | }); |
54 | |||
55 | this.logInfo('cargo-watch started.'); | ||
45 | } | 56 | } |
46 | 57 | ||
47 | public dispose(): void { | 58 | public dispose(): void { |
@@ -54,6 +65,22 @@ export class CargoWatchProvider { | |||
54 | this.cargoProcess.kill(); | 65 | this.cargoProcess.kill(); |
55 | terminate(this.cargoProcess); | 66 | terminate(this.cargoProcess); |
56 | } | 67 | } |
68 | |||
69 | if(this.outputChannel) { | ||
70 | this.outputChannel.dispose(); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | private logInfo(line: string) { | ||
75 | if (Server.config.cargoWatchOptions.trace === 'verbose') { | ||
76 | this.outputChannel!.append(line); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | private logError(line: string) { | ||
81 | if (Server.config.cargoWatchOptions.trace === 'error' || Server.config.cargoWatchOptions.trace === 'verbose' ) { | ||
82 | this.outputChannel!.append(line); | ||
83 | } | ||
57 | } | 84 | } |
58 | 85 | ||
59 | private parseLine(line: string) { | 86 | private parseLine(line: string) { |
@@ -124,14 +151,14 @@ export class CargoWatchProvider { | |||
124 | } | 151 | } |
125 | } | 152 | } |
126 | 153 | ||
127 | private processOutput(chunk: string) { | 154 | private processOutput(chunk: string, cb: (line: string) => void ) { |
128 | // The stdout is not line based, convert it to line based for proceess. | 155 | // The stdout is not line based, convert it to line based for proceess. |
129 | this.outBuffer += chunk; | 156 | this.outBuffer += chunk; |
130 | let eolIndex = this.outBuffer.indexOf('\n'); | 157 | let eolIndex = this.outBuffer.indexOf('\n'); |
131 | while (eolIndex >= 0) { | 158 | while (eolIndex >= 0) { |
132 | // line includes the EOL | 159 | // line includes the EOL |
133 | const line = this.outBuffer.slice(0, eolIndex + 1); | 160 | const line = this.outBuffer.slice(0, eolIndex + 1); |
134 | this.parseLine(line); | 161 | cb(line); |
135 | this.outBuffer = this.outBuffer.slice(eolIndex + 1); | 162 | this.outBuffer = this.outBuffer.slice(eolIndex + 1); |
136 | 163 | ||
137 | eolIndex = this.outBuffer.indexOf('\n'); | 164 | eolIndex = this.outBuffer.indexOf('\n'); |
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 7bba6f9cb..3589edcee 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -137,11 +137,11 @@ export async function handleSingle(runnable: Runnable) { | |||
137 | export async function interactivelyStartCargoWatch( | 137 | export async function interactivelyStartCargoWatch( |
138 | context: vscode.ExtensionContext | 138 | context: vscode.ExtensionContext |
139 | ) { | 139 | ) { |
140 | if (Server.config.enableCargoWatchOnStartup === 'disabled') { | 140 | if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') { |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | 143 | ||
144 | if (Server.config.enableCargoWatchOnStartup === 'ask') { | 144 | if (Server.config.cargoWatchOptions.enableOnStartup === 'ask') { |
145 | const watch = await vscode.window.showInformationMessage( | 145 | const watch = await vscode.window.showInformationMessage( |
146 | 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', | 146 | 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', |
147 | 'yes', | 147 | 'yes', |