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

Commit 771b14c

Browse files
Improve workspace handelling
- Use `cargo locate-project --workspace` to find workspace manifiest - Add `cargo all` which checks all workspaces and all targets - Fix issue with paths relative to the cargo manifest root
1 parent 5bf7bc1 commit 771b14c

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

lib/init.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ module.exports =
2626
'test all'
2727
'rustc'
2828
'clippy'
29+
'clippy all'
2930
]
3031
description: """`cargo` command to run.<ul>
3132
<li>Use **build** to simply compile the code.</li>
3233
<li>Use **check** for fast linting (does not build the project).</li>
3334
<li>Use **check all** for fast linting of all packages in the project.</li>
3435
<li>Use **check tests** to also include \`#[cfg(test)]\` code in linting.</li>
3536
<li>Use **clippy** to increase amount of available lints (you need to install \`clippy\`).</li>
37+
<li>Use **clippy all** to increase amount of available lints (you need to install \`clippy\`) for all packages in the project.</li>
3638
<li>Use **test** to run tests (note that once the tests are built, lints stop showing).</li>
3739
<li>Use **test all** run tests for all packages in the project.</li>
3840
<li>Use **rustc** for linting with Rust pre-1.23.</li>

lib/linter-rust.coffee

+27-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class LinterRust
3232
@subscriptions.add atom.config.observe 'linter-rust.cargoCommand',
3333
(cargoCommand) =>
3434
@cargoCommand = cargoCommand
35+
@useWorkspaceManifest = cargoCommand.endsWith('all')
3536

3637
@subscriptions.add atom.config.observe 'linter-rust.rustcBuildTest',
3738
(rustcBuildTest) =>
@@ -75,6 +76,8 @@ class LinterRust
7576
cmdPath = if cmd[0]? then path.dirname cmd[0] else __dirname
7677
args = cmd.slice 1
7778
env.PATH = cmdPath + path.delimiter + env.PATH
79+
cargoManifestFile = @locateCargo curDir
80+
cargoManifestDir = path.dirname cargoManifestFile
7881

7982
# we set flags only for intermediate json support
8083
if errorMode == errorModes.FLAGS_JSON_CARGO
@@ -116,7 +119,8 @@ class LinterRust
116119
# correct file paths
117120
messages.forEach (message) ->
118121
if !(path.isAbsolute message.location.file)
119-
message.location.file = path.join curDir, message.location.file
122+
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
120124
messages
121125
else
122126
# whoops, we're in trouble -- let's output as much as we can
@@ -199,8 +203,29 @@ class LinterRust
199203
locateCargo: (curDir) =>
200204
root_dir = if /^win/.test process.platform then /^.:\\$/ else /^\/$/
201205
directory = path.resolve curDir
206+
manifest_name = @cargoManifestFilename
207+
202208
loop
203-
return path.join directory, @cargoManifestFilename if fs.existsSync path.join directory, @cargoManifestFilename
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
204229
break if root_dir.test directory
205230
directory = path.resolve path.join(directory, '..')
206231
return false

lib/mode.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ buildCargoArguments = (linter, cargoManifestPath) ->
165165
.catch ->
166166
result: false
167167
usingMultitoolForClippy.then (canUseMultirust) ->
168-
if cargoCommand == 'clippy' and canUseMultirust.result
168+
if (cargoCommand == 'clippy' or cargoCommand == 'clippy all') and canUseMultirust.result
169169
[canUseMultirust.tool, 'run', 'nightly', 'cargo']
170170
else
171171
[cargoPath]
@@ -181,6 +181,7 @@ buildCargoArguments = (linter, cargoManifestPath) ->
181181
when 'test all' then ['test', '--no-run', '--all']
182182
when 'rustc' then ['rustc', '--color', 'never']
183183
when 'clippy' then ['clippy']
184+
when 'clippy all' then ['clippy', '--workspace', '--all-targets']
184185
else ['build']
185186

186187
compilationFeatures = linter.compilationFeatures(true)

0 commit comments

Comments
 (0)