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

Fixed the way json errors are requested from cargo & rustc #74

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/linter-rust.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spawn = require ('child_process')
class LinterRust
cargoDependencyDir: "target/debug/deps"
lintProcess: null
cachedAbleToJsonErrors: null
pattern: XRegExp('(?<file>[^\n\r]+):(?<from_line>\\d+):(?<from_col>\\d+):\\s*\
(?<to_line>\\d+):(?<to_col>\\d+)\\s+\
((?<error>error|fatal error)|(?<warning>warning)|(?<info>note|help)):\\s+\
Expand All @@ -21,11 +22,14 @@ class LinterRust
file = @initCmd do textEditor.getPath
curDir = path.dirname file
PATH = path.dirname @cmd[0]
options = JSON.parse JSON.stringify process.env
options.PATH = PATH + path.delimiter + options.PATH
options =
env: JSON.parse JSON.stringify process.env
options.env.PATH = PATH + path.delimiter + options.env.PATH
options.cwd = curDir
command = @cmd[0]
args = @cmd.slice 1
@cachedAbleToJsonErrors = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... is this line really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmist This ensures that the cached value is live only for a one lint process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, exactly

@cachedAbleToJsonErrors = do @ableToJSONErrors

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

exit = (code) =>
Expand All @@ -49,6 +59,9 @@ class LinterRust
else
resolve []

if do @ableToJSONErrors
Copy link
Member

@Arcanemagus Arcanemagus Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now being called three times for every lint call, its results should probably be cached...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arcanemagus I'll cache it for a single linter usage (meaning per-lint call), but I think it would be incorrect to cache it globally (I mean for a duration of Atom running) -- a user may switch between versions of rustc, while still using the same Atom process running).

additional = if options.env.RUSTFLAGS? then ' ' + options.env.RUSTFLAGS else ''
options.env.RUSTFLAGS = '--error-format=json' + additional
@lintProcess = new BufferedProcess({command, args, options, stdout, stderr, exit})
@lintProcess.onWillThrowError ({error, handle}) ->
atom.notifications.addError "Failed to run #{command}",
Expand Down Expand Up @@ -192,14 +205,14 @@ class LinterRust
@cmd.push path.join path.dirname(cargoManifestPath), @cargoDependencyDir
@cmd = @cmd.concat @compilationFeatures(false)
@cmd = @cmd.concat [editingFile]
@cmd = @cmd.concat ['--error-format=json'] if do @ableToJSONErrors
return editingFile
else
@cmd = @buildCargoPath cargoPath
.concat cargoArgs
.concat ['-j', @config('jobsNumber')]
@cmd = @cmd.concat @compilationFeatures(true)
@cmd = @cmd.concat ['--manifest-path', cargoManifestPath]
@cmd = @cmd.concat ['--','--error-format=json'] if do @ableToJSONErrors
return cargoManifestPath

compilationFeatures: (cargo) =>
Expand All @@ -214,6 +227,7 @@ class LinterRust
result

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