Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 5723802

Browse files
committed
Fixed the way json errors are requested from cargo & rustc
Closes #69 Also fixed the way envinronment variables were passed to BufferedProcess -- according to [the documentation](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) (*`BufferedProcess` is actually a wrapper above node's exec*) they should be passed in an `env` subobject of `options`, but they were passed as raw in options object. Adding to these environment variables accordingly set `RUSTFLAGS` variable, when JSON errors are available, makes cargo tell compiler to output JSON errors. When using `rustc` simply providing `--error-format=json` is enough to make compiler do what we want.
1 parent edd2d0f commit 5723802

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/linter-rust.coffee

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class LinterRust
2121
file = @initCmd do textEditor.getPath
2222
curDir = path.dirname file
2323
PATH = path.dirname @cmd[0]
24-
options = JSON.parse JSON.stringify process.env
25-
options.PATH = PATH + path.delimiter + options.PATH
24+
options = new Object
25+
options.env = JSON.parse JSON.stringify process.env
26+
options.env.PATH = PATH + path.delimiter + options.env.PATH
2627
options.cwd = curDir
2728
command = @cmd[0]
2829
args = @cmd.slice 1
@@ -34,6 +35,11 @@ class LinterRust
3435
atom.notifications.addError "Invalid specified features",
3536
detail: "#{err}"
3637
dismissable: true
38+
else
39+
if do atom.inDevMode
40+
atom.notifications.addError "Something wrong",
41+
detail: "#{err}"
42+
dismissable: true
3743
results.push err
3844

3945
exit = (code) =>
@@ -49,6 +55,9 @@ class LinterRust
4955
else
5056
resolve []
5157

58+
if do @ableToJSONErrors
59+
additional = if options.env.RUSTFLAGS? then ' ' + options.env.RUSTFLAGS else ''
60+
options.env.RUSTFLAGS = '--error-format=json' + additional
5261
@lintProcess = new BufferedProcess({command, args, options, stdout, stderr, exit})
5362
@lintProcess.onWillThrowError ({error, handle}) ->
5463
atom.notifications.addError "Failed to run #{command}",
@@ -192,14 +201,14 @@ class LinterRust
192201
@cmd.push path.join path.dirname(cargoManifestPath), @cargoDependencyDir
193202
@cmd = @cmd.concat @compilationFeatures(false)
194203
@cmd = @cmd.concat [editingFile]
204+
@cmd = @cmd.concat ['--error-format=json']
195205
return editingFile
196206
else
197207
@cmd = @buildCargoPath cargoPath
198208
.concat cargoArgs
199209
.concat ['-j', @config('jobsNumber')]
200210
@cmd = @cmd.concat @compilationFeatures(true)
201211
@cmd = @cmd.concat ['--manifest-path', cargoManifestPath]
202-
@cmd = @cmd.concat ['--','--error-format=json'] if do @ableToJSONErrors
203212
return cargoManifestPath
204213

205214
compilationFeatures: (cargo) =>

0 commit comments

Comments
 (0)