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

Commit 196795d

Browse files
White-Oakgmist
authored andcommitted
Fixed the way json errors are requested from cargo & rustc (#74)
Fixed the way json errors are requested from cargo & rustc. Closes #69
1 parent edd2d0f commit 196795d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/linter-rust.coffee

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spawn = require ('child_process')
88
class LinterRust
99
cargoDependencyDir: "target/debug/deps"
1010
lintProcess: null
11+
cachedAbleToJsonErrors: null
1112
pattern: XRegExp('(?<file>[^\n\r]+):(?<from_line>\\d+):(?<from_col>\\d+):\\s*\
1213
(?<to_line>\\d+):(?<to_col>\\d+)\\s+\
1314
((?<error>error|fatal error)|(?<warning>warning)|(?<info>note|help)):\\s+\
@@ -21,11 +22,14 @@ class LinterRust
2122
file = @initCmd do textEditor.getPath
2223
curDir = path.dirname file
2324
PATH = path.dirname @cmd[0]
24-
options = JSON.parse JSON.stringify process.env
25-
options.PATH = PATH + path.delimiter + options.PATH
25+
options =
26+
env: JSON.parse JSON.stringify process.env
27+
options.env.PATH = PATH + path.delimiter + options.env.PATH
2628
options.cwd = curDir
2729
command = @cmd[0]
2830
args = @cmd.slice 1
31+
@cachedAbleToJsonErrors = null
32+
@cachedAbleToJsonErrors = do @ableToJSONErrors
2933

3034
stdout = (data) ->
3135
console.log data if do atom.inDevMode
@@ -34,6 +38,12 @@ class LinterRust
3438
atom.notifications.addError "Invalid specified features",
3539
detail: "#{err}"
3640
dismissable: true
41+
else
42+
if do atom.inDevMode
43+
atom.notifications.addWarning "Output from stderr while linting",
44+
detail: "#{err}"
45+
description: "This is shown because Atom is running in dev-mode and probably not an actual error"
46+
dismissable: true
3747
results.push err
3848

3949
exit = (code) =>
@@ -49,6 +59,9 @@ class LinterRust
4959
else
5060
resolve []
5161

62+
if do @ableToJSONErrors
63+
additional = if options.env.RUSTFLAGS? then ' ' + options.env.RUSTFLAGS else ''
64+
options.env.RUSTFLAGS = '--error-format=json' + additional
5265
@lintProcess = new BufferedProcess({command, args, options, stdout, stderr, exit})
5366
@lintProcess.onWillThrowError ({error, handle}) ->
5467
atom.notifications.addError "Failed to run #{command}",
@@ -192,14 +205,14 @@ class LinterRust
192205
@cmd.push path.join path.dirname(cargoManifestPath), @cargoDependencyDir
193206
@cmd = @cmd.concat @compilationFeatures(false)
194207
@cmd = @cmd.concat [editingFile]
208+
@cmd = @cmd.concat ['--error-format=json'] if do @ableToJSONErrors
195209
return editingFile
196210
else
197211
@cmd = @buildCargoPath cargoPath
198212
.concat cargoArgs
199213
.concat ['-j', @config('jobsNumber')]
200214
@cmd = @cmd.concat @compilationFeatures(true)
201215
@cmd = @cmd.concat ['--manifest-path', cargoManifestPath]
202-
@cmd = @cmd.concat ['--','--error-format=json'] if do @ableToJSONErrors
203216
return cargoManifestPath
204217

205218
compilationFeatures: (cargo) =>
@@ -214,6 +227,7 @@ class LinterRust
214227
result
215228

216229
ableToJSONErrors: () =>
230+
return @cachedAbleToJsonErrors if @cachedAbleToJsonErrors?
217231
rustcPath = (@config 'rustcPath').trim()
218232
result = spawn.execSync rustcPath + ' --version', {stdio: 'pipe' }
219233
match = XRegExp.exec result, @patternRustcVersion

0 commit comments

Comments
 (0)