π Cargo with less noise:
- errors have highest priority
- they never appear in the middle of warnings
- warnings are skipped by default until errors are fixed
- external path dependencies' warnings are skipped by default
- all messages come in reversed order by default
- to avoid extra scrolling
- messages are grouped by filenames
- number of messages can be limited
- after encountering first error the rest of build time is limited by default
- files can be automatically opened in your text editor on affected lines
Initially this project was a workaround for this issue, which was closed with no adequate solution.
Check out roadmap, issues and ποΈ Rustacean Station podcast episode for more.
cargo install --locked cargo-limit
cargo install --locked --force --git https://github.com/cargo-limit/cargo-limit
Windows users might need to install MSVC build tools and run rustup default stable-x86_64-pc-windows-msvc first.
Run any of these in your project directory:
cargo lbench
cargo lbuild
cargo lcheck
cargo lclippy
cargo ldoc
cargo lfix
cargo lrun
cargo lrustc
cargo lrustdoc
cargo ltest
Also llcheck, llrun, etc. to auto-open text editor for warnings as well, not just for errors.
This tool is especially useful in combination with cargo-watch.
π‘ Environment Variables ποΈ
- limit compiler messages number
0means no limit, which is default
cargoexecution time limit in seconds after encountering first compiling error- automatically overwritten with
0when--keep-goingis used
- automatically overwritten with
1is default0means no limit
- show compiler messages in ascending order
falseis default
- show warnings even if errors still exist
falseis default
- show external path dependencies' warnings
falseis default
- opens affected files in external app
- empty (
"") means don't run external app - when Neovim is installed
"_cargo-limit-open-in-nvim"is default, otherwise""is default
π‘ Neovim Plugin ποΈ
Requires nvim >= 0.7.0 and git to be installed.
This plugin is LSP-independent, it will keep working even when rust-analyzer fails to produce diagnostics!
Using vim-plug:
Plug 'cargo-limit/cargo-limit', { 'do': 'cargo install --locked cargo-limit' }and run
nvim +PlugInstall +UpdateRemotePlugins +qaπ‘ Using other Neovim Plugin Managers ποΈ
Requires nvim >= 0.12.
vim.pack.add({ 'https://github.com/cargo-limit/cargo-limit' })and run
nvim '+lua vim.pack.update()' +qa && cargo install --locked cargo-limit{ 'cargo-limit/cargo-limit', build = 'cargo install --locked cargo-limit' },and run
nvim --headless "+Lazy! sync" +qaadd({
source = 'cargo-limit/cargo-limit',
hooks = { post_checkout = function() vim.cmd(':!cargo install --locked cargo-limit') end },
})and run
nvim +DepsUpdate +qa{ 'cargo-limit/cargo-limit', build = ':!cargo install --locked cargo-limit' },and run
nvim +PaqSync +qa{ 'cargo-limit/cargo-limit', run = ':!cargo install --locked cargo-limit' };and run
nvim '+Pckr install [plugin]+' +qa{ use 'cargo-limit/cargo-limit', run = ':!cargo install --locked cargo-limit' }and run
nvim +PackerUpdate +qadein:
call dein#add('cargo-limit/cargo-limit', { 'rev': 'master', 'hook_post_update': '!cargo install --locked cargo-limit' })and run
nvim --cmd '!call dein#install()'fun! SaveAllFilesOrOpenNextLocation() abort
if exists('*CargoLimitOpenNextLocation')
call g:CargoLimitOpenNextLocation()
end
execute 'silent! wa!'
endf
nmap <F1> :call g:CargoLimitOpenPrevLocation()<Enter>
vmap <F1> <Esc>:call g:CargoLimitOpenPrevLocation()<Enter>v
imap <F1> <Esc>:call g:CargoLimitOpenPrevLocation()<Enter>i
nmap <F2> :call SaveAllFilesOrOpenNextLocation()<cr>
vmap <F2> <esc>:call SaveAllFilesOrOpenNextLocation()<cr>v
imap <F2> <esc>:call SaveAllFilesOrOpenNextLocation()<cr>ilet g:CargoLimitVerbosity = 2 " warnings levelπ‘ Test the plugin! ποΈ
- Open two terminals (or tmux windows, etc.)
cd your/project/directoryin both of them- Run
nvimin one of them - Run
cargo lrunin the other - In case of compiling errors
nvimopens new or existing tabs with the files on affected lines and columns - Fix the error, save the file and
nvimwill jump to the next error location cargo llrun(cargo llcheck, etc.) will open them in case of warnings as well.
β οΈ Known Limitations! ποΈ
- current mode is normal
- current buffer is either empty or contains some existing and unmodified (saved) file
This is by design, in order to not disrupt from active text editing or file navigation process.
Also, by default, auto-jump won't happen to the affected line if it's already modified/fixed (until you rerun cargo ll{check,run,etc.}).
- that's required so cargo-limit could figure out which exact
nviminstance should be controlled - only first
nviminstance with current project (sub)directory will be controlled by cargo-limit.
Add custom update handlers to your init.vim if you want other Neovim behavior.
π‘ See examples for Neovim! ποΈ
fun! g:CargoLimitUpdate(editor_data) abort
let l:current_file = resolve(expand('%:p'))
if l:current_file !=# '' && !filereadable(l:current_file)
return
end
for l:location in reverse(a:editor_data.locations)
let l:path = fnameescape(l:location.path)
if mode() ==# 'n' && &l:modified ==# 0
execute 'edit ' . l:path
call cursor((l:location.line), (l:location.column))
else
break
end
endfor
endfset errorformat =%f:%l:%c:%m
fun! g:CargoLimitUpdate(editor_data) abort
let l:winnr = winnr()
let l:quickfix_is_visible = len(filter(getwininfo(), 'v:val.quickfix')) ># 0
cgetexpr []
for l:location in a:editor_data.locations
caddexpr l:location.path . ':' . l:location.line . ':' . l:location.column . ':' . l:location.message
endfor
if empty(a:editor_data.locations)
cclose
elseif !a:editor_data.corrected_locations || l:quickfix_is_visible
copen
end
if l:winnr !=# winnr()
wincmd p
end
endfBehavior may depend on your configuration. Use :copen if the quickfix list didn't appear to you automatically.
π‘ Other Text Editors/IDEs ποΈ
cargo-limit can run external app/script and provide affected locations to stdin in the following JSON format:
{
"protocol_version": "0.0.11",
"workspace_root": "/full/path/to/project",
"locations": [
{
"path": "/full/path/to/project/file.rs",
"line": 4,
"column": 1,
"message": "unused import: `diagnostic::DiagnosticSpan`",
"level": "warning"
}
],
"corrected_locations": 0
}Theoretically this can be used for any text editor or IDE, especially if it supports client/server communication. To do that you need a wrapper app/script that parses the locations and gives them to the text editor or IDE client.
π‘ Example: Gedit! ποΈ
- Install
jq - Create
open-in-gedit.sh:
#!/bin/bash
jq --raw-output '.locations |= unique_by(.path) | .locations[] | [
"gedit",
.path,
"+" + (.line | tostring) + ":" + (.column | tostring),
"&"
] | join(" ")' | bashchmod +x open-in-gedit.sh- Set
CARGO_EDITOR=/path/to/open-in-gedit.shenvironment variable - Run
cargo lrunin your project directory - In case of compiling errors
open-in-gedit.shwill open files ingediton affected lines and columns cargo llrun(cargo llcheck, etc.) will open them in case of warnings as well.
- bacon is a background rust code checker
- cargo-firstpage shows only the first page of rustc output
- ograc like cargo, but backwards
If this project improved your workflow β please consider:
- pressing β
- sharing this project with your friends/colleges
- buying me some
coffeeveggies π₯
Your donations will help me allocate more time to resolve issues and to finish all the planned features! β€οΈ
-
Bitcoin (BTC)
1Afgvdz1oPaugFcLgDaAzCYYdHexV6tTvH -
TRON (TRX, USDT-TRC20, etc.)
TVxE2HyryNyNReMvw9HRQ3BkYePCszXSrc -
Ethereum (ETH, DAI, etc.)
0xa879cdb1d7d859e6e425f8e50c4ee49f4b3a7b06 -
TON:
EQApceYoD6FDKn4azXrUxOIyT8VF4NIV_PRE7x9KsTJC9h0q -
Zcash (ZEC):
t1NiwnuUQC1tENTY2aPDDhKEA3pykF582TP -
Litecoin (LTC):
Le3yFbk854T1nrRUjWHkqTNrwz1zgDFqVX -
Monero (XMR):
46pRHmFpqzUBA8SLrdjW73H6ainCqRGpe8shjqQJ4UoBFAbegkAwqvjTSCBvBL71NZXYhriSuKPBkGxc1FjCeiut2EvFvxk
For general donations dedicated to all my projects please check out β‘ here.
Thank you for your support! ππΌ
β€οΈ Special thanks to Danil Suetin for sponsoring this project! β€οΈ
Also thanks everyone for code contributions and bug reporting. Special thanks to Casey Rodarmor for providing VimL code for quickfix populator and Otavio Salvador for NixOS package!
MIT/Apache-2.0