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.ts49
1 files changed, 28 insertions, 21 deletions
diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts
index 59d4ba97a..ac62bdd48 100644
--- a/editors/code/src/commands/cargo_watch.ts
+++ b/editors/code/src/commands/cargo_watch.ts
@@ -9,13 +9,13 @@ import { StatusDisplay } from './watch_status';
9 9
10import { 10import {
11 mapRustDiagnosticToVsCode, 11 mapRustDiagnosticToVsCode,
12 RustDiagnostic 12 RustDiagnostic,
13} from '../utils/diagnostics/rust'; 13} from '../utils/diagnostics/rust';
14import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection'; 14import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection';
15import { areDiagnosticsEqual } from '../utils/diagnostics/vscode'; 15import { areDiagnosticsEqual } from '../utils/diagnostics/vscode';
16 16
17export async function registerCargoWatchProvider( 17export async function registerCargoWatchProvider(
18 subscriptions: vscode.Disposable[] 18 subscriptions: vscode.Disposable[],
19): Promise<CargoWatchProvider | undefined> { 19): Promise<CargoWatchProvider | undefined> {
20 let cargoExists = false; 20 let cargoExists = false;
21 21
@@ -30,7 +30,7 @@ export async function registerCargoWatchProvider(
30 30
31 if (!cargoExists) { 31 if (!cargoExists) {
32 vscode.window.showErrorMessage( 32 vscode.window.showErrorMessage(
33 `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}` 33 `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}`,
34 ); 34 );
35 return; 35 return;
36 } 36 }
@@ -52,13 +52,13 @@ export class CargoWatchProvider implements vscode.Disposable {
52 52
53 constructor() { 53 constructor() {
54 this.diagnosticCollection = vscode.languages.createDiagnosticCollection( 54 this.diagnosticCollection = vscode.languages.createDiagnosticCollection(
55 'rustc' 55 'rustc',
56 ); 56 );
57 this.statusDisplay = new StatusDisplay( 57 this.statusDisplay = new StatusDisplay(
58 Server.config.cargoWatchOptions.command 58 Server.config.cargoWatchOptions.command,
59 ); 59 );
60 this.outputChannel = vscode.window.createOutputChannel( 60 this.outputChannel = vscode.window.createOutputChannel(
61 'Cargo Watch Trace' 61 'Cargo Watch Trace',
62 ); 62 );
63 63
64 // Track `rustc`'s suggested fixes so we can convert them to code actions 64 // Track `rustc`'s suggested fixes so we can convert them to code actions
@@ -68,22 +68,24 @@ export class CargoWatchProvider implements vscode.Disposable {
68 this.suggestedFixCollection, 68 this.suggestedFixCollection,
69 { 69 {
70 providedCodeActionKinds: 70 providedCodeActionKinds:
71 SuggestedFixCollection.PROVIDED_CODE_ACTION_KINDS 71 SuggestedFixCollection.PROVIDED_CODE_ACTION_KINDS,
72 } 72 },
73 ); 73 );
74 } 74 }
75 75
76 public start() { 76 public start() {
77 if (this.cargoProcess) { 77 if (this.cargoProcess) {
78 vscode.window.showInformationMessage( 78 vscode.window.showInformationMessage(
79 'Cargo Watch is already running' 79 'Cargo Watch is already running',
80 ); 80 );
81 return; 81 return;
82 } 82 }
83 83
84 let args = 84 let args =
85 Server.config.cargoWatchOptions.command + 85 Server.config.cargoWatchOptions.command + ' --message-format json';
86 ' --all-targets --message-format json'; 86 if (Server.config.cargoWatchOptions.allTargets) {
87 args += ' --all-targets';
88 }
87 if (Server.config.cargoWatchOptions.command.length > 0) { 89 if (Server.config.cargoWatchOptions.command.length > 0) {
88 // Excape the double quote string: 90 // Excape the double quote string:
89 args += ' ' + Server.config.cargoWatchOptions.arguments; 91 args += ' ' + Server.config.cargoWatchOptions.arguments;
@@ -95,7 +97,7 @@ export class CargoWatchProvider implements vscode.Disposable {
95 97
96 const ignoreFlags = Server.config.cargoWatchOptions.ignore.reduce( 98 const ignoreFlags = Server.config.cargoWatchOptions.ignore.reduce(
97 (flags, pattern) => [...flags, '--ignore', pattern], 99 (flags, pattern) => [...flags, '--ignore', pattern],
98 [] as string[] 100 [] as string[],
99 ); 101 );
100 102
101 // Start the cargo watch with json message 103 // Start the cargo watch with json message
@@ -105,12 +107,17 @@ export class CargoWatchProvider implements vscode.Disposable {
105 { 107 {
106 stdio: ['ignore', 'pipe', 'pipe'], 108 stdio: ['ignore', 'pipe', 'pipe'],
107 cwd: vscode.workspace.rootPath, 109 cwd: vscode.workspace.rootPath,
108 windowsVerbatimArguments: true 110 windowsVerbatimArguments: true,
109 } 111 },
110 ); 112 );
111 113
114 if (!this.cargoProcess) {
115 vscode.window.showErrorMessage('Cargo Watch failed to start');
116 return;
117 }
118
112 const stdoutData = new LineBuffer(); 119 const stdoutData = new LineBuffer();
113 this.cargoProcess.stdout.on('data', (s: string) => { 120 this.cargoProcess.stdout?.on('data', (s: string) => {
114 stdoutData.processOutput(s, line => { 121 stdoutData.processOutput(s, line => {
115 this.logInfo(line); 122 this.logInfo(line);
116 try { 123 try {
@@ -122,7 +129,7 @@ export class CargoWatchProvider implements vscode.Disposable {
122 }); 129 });
123 130
124 const stderrData = new LineBuffer(); 131 const stderrData = new LineBuffer();
125 this.cargoProcess.stderr.on('data', (s: string) => { 132 this.cargoProcess.stderr?.on('data', (s: string) => {
126 stderrData.processOutput(s, line => { 133 stderrData.processOutput(s, line => {
127 this.logError('Error on cargo-watch : {\n' + line + '}\n'); 134 this.logError('Error on cargo-watch : {\n' + line + '}\n');
128 }); 135 });
@@ -130,7 +137,7 @@ export class CargoWatchProvider implements vscode.Disposable {
130 137
131 this.cargoProcess.on('error', (err: Error) => { 138 this.cargoProcess.on('error', (err: Error) => {
132 this.logError( 139 this.logError(
133 'Error on cargo-watch process : {\n' + err.message + '}\n' 140 'Error on cargo-watch process : {\n' + err.message + '}\n',
134 ); 141 );
135 }); 142 });
136 143
@@ -223,12 +230,12 @@ export class CargoWatchProvider implements vscode.Disposable {
223 const fileUri = location.uri; 230 const fileUri = location.uri;
224 231
225 const diagnostics: vscode.Diagnostic[] = [ 232 const diagnostics: vscode.Diagnostic[] = [
226 ...(this.diagnosticCollection!.get(fileUri) || []) 233 ...(this.diagnosticCollection!.get(fileUri) || []),
227 ]; 234 ];
228 235
229 // If we're building multiple targets it's possible we've already seen this diagnostic 236 // If we're building multiple targets it's possible we've already seen this diagnostic
230 const isDuplicate = diagnostics.some(d => 237 const isDuplicate = diagnostics.some(d =>
231 areDiagnosticsEqual(d, diagnostic) 238 areDiagnosticsEqual(d, diagnostic),
232 ); 239 );
233 if (isDuplicate) { 240 if (isDuplicate) {
234 return; 241 return;
@@ -241,7 +248,7 @@ export class CargoWatchProvider implements vscode.Disposable {
241 for (const suggestedFix of suggestedFixes) { 248 for (const suggestedFix of suggestedFixes) {
242 this.suggestedFixCollection.addSuggestedFixForDiagnostic( 249 this.suggestedFixCollection.addSuggestedFixForDiagnostic(
243 suggestedFix, 250 suggestedFix,
244 diagnostic 251 diagnostic,
245 ); 252 );
246 } 253 }
247 254
@@ -249,7 +256,7 @@ export class CargoWatchProvider implements vscode.Disposable {
249 vscode.commands.executeCommand( 256 vscode.commands.executeCommand(
250 'vscode.executeCodeActionProvider', 257 'vscode.executeCodeActionProvider',
251 fileUri, 258 fileUri,
252 diagnostic.range 259 diagnostic.range,
253 ); 260 );
254 } 261 }
255 } 262 }