diff options
author | Edwin Cheng <[email protected]> | 2019-04-02 06:07:40 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-04-02 08:03:31 +0100 |
commit | ee05eafe6c657c3d3710655e11d88d61bc5febf0 (patch) | |
tree | 23969e46b774a475e334771b715485287b20d1f8 /editors | |
parent | b84d0fc1a307f6103ea2c2620a106db821696434 (diff) |
Add config for cargo-watch trace
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package.json | 11 | ||||
-rw-r--r-- | editors/code/src/commands/cargo_watch.ts | 41 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 4 | ||||
-rw-r--r-- | editors/code/src/config.ts | 25 |
4 files changed, 66 insertions, 15 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index ba9c9433a..cc364d478 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -194,6 +194,17 @@ | |||
194 | ], | 194 | ], |
195 | "default": "off", | 195 | "default": "off", |
196 | "description": "Trace requests to the ra_lsp_server" | 196 | "description": "Trace requests to the ra_lsp_server" |
197 | }, | ||
198 | "rust-analyzer.trace.cargo-watch": { | ||
199 | "type": "string", | ||
200 | "scope": "window", | ||
201 | "enum": [ | ||
202 | "off", | ||
203 | "error", | ||
204 | "verbose" | ||
205 | ], | ||
206 | "default": "off", | ||
207 | "description": "Trace output of cargo-watch" | ||
197 | } | 208 | } |
198 | } | 209 | } |
199 | }, | 210 | }, |
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', |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 420589068..c95d13878 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -4,14 +4,20 @@ import { Server } from './server'; | |||
4 | 4 | ||
5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
6 | 6 | ||
7 | export type CargoWatchOptions = 'ask' | 'enabled' | 'disabled'; | 7 | export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled'; |
8 | export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose'; | ||
9 | |||
10 | export interface CargoWatchOptions { | ||
11 | enableOnStartup: CargoWatchStartupOptions, | ||
12 | trace: CargoWatchTraceOptions, | ||
13 | }; | ||
8 | 14 | ||
9 | export class Config { | 15 | export class Config { |
10 | public highlightingOn = true; | 16 | public highlightingOn = true; |
11 | public enableEnhancedTyping = true; | 17 | public enableEnhancedTyping = true; |
12 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | 18 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; |
13 | public showWorkspaceLoadedNotification = true; | 19 | public showWorkspaceLoadedNotification = true; |
14 | public enableCargoWatchOnStartup: CargoWatchOptions = 'ask'; | 20 | public cargoWatchOptions: CargoWatchOptions = { enableOnStartup: 'ask', trace: 'off' }; |
15 | 21 | ||
16 | private prevEnhancedTyping: null | boolean = null; | 22 | private prevEnhancedTyping: null | boolean = null; |
17 | 23 | ||
@@ -73,10 +79,17 @@ export class Config { | |||
73 | } | 79 | } |
74 | 80 | ||
75 | if (config.has('enableCargoWatchOnStartup')) { | 81 | if (config.has('enableCargoWatchOnStartup')) { |
76 | this.enableCargoWatchOnStartup = config.get<CargoWatchOptions>( | 82 | this.cargoWatchOptions.enableOnStartup = |
77 | 'enableCargoWatchOnStartup', | 83 | config.get<CargoWatchStartupOptions>( |
78 | 'ask' | 84 | 'enableCargoWatchOnStartup', |
79 | ); | 85 | 'ask' |
86 | ); | ||
87 | this.cargoWatchOptions.trace = | ||
88 | config.get<CargoWatchTraceOptions>( | ||
89 | 'trace.cargo-watch', | ||
90 | 'off' | ||
91 | ); | ||
92 | |||
80 | } | 93 | } |
81 | } | 94 | } |
82 | } | 95 | } |