@@ -5,91 +5,89 @@ Linter = require "#{linterPath}/lib/linter"
5
5
{log , warn , findFile } = require " #{ linterPath} /lib/utils"
6
6
fs = require ' fs'
7
7
path = require ' path'
8
- tmp = require (' tmp' )
9
8
10
9
11
10
class LinterRust extends Linter
12
- @enabled : false
11
+ regex : ' (?<file>.+):(?<line> \\ d+):(?<col> \\ d+): \\ s*( \\ d+):( \\ d+) \\ s+((?<error>error|fatal error)|(?<warning>warning)|(?<info>note)): \\ s+(?<message>.+) \n '
13
12
@syntax : ' source.rust'
14
- rustcPath : ' '
15
13
linterName : ' rust'
16
14
errorStream : ' stderr'
17
- regex : ' (?<file>.+):(?<line>\\ d+):(?<col>\\ d+):\\ s*(\\ d+):(\\ d+)\\ s+((?<error>error|fatal error)|(?<warning>warning)|(?<info>note)):\\ s+(?<message>.+)\n '
15
+
16
+ rustcPath : ' '
17
+ cargoPath : ' '
18
18
cargoManifestFilename : ' '
19
- dependencyDir : " target/debug/deps"
20
- tmpFile : null
21
- lintOnChange : false
19
+ cargoDependencyDir : " target/debug/deps"
20
+ useCargo : true
21
+ jobsNumber : 2
22
+
23
+ baseOptions : []
24
+ executionTimeout : 10000
22
25
23
26
24
27
constructor : (@editor ) ->
25
28
super @editor
26
29
atom .config .observe ' linter-rust.executablePath' , =>
27
- rustcPath = atom .config .get ' linter-rust.executablePath'
28
- if rustcPath != @rustcPath
29
- @enabled = false
30
- @rustcPath = rustcPath
31
- exec " \" #{ @rustcPath } \" --version" , @executionCheckHandler
30
+ @ rustcPath = atom .config .get ' linter-rust.executablePath'
31
+ exec " \" #{ @ rustcPath} \" --version " , @executionCheckHandler
32
+ atom . config . observe ' linter-rust.cargoExecutablePath ' , =>
33
+ @cargoPath = atom . config . get ' linter-rust.cargoExecutablePath '
34
+ exec " \" #{ @cargoPath } \" --version" , @executionCheckHandler
32
35
atom .config .observe ' linter-rust.cargoManifestFilename' , =>
33
- @cargoManifestFilename = atom .config .get ' linter-rust.cargoMainifestFilename'
34
- atom .config .observe ' linter-rust.lintOnChange' , =>
35
- @lintOnChange = atom .config .get ' linter-rust.lintOnChange'
36
+ @cargoManifestFilename = atom .config .get ' linter-rust.cargoManifestFilename'
37
+ atom .config .observe ' linter-rust.useCargo' , =>
38
+ @useCargo = atom .config .get ' linter-rust.useCargo'
39
+ atom .config .observe ' linter-rust.jobsNumber' , =>
40
+ @jobsNumber = atom .config .get ' jobsNumber'
41
+ atom .config .observe ' linter-rust.executionTimeout' , =>
42
+ @executionTimeout = atom .config .get ' linter-rust.executionTimeout'
36
43
37
44
38
45
executionCheckHandler : (error , stdout , stderr ) =>
39
- versionRegEx = / rustc ([\d \. ] + )/
40
- if not versionRegEx .test (stdout)
46
+ executable = if / ^ rustc/ .test stdout then [' rustc' , @rustcPath ] else [' cargo' , @cargoPath ]
47
+ versionRegEx = / (rustc| cargo) ([\d \. ] + )/
48
+ if not versionRegEx .test stdout
41
49
result = if error? then ' #' + error .code + ' : ' else ' '
42
50
result += ' stdout: ' + stdout if stdout .length > 0
43
51
result += ' stderr: ' + stderr if stderr .length > 0
44
- console .error " Linter-Rust: \" #{ @rustcPath } \" was not executable: \
52
+ console .error " Linter-Rust: \" #{ executable[ 1 ] } \" was not executable: \
45
53
\" #{ result} \" . Please, check executable path in the linter settings."
54
+ if ' rustc' == executable[0 ] then @rustcPath = ' ' else @cargoPath = ' '
46
55
else
47
- @enabled = true
48
- log " Linter-Rust: found rust " + versionRegEx .exec (stdout)[1 ]
49
- do @initCmd
56
+ log " Linter-Rust: found #{ executable[0 ]} "
50
57
51
58
52
- initCmd : =>
53
- @cmd = [@rustcPath , ' -Z' , ' no-trans' , ' --color' , ' never' ]
54
- cargoPath = do @locateCargoManifest
55
- if cargoPath
56
- @cmd .push ' -L'
57
- @cmd .push path .join cargoPath, @dependencyDir
58
- log ' Linter-Rust: initialization completed'
59
+ initCmd : (editingFile ) =>
60
+ cargoManifestPath = do @locateCargoManifest
61
+ if not @cargoPath or not @useCargo or not cargoManifestPath
62
+ @cmd = [@rustcPath , ' -Z' , ' no-trans' , ' --color' , ' never' ]
63
+ if cargoManifestPath
64
+ @cmd .push ' -L'
65
+ @cmd .push path .join path .dirname (cargoManifestPath), @cargoDependencyDir
66
+ return editingFile
67
+ else
68
+ @cmd = [@cargoPath , ' build' , ' -j' , 2 , ' --manifest-path' ]
69
+ return cargoManifestPath
59
70
60
71
61
72
lintFile : (filePath , callback ) =>
62
- if @enabled
63
- fileName = path .basename do @editor .getPath
64
- if @lintOnChange
65
- cur_dir = path .dirname do @editor .getPath
66
- @tmpFile = tmp .fileSync {dir : cur_dir, postfix : " -#{ fileName} " }
67
- fs .writeFileSync @tmpFile .name , @editor .getText ()
68
- super @tmpFile .name , callback
69
- else
70
- super fileName, callback
73
+ editingFile = @ initCmd path .basename do @editor .getPath
74
+ if @rustcPath or (@cargoPath and @useCargo )
75
+ super editingFile, callback
71
76
72
77
73
78
locateCargoManifest : ->
74
79
cur_dir = path .resolve path .dirname do @editor .getPath
75
- return findFile (cur_dir, @cargoManifestFilename )
76
-
80
+ findFile (cur_dir, @cargoManifestFilename )
77
81
78
- processMessage : (message , callback ) ->
79
- if @tmpFile
80
- @tmpFile .removeCallback ()
81
- @tmpFile = null
82
- super message, callback
83
82
84
-
85
- formatMessage : (match ) ->
86
- fileName = path .basename do @editor .getPath
87
- fileNameRE = RegExp " -#{ fileName} $"
83
+ formatMessage : (match ) =>
88
84
type = if match .error then match .error else if match .warning then match .warning else match .info
89
- if fileNameRE . test ( match . file ) or fileName == match . file
90
- " #{ type } : #{ match .message } "
91
- else
85
+ fileName = path . basename do @editor . getPath
86
+ if match .file isnt fileName
87
+ match . col = match . line = 0
92
88
" #{ type} in #{ match .file } : #{ match .message } "
89
+ else
90
+ " #{ type} : #{ match .message } "
93
91
94
92
95
93
module .exports = LinterRust
0 commit comments