@@ -76,8 +76,9 @@ class LinterRust
76
76
cmdPath = if cmd[0 ]? then path .dirname cmd[0 ] else __dirname
77
77
args = cmd .slice 1
78
78
env .PATH = cmdPath + path .delimiter + env .PATH
79
- cargoManifestFile = @ locateCargo curDir
80
- cargoManifestDir = path .dirname cargoManifestFile
79
+ editingDir = path .dirname textEditor .getPath ()
80
+ cargoWorkspaceManifestFile = @ locateCargoWorkspace editingDir
81
+ cargoCrateManifestFile = @ locateCargoCrate editingDir
81
82
82
83
# we set flags only for intermediate json support
83
84
if errorMode == errorModes .FLAGS_JSON_CARGO
@@ -91,8 +92,14 @@ class LinterRust
91
92
stream : ' both'
92
93
execOpts .timeout = Infinity if @disableExecTimeout
93
94
94
- atom_linter .exec (command, args, execOpts)
95
- .then (result) =>
95
+ Promise .all [atom_linter .exec (command, args, execOpts), cargoWorkspaceManifestFile]
96
+ .then (promiseReturns) ->
97
+ result = promiseReturns[0 ]
98
+ cargoWorkspaceManifestFile = promiseReturns[1 ]
99
+
100
+ cargoCrateManifestDir = path .dirname cargoCrateManifestFile
101
+ cargoWorkspaceManifestDir = path .dirname cargoWorkspaceManifestFile
102
+
96
103
{stdout , stderr , exitCode } = result
97
104
# first, check if an output says specified features are invalid
98
105
if stderr .indexOf (' does not have these features' ) >= 0
@@ -120,7 +127,8 @@ class LinterRust
120
127
messages .forEach (message) ->
121
128
if ! (path .isAbsolute message .location .file )
122
129
message .location .file = path .join curDir, message .location .file if fs .existsSync path .join curDir, message .location .file
123
- message .location .file = path .join cargoManifestDir, message .location .file if fs .existsSync path .join cargoManifestDir, message .location .file
130
+ message .location .file = path .join cargoCrateManifestDir, message .location .file if fs .existsSync path .join cargoCrateManifestDir, message .location .file
131
+ message .location .file = path .join cargoWorkspaceManifestDir, message .location .file if fs .existsSync path .join cargoWorkspaceManifestDir, message .location .file
124
132
messages
125
133
else
126
134
# whoops, we're in trouble -- let's output as much as we can
@@ -141,15 +149,15 @@ class LinterRust
141
149
142
150
initCmd : (editingFile ) =>
143
151
curDir = if editingFile? then path .dirname editingFile else __dirname
144
- cargoManifestPath = @ locateCargo curDir
145
- if not @useCargo or not cargoManifestPath
146
- @ decideErrorMode (curDir, ' rustc' ).then (mode) =>
147
- mode .buildArguments (this , [editingFile, cargoManifestPath]).then (cmd) ->
148
- [cmd, mode]
149
- else
150
- @ decideErrorMode (curDir, ' cargo' ).then (mode) =>
151
- mode .buildArguments (this , cargoManifestPath).then (cmd) ->
152
- [cmd, mode]
152
+ @ locateCargo ( curDir). then (cargoManifestPath) =>
153
+ if not @useCargo or not cargoManifestPath
154
+ @ decideErrorMode (curDir, ' rustc' ).then (mode) =>
155
+ mode .buildArguments (this , [editingFile, cargoManifestPath]).then (cmd) ->
156
+ [cmd, mode]
157
+ else
158
+ @ decideErrorMode (curDir, ' cargo' ).then (mode) =>
159
+ mode .buildArguments (this , cargoManifestPath).then (cmd) ->
160
+ [cmd, mode]
153
161
154
162
compilationFeatures : (cargo ) =>
155
163
if @specifiedFeatures .length > 0
@@ -200,34 +208,34 @@ class LinterRust
200
208
@cachedErrorMode = result
201
209
result
202
210
203
- locateCargo : (curDir ) =>
211
+ locateCargoCrate : (curDir ) =>
204
212
root_dir = if / ^ win/ .test process .platform then / ^ . :\\ $ / else / ^ \/ $ /
205
213
directory = path .resolve curDir
206
- manifest_name = @cargoManifestFilename
207
-
208
214
loop
209
- if fs .existsSync path .join directory, manifest_name
210
- crate_level_manifest = path .join directory , manifest_name
211
-
212
- if @useWorkspaceManifest
213
- execOpts =
214
- env : JSON .parse JSON .stringify process .env
215
- cwd : curDir
216
- stream : ' both'
217
-
218
- atom_linter .exec (' cargo' , [' locate-project' , ' --workspace' , ' --manifest-path=' + crate_level_manifest], execOpts)
219
- .then (result) =>
220
- {stdout , stderr , exitCode } = result
221
- json = JSON .parse stdout
222
- return json .root
223
- .catch (error) ->
224
- return crate_level_manifest
225
- else
226
- return crate_level_manifest
227
-
228
- return path .join directory , manifest_name if fs .existsSync path .join directory, manifest_name
215
+ return path .join directory , @cargoManifestFilename if fs .existsSync path .join directory, @cargoManifestFilename
229
216
break if root_dir .test directory
230
217
directory = path .resolve path .join (directory, ' ..' )
231
218
return false
232
219
220
+ locateCargoWorkspace : (curDir ) =>
221
+ crate_level_manifest = @ locateCargoCrate (curDir)
222
+ if @useWorkspaceManifest and @useCargo
223
+ execOpts =
224
+ env : JSON .parse JSON .stringify process .env
225
+ cwd : curDir
226
+ stream : ' both'
227
+
228
+ return atom_linter .exec (' cargo' , [' locate-project' , ' --workspace' , ' --manifest-path=' + crate_level_manifest], execOpts)
229
+ .then (result) =>
230
+ {stdout , stderr , exitCode } = result
231
+ json = JSON .parse stdout
232
+ return json .root
233
+ .catch (error) ->
234
+ return crate_level_manifest
235
+ else
236
+ return crate_level_manifest
237
+
238
+ locateCargo : (curDir ) =>
239
+ return @ locateCargoWorkspace curDir
240
+
233
241
module .exports = LinterRust
0 commit comments