| Crates.io | cargo-limit |
| lib.rs | cargo-limit |
| version | 0.0.10 |
| created_at | 2020-09-13 23:38:58.773206+00 |
| updated_at | 2023-01-14 09:14:01.849543+00 |
| description | Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc. |
| homepage | |
| repository | https://github.com/alopatindev/cargo-limit |
| max_upload_size | |
| id | 288385 |
| size | 102,880 |
🚀 Cargo with less noise:
This tool is especially useful in combination with cargo-watch.
Initially this project was just a workaround for this issue.
cargo install cargo-limit
cargo install --force --git https://github.com/alopatindev/cargo-limit
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.
0 means no limit, which is defaultcargo execution time limit in seconds after encountering first compiling error1 is default0 means no limitfalse is defaultfalse is defaultfalse is default"") means don't run external app"_cargo-limit-open-in-nvim" is default
Enable the plugin in your init.vim. For instance for vim-plug:
Plug 'alopatindev/cargo-limit', { 'do': 'cargo install cargo-limit nvim-send' }
and install it with
nvim +PlugInstall +UpdateRemotePlugins +qa
function! SaveAllFilesOrOpenNextLocation()
let l:all_files_are_saved = 1
for i in getbufinfo({'bufmodified': 1})
if i.name != ''
let l:all_files_are_saved = 0
break
endif
endfor
if l:all_files_are_saved
call g:CargoLimitOpenNextLocation()
else
execute 'wa'
endif
endfunction
nmap <F2> :call SaveAllFilesOrOpenNextLocation()<cr>
vmap <F2> <esc>:call SaveAllFilesOrOpenNextLocation()<cr>v
imap <F2> <esc>:call SaveAllFilesOrOpenNextLocation()<cr>i
cd your/project/directory in both of themnvim in one of themcargo lrun in the othernvim opens new or existing tabs with the files on affected lines and columnsnvim will jump to the next error locationcargo llrun (cargo llcheck, etc.) will open them in case of warnings as well.
This is by design, in order to not disrupt from active text editing or file navigation process.
For precise jump please rerun cargo ll{check,run,etc.}.
nvim: Current Directory should be Project (sub)directorynvim instance should be controllednvim instance with current project (sub)directory will be controlled by cargo-limit.Add a custom open handler to your init.vim if you want other Neovim behavior.
function! g:CargoLimitOpen(editor_data)
let l:current_file = resolve(expand('%:p'))
if l:current_file != '' && !filereadable(l:current_file)
return
endif
for location in reverse(a:editor_data.files)
let l:path = fnameescape(location.path)
if mode() == 'n' && &l:modified == 0
execute 'edit ' . l:path
call cursor((location.line), (location.column))
else
break
endif
endfor
endfunction
set errorformat =%f:%l:%c:%m
function! g:CargoLimitOpen(editor_data)
let l:winnr = winnr()
cgetexpr []
for file in a:editor_data['files']
caddexpr file['path'] . ':' . file['line'] . ':' . file['column'] . ':' . file['message']
endfor
if empty(a:editor_data['files'])
cclose
else
copen
endif
if l:winnr !=# winnr()
wincmd p
endif
endfunction
cargo-limit can run external app/script and provide affected locations to stdin in the following JSON format:
{
"workspace_root": "/full/path/to/project",
"files": [
{
"path": "/full/path/to/project/file.rs",
"line": 4,
"column": 1,
"message": "unused import: `diagnostic::DiagnosticSpan`",
"level": "warning"
}
]
}
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 files and gives them to the text editor or IDE client.
jqopen-in-gedit.sh:#!/bin/bash
jq --raw-output '.files |= unique_by(.path) | .files[] | [
"gedit",
.path,
"+" + (.line | tostring) + ":" + (.column | tostring),
"&"
] | join(" ")' | bash
chmod +x open-in-gedit.shCARGO_EDITOR=/path/to/open-in-gedit.sh environment variablecargo lrun in your project directoryopen-in-gedit.sh will open files in gedit on affected lines and columnscargo llrun (cargo llcheck, etc.) will open them in case of warnings as well.bacon is a background rust code checker.
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.
Please check out issues and kanban board. You can also make a package for your favorite OS distribution.
Please support the project with crypto:
1Afgvdz1oPaugFcLgDaAzCYYdHexV6tTvH
TVxE2HyryNyNReMvw9HRQ3BkYePCszXSrc
0xa879cdb1d7d859e6e425f8e50c4ee49f4b3a7b06
MIT/Apache-2.0