aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/cargo_watch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/cargo_watch.ts')
-rw-r--r--editors/code/src/commands/cargo_watch.ts41
1 files changed, 34 insertions, 7 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 @@
1import * as child_process from 'child_process'; 1import * as child_process from 'child_process';
2import * as path from 'path'; 2import * as path from 'path';
3import * as vscode from 'vscode'; 3import * as vscode from 'vscode';
4import { Server } from '../server';
4import { terminate } from '../utils/processes'; 5import { terminate } from '../utils/processes';
5import { StatusDisplay } from './watch_status'; 6import { 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');