@@ -8,6 +8,7 @@ spawn = require ('child_process')
8
8
class LinterRust
9
9
cargoDependencyDir : " target/debug/deps"
10
10
lintProcess : null
11
+ cachedAbleToJsonErrors : null
11
12
pattern : XRegExp (' (?<file>[^\n\r ]+):(?<from_line>\\ d+):(?<from_col>\\ d+):\\ s*\
12
13
(?<to_line>\\ d+):(?<to_col>\\ d+)\\ s+\
13
14
((?<error>error|fatal error)|(?<warning>warning)|(?<info>note|help)):\\ s+\
@@ -21,11 +22,14 @@ class LinterRust
21
22
file = @ initCmd do textEditor .getPath
22
23
curDir = path .dirname file
23
24
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
26
28
options .cwd = curDir
27
29
command = @cmd [0 ]
28
30
args = @cmd .slice 1
31
+ @cachedAbleToJsonErrors = null
32
+ @cachedAbleToJsonErrors = do @ableToJSONErrors
29
33
30
34
stdout = (data ) ->
31
35
console .log data if do atom .inDevMode
@@ -34,6 +38,12 @@ class LinterRust
34
38
atom .notifications .addError " Invalid specified features" ,
35
39
detail : " #{ err} "
36
40
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
37
47
results .push err
38
48
39
49
exit = (code ) =>
@@ -49,6 +59,9 @@ class LinterRust
49
59
else
50
60
resolve []
51
61
62
+ if do @ableToJSONErrors
63
+ additional = if options .env .RUSTFLAGS ? then ' ' + options .env .RUSTFLAGS else ' '
64
+ options .env .RUSTFLAGS = ' --error-format=json' + additional
52
65
@lintProcess = new BufferedProcess ({command, args, options, stdout, stderr, exit})
53
66
@lintProcess .onWillThrowError ({error, handle}) ->
54
67
atom .notifications .addError " Failed to run #{ command} " ,
@@ -192,14 +205,14 @@ class LinterRust
192
205
@cmd .push path .join path .dirname (cargoManifestPath), @cargoDependencyDir
193
206
@cmd = @cmd .concat @ compilationFeatures (false )
194
207
@cmd = @cmd .concat [editingFile]
208
+ @cmd = @cmd .concat [' --error-format=json' ] if do @ableToJSONErrors
195
209
return editingFile
196
210
else
197
211
@cmd = @ buildCargoPath cargoPath
198
212
.concat cargoArgs
199
213
.concat [' -j' , @ config (' jobsNumber' )]
200
214
@cmd = @cmd .concat @ compilationFeatures (true )
201
215
@cmd = @cmd .concat [' --manifest-path' , cargoManifestPath]
202
- @cmd = @cmd .concat [' --' ,' --error-format=json' ] if do @ableToJSONErrors
203
216
return cargoManifestPath
204
217
205
218
compilationFeatures : (cargo ) =>
@@ -214,6 +227,7 @@ class LinterRust
214
227
result
215
228
216
229
ableToJSONErrors : () =>
230
+ return @cachedAbleToJsonErrors if @cachedAbleToJsonErrors ?
217
231
rustcPath = (@ config ' rustcPath' ).trim ()
218
232
result = spawn .execSync rustcPath + ' --version' , {stdio : ' pipe' }
219
233
match = XRegExp .exec result, @patternRustcVersion
0 commit comments