This repository was archived by the owner on Aug 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Fixed the way json errors are requested from cargo & rustc #74
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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+\ | ||
|
@@ -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 | ||
@cachedAbleToJsonErrors = do @ableToJSONErrors | ||
|
||
stdout = (data) -> | ||
console.log data if do atom.inDevMode | ||
|
@@ -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) => | ||
|
@@ -49,6 +59,9 @@ class LinterRust | |
else | ||
resolve [] | ||
|
||
if do @ableToJSONErrors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Arcanemagus I'll cache it for a single linter usage (meaning per- |
||
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}", | ||
|
@@ -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) => | ||
|
@@ -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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, exactly