about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorEdwin Cheng <edwin0cheng@gmail.com>2019-04-02 13:07:40 +0800
committerEdwin Cheng <edwin0cheng@gmail.com>2019-04-02 15:03:31 +0800
commitee05eafe6c657c3d3710655e11d88d61bc5febf0 (patch)
tree23969e46b774a475e334771b715485287b20d1f8 /editors/code/src
parentb84d0fc1a307f6103ea2c2620a106db821696434 (diff)
downloadrust-ee05eafe6c657c3d3710655e11d88d61bc5febf0.tar.gz
rust-ee05eafe6c657c3d3710655e11d88d61bc5febf0.zip
Add config for cargo-watch trace
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/cargo_watch.ts41
-rw-r--r--editors/code/src/commands/runnables.ts4
-rw-r--r--editors/code/src/config.ts25
3 files changed, 55 insertions, 15 deletions
diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts
index e51cac78a7e..9864ce01ac8 100644
--- a/editors/code/src/commands/cargo_watch.ts
+++ b/editors/code/src/commands/cargo_watch.ts
@@ -1,6 +1,7 @@
 import * as child_process from 'child_process';
 import * as path from 'path';
 import * as vscode from 'vscode';
+import { Server } from '../server';
 import { terminate } from '../utils/processes';
 import { StatusDisplay } from './watch_status';
 
@@ -10,6 +11,7 @@ export class CargoWatchProvider {
     private cargoProcess?: child_process.ChildProcess;
     private outBuffer: string = '';
     private statusDisplay?: StatusDisplay;
+    private outputChannel?: vscode.OutputChannel;
 
     public activate(subscriptions: vscode.Disposable[]) {
         subscriptions.push(this);
@@ -18,7 +20,10 @@ export class CargoWatchProvider {
         );
 
         this.statusDisplay = new StatusDisplay(subscriptions);
-
+        this.outputChannel = vscode.window.createOutputChannel(
+            'Cargo Watch Trace'
+        );
+            
         // Start the cargo watch with json message
         this.cargoProcess = child_process.spawn(
             'cargo',
@@ -31,17 +36,23 @@ export class CargoWatchProvider {
         );
 
         this.cargoProcess.stdout.on('data', (s: string) => {
-            this.processOutput(s);
-            console.log(s);
+            this.processOutput(s, (line) => {
+                this.logInfo(line);
+                this.parseLine(line);
+            });
         });
 
         this.cargoProcess.stderr.on('data', (s: string) => {
-            console.error('Error on cargo watch : ' + s);
+            this.processOutput(s, (line) => {
+                this.logError('Error on cargo-watch : {\n' + line + '}\n' );
+            });
         });
 
         this.cargoProcess.on('error', (err: Error) => {
-            console.error('Error on spawn cargo process : ' + err);
+            this.logError('Error on cargo-watch process : {\n' + err.message + '}\n');
         });
+
+        this.logInfo('cargo-watch started.');
     }
 
     public dispose(): void {
@@ -54,6 +65,22 @@ export class CargoWatchProvider {
             this.cargoProcess.kill();
             terminate(this.cargoProcess);
         }
+
+        if(this.outputChannel) {
+            this.outputChannel.dispose();
+        }
+    }
+
+    private logInfo(line: string) {
+        if (Server.config.cargoWatchOptions.trace === 'verbose') {
+            this.outputChannel!.append(line);
+        }                
+    }
+
+    private logError(line: string) {
+        if (Server.config.cargoWatchOptions.trace === 'error' || Server.config.cargoWatchOptions.trace === 'verbose' ) {
+            this.outputChannel!.append(line);
+        }                
     }
 
     private parseLine(line: string) {
@@ -124,14 +151,14 @@ export class CargoWatchProvider {
         }
     }
 
-    private processOutput(chunk: string) {
+    private processOutput(chunk: string, cb: (line: string) => void  ) {
         // The stdout is not line based, convert it to line based for proceess.
         this.outBuffer += chunk;
         let eolIndex = this.outBuffer.indexOf('\n');
         while (eolIndex >= 0) {
             // line includes the EOL
             const line = this.outBuffer.slice(0, eolIndex + 1);
-            this.parseLine(line);
+            cb(line);
             this.outBuffer = this.outBuffer.slice(eolIndex + 1);
 
             eolIndex = this.outBuffer.indexOf('\n');
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 7bba6f9cb25..3589edceecd 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) {
 export async function interactivelyStartCargoWatch(
     context: vscode.ExtensionContext
 ) {
-    if (Server.config.enableCargoWatchOnStartup === 'disabled') {
+    if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') {
         return;
     }
 
-    if (Server.config.enableCargoWatchOnStartup === 'ask') {
+    if (Server.config.cargoWatchOptions.enableOnStartup === 'ask') {
         const watch = await vscode.window.showInformationMessage(
             'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
             'yes',
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 42058906845..c95d1387800 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -4,14 +4,20 @@ import { Server } from './server';
 
 const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
 
-export type CargoWatchOptions = 'ask' | 'enabled' | 'disabled';
+export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled';
+export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose';
+
+export interface CargoWatchOptions {
+    enableOnStartup: CargoWatchStartupOptions,
+    trace: CargoWatchTraceOptions,
+};
 
 export class Config {
     public highlightingOn = true;
     public enableEnhancedTyping = true;
     public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
     public showWorkspaceLoadedNotification = true;
-    public enableCargoWatchOnStartup: CargoWatchOptions = 'ask';
+    public cargoWatchOptions: CargoWatchOptions = { enableOnStartup: 'ask', trace: 'off' };
 
     private prevEnhancedTyping: null | boolean = null;
 
@@ -73,10 +79,17 @@ export class Config {
         }
 
         if (config.has('enableCargoWatchOnStartup')) {
-            this.enableCargoWatchOnStartup = config.get<CargoWatchOptions>(
-                'enableCargoWatchOnStartup',
-                'ask'
-            );
+            this.cargoWatchOptions.enableOnStartup =
+                config.get<CargoWatchStartupOptions>(
+                    'enableCargoWatchOnStartup',
+                    'ask'
+                );
+            this.cargoWatchOptions.trace =
+                config.get<CargoWatchTraceOptions>(
+                    'trace.cargo-watch',
+                    'off'
+                );
+
         }
     }
 }