From 6add34d5d99f151487f6617081e8adb667e96000 Mon Sep 17 00:00:00 2001 From: DanielSchuette Date: Thu, 6 Jan 2022 21:37:23 +0100 Subject: [PATCH] update rust vim plugin --- .../plugins/rust.vim/.github/workflows/ci.yml | 9 + vim-config/plugins/rust.vim/.gitignore | 1 + vim-config/plugins/rust.vim/.vintrc.yml | 10 + vim-config/plugins/rust.vim/ISSUE_TEMPLATE.md | 28 ++ vim-config/plugins/rust.vim/README.md | 86 ++++-- .../plugins/rust.vim/after/syntax/rust.vim | 0 .../plugins/rust.vim/autoload/cargo.vim | 38 ++- .../rust.vim/autoload/cargo/quickfix.vim | 3 +- vim-config/plugins/rust.vim/autoload/rust.vim | 62 ++-- .../rust.vim/autoload/rust/debugging.vim | 6 +- .../rust.vim/autoload/rust/delimitmate.vim | 0 .../plugins/rust.vim/autoload/rust/tags.vim | 18 ++ .../plugins/rust.vim/autoload/rustfmt.vim | 62 ++-- .../plugins/rust.vim/compiler/cargo.vim | 0 .../plugins/rust.vim/compiler/rustc.vim | 6 +- vim-config/plugins/rust.vim/ctags/rust.ctags | 0 vim-config/plugins/rust.vim/doc/rust.txt | 55 +++- vim-config/plugins/rust.vim/doc/tags | 66 ---- vim-config/plugins/rust.vim/ftdetect/rust.vim | 13 +- vim-config/plugins/rust.vim/ftplugin/rust.vim | 11 +- .../plugins/rust.vim/ftplugin/rust/tagbar.vim | 2 +- vim-config/plugins/rust.vim/indent/rust.vim | 79 ++++- vim-config/plugins/rust.vim/plugin/cargo.vim | 1 + vim-config/plugins/rust.vim/plugin/rust.vim | 0 vim-config/plugins/rust.vim/syntax/rust.vim | 88 ++++-- .../rust.vim/syntax_checkers/rust/cargo.vim | 0 .../rust.vim/syntax_checkers/rust/rustc.vim | 0 vim-config/plugins/rust.vim/test/.gitignore | 0 vim-config/plugins/rust.vim/test/Dockerfile | 0 .../plugins/rust.vim/test/coverage.vader | 0 vim-config/plugins/rust.vim/test/indent.vader | 292 ++++++++++++++++++ vim-config/plugins/rust.vim/test/run-tests | 6 +- vim-config/plugins/rust.vim/test/sample.rs | 0 vim-config/plugins/rust.vim/test/vimrc | 0 vim-config/plugins/rust.vim/triagebot.toml | 1 + 35 files changed, 737 insertions(+), 206 deletions(-) create mode 100644 vim-config/plugins/rust.vim/.github/workflows/ci.yml create mode 100644 vim-config/plugins/rust.vim/.gitignore create mode 100644 vim-config/plugins/rust.vim/.vintrc.yml create mode 100644 vim-config/plugins/rust.vim/ISSUE_TEMPLATE.md mode change 100755 => 100644 vim-config/plugins/rust.vim/after/syntax/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/autoload/cargo.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/autoload/cargo/quickfix.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/autoload/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/autoload/rust/debugging.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/autoload/rust/delimitmate.vim create mode 100644 vim-config/plugins/rust.vim/autoload/rust/tags.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/autoload/rustfmt.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/compiler/cargo.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/compiler/rustc.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/ctags/rust.ctags mode change 100755 => 100644 vim-config/plugins/rust.vim/doc/rust.txt delete mode 100755 vim-config/plugins/rust.vim/doc/tags mode change 100755 => 100644 vim-config/plugins/rust.vim/ftdetect/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/ftplugin/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/ftplugin/rust/tagbar.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/indent/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/plugin/cargo.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/plugin/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/syntax/rust.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/syntax_checkers/rust/cargo.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/syntax_checkers/rust/rustc.vim mode change 100755 => 100644 vim-config/plugins/rust.vim/test/.gitignore mode change 100755 => 100644 vim-config/plugins/rust.vim/test/Dockerfile mode change 100755 => 100644 vim-config/plugins/rust.vim/test/coverage.vader create mode 100644 vim-config/plugins/rust.vim/test/indent.vader mode change 100755 => 100644 vim-config/plugins/rust.vim/test/sample.rs mode change 100755 => 100644 vim-config/plugins/rust.vim/test/vimrc create mode 100644 vim-config/plugins/rust.vim/triagebot.toml diff --git a/vim-config/plugins/rust.vim/.github/workflows/ci.yml b/vim-config/plugins/rust.vim/.github/workflows/ci.yml new file mode 100644 index 00000000..bd6e2265 --- /dev/null +++ b/vim-config/plugins/rust.vim/.github/workflows/ci.yml @@ -0,0 +1,9 @@ +on: push +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run tests + run: cd test && ./run-tests + shell: bash diff --git a/vim-config/plugins/rust.vim/.gitignore b/vim-config/plugins/rust.vim/.gitignore new file mode 100644 index 00000000..0a56e3fc --- /dev/null +++ b/vim-config/plugins/rust.vim/.gitignore @@ -0,0 +1 @@ +/doc/tags diff --git a/vim-config/plugins/rust.vim/.vintrc.yml b/vim-config/plugins/rust.vim/.vintrc.yml new file mode 100644 index 00000000..0914f1b5 --- /dev/null +++ b/vim-config/plugins/rust.vim/.vintrc.yml @@ -0,0 +1,10 @@ +cmdargs: + # Checking more strictly + severity: style_problem + +policies: + # Disable a violation + ProhibitUnnecessaryDoubleQuote: + enabled: false + ProhibitImplicitScopeVariable: + enabled: false diff --git a/vim-config/plugins/rust.vim/ISSUE_TEMPLATE.md b/vim-config/plugins/rust.vim/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..cf8c71bb --- /dev/null +++ b/vim-config/plugins/rust.vim/ISSUE_TEMPLATE.md @@ -0,0 +1,28 @@ + + +* rust.vim version: + +Steps to reproduce: + + +_?_ + +Expected vs. actual behavior: + +_?_ + +Paste debugging info from the Rust Vim plugin via _one_ of the following +commands: `:RustInfo`, `:RustInfoToClipboard`, or `:RustInfoToFile `. + + +_?_ diff --git a/vim-config/plugins/rust.vim/README.md b/vim-config/plugins/rust.vim/README.md index aaba3dac..c1d428b8 100644 --- a/vim-config/plugins/rust.vim/README.md +++ b/vim-config/plugins/rust.vim/README.md @@ -8,28 +8,53 @@ Some things may not work on earlier versions. ## Installation -Use one of the following package managers: - -* [Vim8 packages][vim8pack]: - * `git clone https://github.com/rust-lang/rust.vim ~/.vim/pack/plugins/start/rust.vim` -* [Vundle][v]: - * Add `Plugin 'rust-lang/rust.vim'` to `~/.vimrc` - * `:PluginInstall` or `$ vim +PluginInstall +qall` - * *Note:* Vundle will not automatically detect Rust files properly if `filetype -on` is executed before Vundle. Please check the [quickstart][vqs] for more -details. Errors such as `Not an editor command: RustFmt` may occur if Vundle -is misconfigured with this plugin. -* [Pathogen][p]: - * `git clone --depth=1 https://github.com/rust-lang/rust.vim.git ~/.vim/bundle/rust.vim` -* [vim-plug][vp]: - * Add `Plug 'rust-lang/rust.vim'` to `~/.vimrc` - * `:PlugInstall` or `$ vim +PlugInstall +qall` -* [dein.vim][d]: - * Add `call dein#add('rust-lang/rust.vim')` to `~/.vimrc` - * `:call dein#install()` -* [NeoBundle][nb]: - * Add `NeoBundle 'rust-lang/rust.vim'` to `~/.vimrc` - * Re-open vim or execute `:source ~/.vimrc` +For activating the full functionality, this plugin requires either the plugin +manager or the `.vimrc` to have the following: + +```vim +syntax enable +filetype plugin indent on +``` + +Most plugin managers don't do this automatically, so these statements are +usually added by users in their `vimrc` _right after_ the plugin manager load +section. + +### [Vim8 packages][vim8pack] + +```sh +git clone https://github.com/rust-lang/rust.vim ~/.vim/pack/plugins/start/rust.vim +``` + +### [Vundle][v] + +```vim +Plugin 'rust-lang/rust.vim' +``` + +### [Pathogen][p] + +```sh +git clone --depth=1 https://github.com/rust-lang/rust.vim.git ~/.vim/bundle/rust.vim +``` + +### [vim-plug][vp] + +```vim +Plug 'rust-lang/rust.vim' +``` + +### [dein.vim][d] + +```vim +call dein#add('rust-lang/rust.vim') +``` + +### [NeoBundle][nb] + +```vim +NeoBundle 'rust-lang/rust.vim' +``` ## Features @@ -41,13 +66,15 @@ for more details. ### Source browsing with [Tagbar][tgbr] -`rust.vim` has builtin `ctags/` definitions for [Tagbar][tgbr] which -are loaded if Tagbar is installed. +The installation of Tagbar along with [Universal Ctags][uctags] is recommended +for a good Tagbar experience. For other kinds of setups, `rust.vim` tries to +configure Tagbar to some degree. ### Formatting with [rustfmt][rfmt] The `:RustFmt` command will format your code with -[rustfmt][rfmt] if installed. +[rustfmt][rfmt] if installed. `rustfmt` can be installed +via `rustup component add rustfmt`. Placing `let g:rustfmt_autosave = 1` in your `~/.vimrc` will enable automatic running of `:RustFmt` when you save a buffer. @@ -66,16 +93,16 @@ If you set g:rust_clip_command RustPlay will copy the url to the clipboard. - Mac: - let g:rust_clip_command = 'pbcopy' + let g:rust_clip_command = 'pbcopy' - Linux: - let g:rust_clip_command = 'xclip -selection clipboard' + let g:rust_clip_command = 'xclip -selection clipboard' ### Running a test under cursor -In cargo project, the `:RustTest` command will run a test under the cursor. -This is useful when your project is bigger and running all tests take longer time. +In a Cargo project, the `:RustTest` command will run the test that is under the cursor. +This is useful when your project is big and running all of the tests takes a long time. ## Help @@ -102,6 +129,7 @@ LICENSE-MIT for details. [rfmt]: https://github.com/rust-lang-nursery/rustfmt [syn]: https://github.com/scrooloose/syntastic [tgbr]: https://github.com/majutsushi/tagbar +[uctags]: https://ctags.io [wav]: https://github.com/mattn/webapi-vim [pp]: https://play.rust-lang.org/ [vim8pack]: http://vimhelp.appspot.com/repeat.txt.html#packages diff --git a/vim-config/plugins/rust.vim/after/syntax/rust.vim b/vim-config/plugins/rust.vim/after/syntax/rust.vim old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/autoload/cargo.vim b/vim-config/plugins/rust.vim/autoload/cargo.vim old mode 100755 new mode 100644 index b5d40e2f..a95a57f9 --- a/vim-config/plugins/rust.vim/autoload/cargo.vim +++ b/vim-config/plugins/rust.vim/autoload/cargo.vim @@ -1,9 +1,21 @@ -function! cargo#Load() +function! cargo#Load() " Utility call to get this script loaded, for debugging endfunction -function! cargo#cmd(args) - execute "! cargo" a:args +function! cargo#cmd(args) abort + " Trim trailing spaces. This is necessary since :terminal command parses + " trailing spaces as an empty argument. + let args = substitute(a:args, '\s\+$', '', '') + if exists('g:cargo_shell_command_runner') + let cmd = g:cargo_shell_command_runner + elseif has('terminal') + let cmd = 'terminal' + elseif has('nvim') + let cmd = 'noautocmd new | terminal' + else + let cmd = '!' + endif + execute cmd 'cargo' args endfunction function! s:nearest_cargo(...) abort @@ -55,6 +67,10 @@ function! cargo#build(args) call cargo#cmd("build " . a:args) endfunction +function! cargo#check(args) + call cargo#cmd("check " . a:args) +endfunction + function! cargo#clean(args) call cargo#cmd("clean " . a:args) endfunction @@ -84,6 +100,22 @@ function! cargo#bench(args) call cargo#cmd("bench " . a:args) endfunction +function! cargo#update(args) + call cargo#cmd("update " . a:args) +endfunction + +function! cargo#search(args) + call cargo#cmd("search " . a:args) +endfunction + +function! cargo#publish(args) + call cargo#cmd("publish " . a:args) +endfunction + +function! cargo#install(args) + call cargo#cmd("install " . a:args) +endfunction + function! cargo#runtarget(args) let l:filename = expand('%:p') let l:read_manifest = system('cargo read-manifest') diff --git a/vim-config/plugins/rust.vim/autoload/cargo/quickfix.vim b/vim-config/plugins/rust.vim/autoload/cargo/quickfix.vim old mode 100755 new mode 100644 index fb16fc72..fbeb42f7 --- a/vim-config/plugins/rust.vim/autoload/cargo/quickfix.vim +++ b/vim-config/plugins/rust.vim/autoload/cargo/quickfix.vim @@ -1,5 +1,6 @@ function! cargo#quickfix#CmdPre() abort - if &filetype ==# 'rust' && get(b:, 'current_compiler', '') ==# 'cargo' + if &filetype ==# 'rust' && get(b:, 'current_compiler', '') ==# 'cargo' && + \ &makeprg =~ '\V\^cargo\ \.\*' " Preserve the current directory, and 'lcd' to the nearest Cargo file. let b:rust_compiler_cargo_qf_has_lcd = haslocaldir() let b:rust_compiler_cargo_qf_prev_cd = getcwd() diff --git a/vim-config/plugins/rust.vim/autoload/rust.vim b/vim-config/plugins/rust.vim/autoload/rust.vim old mode 100755 new mode 100644 index 4ec13dc4..025949c6 --- a/vim-config/plugins/rust.vim/autoload/rust.vim +++ b/vim-config/plugins/rust.vim/autoload/rust.vim @@ -1,4 +1,3 @@ -" Author: Kevin Ballard " Description: Helper functions for Rust commands/mappings " Last Modified: May 27, 2014 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim @@ -396,10 +395,19 @@ function! s:RmDir(path) echoerr 'Attempted to delete empty path' return 0 elseif a:path ==# '/' || a:path ==# $HOME - echoerr 'Attempted to delete protected path: ' . a:path + let l:path = expand(a:path) + if l:path ==# '/' || l:path ==# $HOME + echoerr 'Attempted to delete protected path: ' . a:path + return 0 + endif + endif + + if !isdirectory(a:path) return 0 endif - return system("rm -rf " . shellescape(a:path)) + + " delete() returns 0 when removing file successfully + return delete(a:path, 'rf') == 0 endfunction " Executes {cmd} with the cwd set to {pwd}, without changing Vim's cwd. @@ -491,7 +499,15 @@ function! s:SearchTestFunctionNameUnderCursor() abort " Search the end of test function (closing brace) to ensure that the " cursor position is within function definition - normal! % + if maparg('(MatchitNormalForward)') ==# '' + keepjumps normal! % + else + " Prefer matchit.vim official plugin to native % since the plugin + " provides better behavior than original % (#391) + " To load the plugin, run: + " :packadd matchit + execute 'keepjumps' 'normal' "\(MatchitNormalForward)" + endif if line('.') < cursor_line return '' endif @@ -499,14 +515,23 @@ function! s:SearchTestFunctionNameUnderCursor() abort return matchstr(getline(test_func_line), '\m\C^\s*fn\s\+\zs\h\w*') endfunction -function! rust#Test(all, options) abort +function! rust#Test(mods, winsize, all, options) abort let manifest = findfile('Cargo.toml', expand('%:p:h') . ';') if manifest ==# '' return rust#Run(1, '--test ' . a:options) endif - if exists(':terminal') - let cmd = 'terminal ' + " defaults to 0, but we prefer an empty string + let winsize = a:winsize ? a:winsize : '' + + if has('terminal') + if has('patch-8.0.910') + let cmd = printf('%s noautocmd %snew | terminal ++curwin ', a:mods, winsize) + else + let cmd = printf('%s terminal ', a:mods) + endif + elseif has('nvim') + let cmd = printf('%s noautocmd %snew | terminal ', a:mods, winsize) else let cmd = '!' let manifest = shellescape(manifest) @@ -524,21 +549,20 @@ function! rust#Test(all, options) abort let saved = getpos('.') try let func_name = s:SearchTestFunctionNameUnderCursor() - if func_name ==# '' - echohl ErrorMsg - echo 'No test function was found under the cursor. Please add ! to command if you want to run all tests' - echohl None - return - endif - if a:options ==# '' - execute cmd . 'cargo test --manifest-path' manifest func_name - else - execute cmd . 'cargo test --manifest-path' manifest func_name a:options - endif - return finally call setpos('.', saved) endtry + if func_name ==# '' + echohl ErrorMsg + echomsg 'No test function was found under the cursor. Please add ! to command if you want to run all tests' + echohl None + return + endif + if a:options ==# '' + execute cmd . 'cargo test --manifest-path' manifest func_name + else + execute cmd . 'cargo test --manifest-path' manifest func_name a:options + endif endfunction " }}}1 diff --git a/vim-config/plugins/rust.vim/autoload/rust/debugging.vim b/vim-config/plugins/rust.vim/autoload/rust/debugging.vim old mode 100755 new mode 100644 index ae307a0b..b39f6877 --- a/vim-config/plugins/rust.vim/autoload/rust/debugging.vim +++ b/vim-config/plugins/rust.vim/autoload/rust/debugging.vim @@ -1,6 +1,7 @@ " For debugging, inspired by https://github.com/w0rp/rust/blob/master/autoload/rust/debugging.vim let s:global_variable_list = [ + \ '_rustfmt_autosave_because_of_config', \ 'ftplugin_rust_source_path', \ 'loaded_syntastic_rust_cargo_checker', \ 'loaded_syntastic_rust_filetype', @@ -28,7 +29,6 @@ let s:global_variable_list = [ \ 'rustc_makeprg_no_percent', \ 'rustc_path', \ 'rustfmt_autosave', - \ 'rustfmt_autosave_because_of_config', \ 'rustfmt_autosave_if_config_present', \ 'rustfmt_command', \ 'rustfmt_emit_files', @@ -44,7 +44,9 @@ endfunction function! s:EchoGlobalVariables() abort for l:key in s:global_variable_list - call s:Echo('let g:' . l:key . ' = ' . string(get(g:, l:key, v:null))) + if l:key !~# '^_' + call s:Echo('let g:' . l:key . ' = ' . string(get(g:, l:key, v:null))) + endif if has_key(b:, l:key) call s:Echo('let b:' . l:key . ' = ' . string(b:[l:key])) diff --git a/vim-config/plugins/rust.vim/autoload/rust/delimitmate.vim b/vim-config/plugins/rust.vim/autoload/rust/delimitmate.vim old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/autoload/rust/tags.vim b/vim-config/plugins/rust.vim/autoload/rust/tags.vim new file mode 100644 index 00000000..0a4cc20e --- /dev/null +++ b/vim-config/plugins/rust.vim/autoload/rust/tags.vim @@ -0,0 +1,18 @@ +" Tagbar support code, for the sake of not automatically overriding its +" configuration in case Universal Ctags is detected. + +let s:ctags_is_uctags = 0 +let s:checked_ctags = 0 + +function! rust#tags#IsUCtags() abort + if s:checked_ctags == 0 + let l:ctags_bin = get(g:, 'tagbar_ctags_bin', 'ctags') + if system(l:ctags_bin.' --version') =~? 'universal ctags' + let s:ctags_is_uctags = 1 + endif + let s:checked_ctags = 1 + endif + return s:ctags_is_uctags +endfunction + +" vim: set et sw=4 sts=4 ts=8: diff --git a/vim-config/plugins/rust.vim/autoload/rustfmt.vim b/vim-config/plugins/rust.vim/autoload/rustfmt.vim old mode 100755 new mode 100644 index 7e2e9fd6..59a58e84 --- a/vim-config/plugins/rust.vim/autoload/rustfmt.vim +++ b/vim-config/plugins/rust.vim/autoload/rustfmt.vim @@ -60,18 +60,19 @@ function! s:RustfmtWriteMode() endif endfunction -function! s:RustfmtConfig() +function! s:RustfmtConfigOptions() let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';') if l:rustfmt_toml !=# '' - return '--config-path '.l:rustfmt_toml + return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) endif let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';') if l:_rustfmt_toml !=# '' - return '--config-path '.l:_rustfmt_toml + return '--config-path '.shellescape(fnamemodify(l:_rustfmt_toml, ":p")) endif - return '' + " Default to edition 2018 in case no rustfmt.toml was found. + return '--edition 2018' endfunction function! s:RustfmtCommandRange(filename, line1, line2) @@ -82,7 +83,7 @@ function! s:RustfmtCommandRange(filename, line1, line2) let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]} let l:write_mode = s:RustfmtWriteMode() - let l:rustfmt_config = s:RustfmtConfig() + let l:rustfmt_config = s:RustfmtConfigOptions() " FIXME: When --file-lines gets to be stable, add version range checking " accordingly. @@ -96,22 +97,17 @@ function! s:RustfmtCommandRange(filename, line1, line2) endfunction function! s:RustfmtCommand() - if g:rustfmt_emit_files - let l:write_mode = "--emit=stdout" - else - let l:write_mode = "--write-mode=display" - endif - " rustfmt will pick on the right config on its own due to the - " current directory change. - return g:rustfmt_command . " ". l:write_mode . " " . g:rustfmt_options + let write_mode = g:rustfmt_emit_files ? '--emit=stdout' : '--write-mode=display' + let config = s:RustfmtConfigOptions() + return join([g:rustfmt_command, write_mode, config, g:rustfmt_options]) endfunction function! s:DeleteLines(start, end) abort silent! execute a:start . ',' . a:end . 'delete _' endfunction -function! s:RunRustfmt(command, tmpname, fail_silently) - mkview! +function! s:RunRustfmt(command, tmpname, from_writepre) + let l:view = winsaveview() let l:stderr_tmpname = tempname() call writefile([], l:stderr_tmpname) @@ -145,9 +141,12 @@ function! s:RunRustfmt(command, tmpname, fail_silently) call delete(l:stderr_tmpname) + let l:open_lwindow = 0 if v:shell_error == 0 - " remove undo point caused via BufWritePre - try | silent undojoin | catch | endtry + if a:from_writepre + " remove undo point caused via BufWritePre + try | silent undojoin | catch | endtry + endif if a:tmpname ==# '' let l:content = l:out @@ -165,9 +164,9 @@ function! s:RunRustfmt(command, tmpname, fail_silently) if s:got_fmt_error let s:got_fmt_error = 0 call setloclist(0, []) - lwindow + let l:open_lwindow = 1 endif - elseif g:rustfmt_fail_silently == 0 && a:fail_silently == 0 + elseif g:rustfmt_fail_silently == 0 && !a:from_writepre " otherwise get the errors and put them in the location list let l:errors = [] @@ -197,7 +196,7 @@ function! s:RunRustfmt(command, tmpname, fail_silently) endif let s:got_fmt_error = 1 - lwindow + let l:open_lwindow = 1 endif " Restore the current directory if needed @@ -209,19 +208,24 @@ function! s:RunRustfmt(command, tmpname, fail_silently) endif endif - silent! loadview + " Open lwindow after we have changed back to the previous directory + if l:open_lwindow == 1 + lwindow + endif + + call winrestview(l:view) endfunction function! rustfmt#FormatRange(line1, line2) let l:tmpname = tempname() call writefile(getline(1, '$'), l:tmpname) let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2) - call s:RunRustfmt(command, l:tmpname, 0) + call s:RunRustfmt(command, l:tmpname, v:false) call delete(l:tmpname) endfunction function! rustfmt#Format() - call s:RunRustfmt(s:RustfmtCommand(), '', 0) + call s:RunRustfmt(s:RustfmtCommand(), '', v:false) endfunction function! rustfmt#Cmd() @@ -230,10 +234,18 @@ function! rustfmt#Cmd() endfunction function! rustfmt#PreWrite() + if !filereadable(expand("%@")) + return + endif if rust#GetConfigVar('rustfmt_autosave_if_config_present', 0) if findfile('rustfmt.toml', '.;') !=# '' || findfile('.rustfmt.toml', '.;') !=# '' let b:rustfmt_autosave = 1 - let b:rustfmt_autosave_because_of_config = 1 + let b:_rustfmt_autosave_because_of_config = 1 + endif + else + if has_key(b:, '_rustfmt_autosave_because_of_config') + unlet b:_rustfmt_autosave_because_of_config + unlet b:rustfmt_autosave endif endif @@ -241,7 +253,7 @@ function! rustfmt#PreWrite() return endif - call s:RunRustfmt(s:RustfmtCommand(), '', 1) + call s:RunRustfmt(s:RustfmtCommand(), '', v:true) endfunction diff --git a/vim-config/plugins/rust.vim/compiler/cargo.vim b/vim-config/plugins/rust.vim/compiler/cargo.vim old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/compiler/rustc.vim b/vim-config/plugins/rust.vim/compiler/rustc.vim old mode 100755 new mode 100644 index 6114b747..9b70732a --- a/vim-config/plugins/rust.vim/compiler/rustc.vim +++ b/vim-config/plugins/rust.vim/compiler/rustc.vim @@ -21,7 +21,11 @@ endif if get(g:, 'rustc_makeprg_no_percent', 0) CompilerSet makeprg=rustc else - CompilerSet makeprg=rustc\ \% + if has('patch-7.4.191') + CompilerSet makeprg=rustc\ \%:S + else + CompilerSet makeprg=rustc\ \"%\" + endif endif " New errorformat (after nightly 2016/08/10) diff --git a/vim-config/plugins/rust.vim/ctags/rust.ctags b/vim-config/plugins/rust.vim/ctags/rust.ctags old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/doc/rust.txt b/vim-config/plugins/rust.vim/doc/rust.txt old mode 100755 new mode 100644 index b11d4181..9d5eb8cc --- a/vim-config/plugins/rust.vim/doc/rust.txt +++ b/vim-config/plugins/rust.vim/doc/rust.txt @@ -91,12 +91,17 @@ g:rust_use_custom_ctags_defs~ and do not wish for those included with rust.vim to be used: > let g:rust_use_custom_ctags_defs = 1 < - Note that rust.vim's built-in definitions are only used for the Tagbar - Vim plugin, if you have it installed--it is not automatically used - when generating |tags| files that Vim can use to navigate to - definitions across different source files. Feel free to copy - `rust.vim/ctags/rust.ctags` into your own `~/.ctags` if you wish to - generate |tags| files. + + NOTE: rust.vim's built-in definitions are only used for the Tagbar Vim + plugin, if you have it installed, AND if Universal Ctags is not + detected. This is because Universal Ctags already has built-in + support for Rust when used with Tagbar. + + Also, note that when using ctags other than Universal Ctags, it is not + automatically used when generating |tags| files that Vim can use to + navigate to definitions across different source files. Feel free to + copy `rust.vim/ctags/rust.ctags` into your own `~/.ctags` if you wish + to generate |tags| files. *g:ftplugin_rust_source_path* @@ -120,18 +125,17 @@ g:rustfmt_autosave~ < There is also a buffer-local b:rustfmt_autosave that can be set for the same purpose, and can override the global setting. - + *g:rustfmt_autosave_if_config_present* g:rustfmt_autosave_if_config_present~ - Set this option to 1 to to have *b:rustfmt_autosave* be set automatically - if a `rustfmt.toml` file is present in any parent directly leading to + Set this option to 1 to have *b:rustfmt_autosave* be set automatically + if a `rustfmt.toml` file is present in any parent directly leading to the file being edited. If not set, default to 0: > - let g:rustfmt_autosave_if_config_present = 0 < This is useful to have `rustfmt` only execute on save, on projects that have `rustfmt.toml` configuration. - + There is also a buffer-local b:rustfmt_autosave_if_config_present that can be set for the same purpose, which can overrides the global setting. @@ -156,6 +160,7 @@ g:rustfmt_emit_files~ provided) instead of '--write-mode=overwrite'. > let g:rustfmt_emit_files = 0 + *g:rust_playpen_url* g:rust_playpen_url~ Set this option to override the url for the playpen to use: > @@ -182,14 +187,24 @@ g:cargo_makeprg_params~ let g:cargo_makeprg_params = 'build' < + *g:cargo_shell_command_runner* +g:cargo_shell_command_runner~ + Set this option to change how to run shell commands for cargo commands + |:Cargo|, |:Cbuild|, |:Crun|, ... + By default, |:terminal| is used to run shell command in terminal window + asynchronously. But if you prefer |:!| for running the commands, it can + be specified: > + let g:cargo_shell_command_runner = '!' +< + Integration with Syntastic *rust-syntastic* -------------------------- This plugin automatically integrates with the Syntastic checker. There are two -checkers provided: 'rustc', and 'cargo'. The later invokes 'Cargo' in order to +checkers provided: 'rustc', and 'cargo'. The latter invokes 'Cargo' in order to build code, and the former delivers a single edited '.rs' file as a compilation -target directly to the Rust compiler, `rustc`. +target directly to the Rust compiler, `rustc`. Because Cargo is almost exclusively being used for building Rust code these days, 'cargo' is the default checker. > @@ -349,7 +364,8 @@ Playpen integration |g:rust_clip_command| is the command to run to copy the playpen url to the clipboard of your system. -Evaulation of a single Rust file + +Evaluation of a single Rust file -------------------------------- NOTE: These commands are useful only when working with standalone Rust files, @@ -421,12 +437,15 @@ functionality from other plugins. Running test(s) --------------- -:RustTest[!] [options] *:RustTest* +:[N]RustTest[!] [options] *:RustTest* Runs a test under the cursor when the current buffer is in a cargo project with "cargo test" command. If the command did not find any test function under the cursor, it stops with an error message. + When N is given, adjust the size of the new window to N lines + or columns. + When ! is given, runs all tests regardless of current cursor position. @@ -439,7 +458,11 @@ Running test(s) is no way to run specific test function with rustc. [options] is passed to "rustc" command arguments in the case. - + Takes optional modifiers (see ||): > + :tab RustTest + :belowright 16RustTest + :leftabove vert 80RustTest +< rust.vim Debugging ------------------ diff --git a/vim-config/plugins/rust.vim/doc/tags b/vim-config/plugins/rust.vim/doc/tags deleted file mode 100755 index 2d22d1d0..00000000 --- a/vim-config/plugins/rust.vim/doc/tags +++ /dev/null @@ -1,66 +0,0 @@ -:Cargo rust.txt /*:Cargo* -:Cbench rust.txt /*:Cbench* -:Cbuild rust.txt /*:Cbuild* -:Cclean rust.txt /*:Cclean* -:Cdoc rust.txt /*:Cdoc* -:Cinit rust.txt /*:Cinit* -:Cinstall rust.txt /*:Cinstall* -:Cpublish rust.txt /*:Cpublish* -:Crun rust.txt /*:Crun* -:Cruntarget rust.txt /*:Cruntarget* -:Csearch rust.txt /*:Csearch* -:Ctest rust.txt /*:Ctest* -:Cupdate rust.txt /*:Cupdate* -:RustEmitAsm rust.txt /*:RustEmitAsm* -:RustEmitIr rust.txt /*:RustEmitIr* -:RustExpand rust.txt /*:RustExpand* -:RustFmt rust.txt /*:RustFmt* -:RustFmtRange rust.txt /*:RustFmtRange* -:RustInfo rust.txt /*:RustInfo* -:RustInfoClipboard rust.txt /*:RustInfoClipboard* -:RustInfoToFile rust.txt /*:RustInfoToFile* -:RustPlay rust.txt /*:RustPlay* -:RustRun rust.txt /*:RustRun* -:RustTest rust.txt /*:RustTest* -b:rust_cargo_avoid_whole_workspace rust.txt /*b:rust_cargo_avoid_whole_workspace* -b:rust_cargo_check_all_features rust.txt /*b:rust_cargo_check_all_features* -b:rust_cargo_check_all_targets rust.txt /*b:rust_cargo_check_all_targets* -b:rust_cargo_check_benches rust.txt /*b:rust_cargo_check_benches* -b:rust_cargo_check_examples rust.txt /*b:rust_cargo_check_examples* -b:rust_cargo_check_tests rust.txt /*b:rust_cargo_check_tests* -b:rustfmt_autosave rust.txt /*b:rustfmt_autosave* -ft_rust.txt rust.txt /*ft_rust.txt* -g:cargo_makeprg_params rust.txt /*g:cargo_makeprg_params* -g:ftplugin_rust_source_path rust.txt /*g:ftplugin_rust_source_path* -g:rust_bang_comment_leader rust.txt /*g:rust_bang_comment_leader* -g:rust_cargo_avoid_whole_workspace rust.txt /*g:rust_cargo_avoid_whole_workspace* -g:rust_cargo_check_all_features rust.txt /*g:rust_cargo_check_all_features* -g:rust_cargo_check_all_targets rust.txt /*g:rust_cargo_check_all_targets* -g:rust_cargo_check_benches rust.txt /*g:rust_cargo_check_benches* -g:rust_cargo_check_examples rust.txt /*g:rust_cargo_check_examples* -g:rust_cargo_check_tests rust.txt /*g:rust_cargo_check_tests* -g:rust_clip_command rust.txt /*g:rust_clip_command* -g:rust_conceal rust.txt /*g:rust_conceal* -g:rust_conceal_mod_path rust.txt /*g:rust_conceal_mod_path* -g:rust_conceal_pub rust.txt /*g:rust_conceal_pub* -g:rust_fold rust.txt /*g:rust_fold* -g:rust_keep_autopairs_default rust.txt /*g:rust_keep_autopairs_default* -g:rust_playpen_url rust.txt /*g:rust_playpen_url* -g:rust_recommended_style rust.txt /*g:rust_recommended_style* -g:rust_shortener_url rust.txt /*g:rust_shortener_url* -g:rust_use_custom_ctags_defs rust.txt /*g:rust_use_custom_ctags_defs* -g:rustc_makeprg_no_percent rust.txt /*g:rustc_makeprg_no_percent* -g:rustc_path rust.txt /*g:rustc_path* -g:rustfmt_autosave rust.txt /*g:rustfmt_autosave* -g:rustfmt_autosave_if_config_present rust.txt /*g:rustfmt_autosave_if_config_present* -g:rustfmt_command rust.txt /*g:rustfmt_command* -g:rustfmt_emit_files rust.txt /*g:rustfmt_emit_files* -g:rustfmt_fail_silently rust.txt /*g:rustfmt_fail_silently* -g:rustfmt_options rust.txt /*g:rustfmt_options* -rust rust.txt /*rust* -rust-auto-pairs rust.txt /*rust-auto-pairs* -rust-commands rust.txt /*rust-commands* -rust-intro rust.txt /*rust-intro* -rust-mappings rust.txt /*rust-mappings* -rust-settings rust.txt /*rust-settings* -rust-syntastic rust.txt /*rust-syntastic* diff --git a/vim-config/plugins/rust.vim/ftdetect/rust.vim b/vim-config/plugins/rust.vim/ftdetect/rust.vim old mode 100755 new mode 100644 index 77e28e74..e0950930 --- a/vim-config/plugins/rust.vim/ftdetect/rust.vim +++ b/vim-config/plugins/rust.vim/ftdetect/rust.vim @@ -1,6 +1,15 @@ " vint: -ProhibitAutocmdWithNoGroup -autocmd BufRead,BufNewFile *.rs setf rust -autocmd BufRead,BufNewFile Cargo.toml if &filetype == "" | set filetype=cfg | endif +autocmd BufRead,BufNewFile *.rs call s:set_rust_filetype() + +if has('patch-8.0.613') + autocmd BufRead,BufNewFile Cargo.toml setf FALLBACK cfg +endif + +function! s:set_rust_filetype() abort + if &filetype !=# 'rust' + set filetype=rust + endif +endfunction " vim: set et sw=4 sts=4 ts=8: diff --git a/vim-config/plugins/rust.vim/ftplugin/rust.vim b/vim-config/plugins/rust.vim/ftplugin/rust.vim old mode 100755 new mode 100644 index adf2d4b0..fb048cac --- a/vim-config/plugins/rust.vim/ftplugin/rust.vim +++ b/vim-config/plugins/rust.vim/ftplugin/rust.vim @@ -1,7 +1,6 @@ " Language: Rust " Description: Vim ftplugin for Rust " Maintainer: Chris Morgan -" Maintainer: Kevin Ballard " Last Change: June 08, 2016 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim @@ -35,7 +34,7 @@ if get(g:, 'rust_bang_comment_leader', 0) " leaders. I'm fairly sure that's a Vim bug. setlocal comments=s1:/*,mb:*,ex:*/,s0:/*,mb:\ ,ex:*/,:///,://!,:// else - setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,:// + setlocal comments=s0:/*!,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,:// endif setlocal commentstring=//%s setlocal formatoptions-=t formatoptions+=croqnl @@ -48,7 +47,7 @@ setlocal smartindent nocindent if get(g:, 'rust_recommended_style', 1) let b:rust_set_style = 1 - setlocal tabstop=8 shiftwidth=4 softtabstop=4 expandtab + setlocal shiftwidth=4 softtabstop=4 expandtab setlocal textwidth=99 endif @@ -122,7 +121,7 @@ command! -nargs=* -buffer RustEmitAsm call rust#Emit("asm", ) command! -range=% RustPlay :call rust#Play(, , , ) " See |:RustFmt| for docs -command! -buffer RustFmt call rustfmt#Format() +command! -bar -buffer RustFmt call rustfmt#Format() " See |:RustFmtRange| for docs command! -range -buffer RustFmtRange call rustfmt#FormatRange(, ) @@ -137,7 +136,7 @@ command! -bar RustInfoToClipboard call rust#debugging#InfoToClipboard() command! -bar -nargs=1 RustInfoToFile call rust#debugging#InfoToFile() " See |:RustTest| for docs -command! -buffer -nargs=* -bang RustTest call rust#Test(0, ) +command! -buffer -nargs=* -count -bang RustTest call rust#Test(, , 0, ) if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args") let b:rust_last_rustc_args = [] @@ -191,7 +190,7 @@ augroup END setlocal matchpairs+=<:> " For matchit.vim (rustArrow stops `Fn() -> X` messing things up) -let b:match_skip = 's:comment\|string\|rustArrow' +let b:match_skip = 's:comment\|string\|rustCharacter\|rustArrow' " vint: -ProhibitAbbreviationOption let &cpo = s:save_cpo diff --git a/vim-config/plugins/rust.vim/ftplugin/rust/tagbar.vim b/vim-config/plugins/rust.vim/ftplugin/rust/tagbar.vim old mode 100755 new mode 100644 index 9cb1b480..de8a094c --- a/vim-config/plugins/rust.vim/ftplugin/rust/tagbar.vim +++ b/vim-config/plugins/rust.vim/ftplugin/rust/tagbar.vim @@ -1,7 +1,7 @@ " " Support for Tagbar -- https://github.com/majutsushi/tagbar " -if !exists(':Tagbar') +if !exists(':Tagbar') || rust#tags#IsUCtags() finish endif diff --git a/vim-config/plugins/rust.vim/indent/rust.vim b/vim-config/plugins/rust.vim/indent/rust.vim old mode 100755 new mode 100644 index 91192c39..e0c847cb --- a/vim-config/plugins/rust.vim/indent/rust.vim +++ b/vim-config/plugins/rust.vim/indent/rust.vim @@ -11,8 +11,8 @@ endif let b:did_indent = 1 setlocal cindent -setlocal cinoptions=L0,(0,Ws,J1,j1,m1 -setlocal cinkeys=0{,0},!^F,o,O,0[,0] +setlocal cinoptions=L0,(s,Ws,J1,j1,m1 +setlocal cinkeys=0{,0},!^F,o,O,0[,0],0(,0) " Don't think cinwords will actually do anything at all... never mind setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern,macro @@ -20,10 +20,12 @@ setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,ex setlocal nolisp " Make sure lisp indenting doesn't supersede us setlocal autoindent " indentexpr isn't much help otherwise " Also do indentkeys, otherwise # gets shoved to column 0 :-/ -setlocal indentkeys=0{,0},!^F,o,O,0[,0] +setlocal indentkeys=0{,0},!^F,o,O,0[,0],0(,0) setlocal indentexpr=GetRustIndent(v:lnum) +let b:undo_indent = "setlocal cindent< cinoptions< cinkeys< cinwords< lisp< autoindent< indentkeys< indentexpr<" + " Only define the function once. if exists("*GetRustIndent") finish @@ -81,8 +83,17 @@ function! s:is_string_comment(lnum, col) endif endfunction -function GetRustIndent(lnum) +if exists('*shiftwidth') + function! s:shiftwidth() + return shiftwidth() + endfunc +else + function! s:shiftwidth() + return &shiftwidth + endfunc +endif +function GetRustIndent(lnum) " Starting assumption: cindent (called at the end) will do it right " normally. We just want to fix up a few cases. @@ -128,14 +139,70 @@ function GetRustIndent(lnum) let prevline = s:get_line_trimmed(prevlinenum) endwhile + " A standalone '{', '}', or 'where' + let l:standalone_open = line =~# '\V\^\s\*{\s\*\$' + let l:standalone_close = line =~# '\V\^\s\*}\s\*\$' + let l:standalone_where = line =~# '\V\^\s\*where\s\*\$' + if l:standalone_open || l:standalone_close || l:standalone_where + " ToDo: we can search for more items than 'fn' and 'if'. + let [l:found_line, l:col, l:submatch] = + \ searchpos('\<\(fn\)\|\(if\)\>', 'bnWp') + if l:found_line !=# 0 + " Now we count the number of '{' and '}' in between the match + " locations and the current line (there is probably a better + " way to compute this). + let l:i = l:found_line + let l:search_line = strpart(getline(l:i), l:col - 1) + let l:opens = 0 + let l:closes = 0 + while l:i < a:lnum + let l:search_line2 = substitute(l:search_line, '\V{', '', 'g') + let l:opens += strlen(l:search_line) - strlen(l:search_line2) + let l:search_line3 = substitute(l:search_line2, '\V}', '', 'g') + let l:closes += strlen(l:search_line2) - strlen(l:search_line3) + let l:i += 1 + let l:search_line = getline(l:i) + endwhile + if l:standalone_open || l:standalone_where + if l:opens ==# l:closes + return indent(l:found_line) + endif + else + " Expect to find just one more close than an open + if l:opens ==# l:closes + 1 + return indent(l:found_line) + endif + endif + endif + endif + + " A standalone 'where' adds a shift. + let l:standalone_prevline_where = prevline =~# '\V\^\s\*where\s\*\$' + if l:standalone_prevline_where + return indent(prevlinenum) + 4 + endif + " Handle where clauses nicely: subsequent values should line up nicely. if prevline[len(prevline) - 1] ==# "," \ && prevline =~# '^\s*where\s' return indent(prevlinenum) + 6 endif - if prevline[len(prevline) - 1] ==# "," - \ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{}]' + let l:last_prevline_character = prevline[len(prevline) - 1] + + " A line that ends with '.;' is probably an end of a long list + " of method operations. + if prevline =~# '\V\^\s\*.' && l:last_prevline_character ==# ';' + call cursor(a:lnum - 1, 1) + let l:scope_start = searchpair('{\|(', '', '}\|)', 'nbW', + \ 's:is_string_comment(line("."), col("."))') + if l:scope_start != 0 && l:scope_start < a:lnum + return indent(l:scope_start) + 4 + endif + endif + + if l:last_prevline_character ==# "," + \ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{})]' \ && prevline !~# '^\s*fn\s' \ && prevline !~# '([^()]\+,$' \ && s:get_line_trimmed(a:lnum) !~# '^\s*\S\+\s*=>' diff --git a/vim-config/plugins/rust.vim/plugin/cargo.vim b/vim-config/plugins/rust.vim/plugin/cargo.vim old mode 100755 new mode 100644 index 5cd413cc..efc38768 --- a/vim-config/plugins/rust.vim/plugin/cargo.vim +++ b/vim-config/plugins/rust.vim/plugin/cargo.vim @@ -7,6 +7,7 @@ set cpoptions&vim command! -nargs=+ Cargo call cargo#cmd() command! -nargs=* Cbuild call cargo#build() +command! -nargs=* Ccheck call cargo#check() command! -nargs=* Cclean call cargo#clean() command! -nargs=* Cdoc call cargo#doc() command! -nargs=+ Cnew call cargo#new() diff --git a/vim-config/plugins/rust.vim/plugin/rust.vim b/vim-config/plugins/rust.vim/plugin/rust.vim old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/syntax/rust.vim b/vim-config/plugins/rust.vim/syntax/rust.vim old mode 100755 new mode 100644 index 4a419f40..8407b56e --- a/vim-config/plugins/rust.vim/syntax/rust.vim +++ b/vim-config/plugins/rust.vim/syntax/rust.vim @@ -15,7 +15,13 @@ endif " Syntax definitions {{{1 " Basic keywords {{{2 syn keyword rustConditional match if else -syn keyword rustRepeat for loop while +syn keyword rustRepeat loop while +" `:syn match` must be used to prioritize highlighting `for` keyword. +syn match rustRepeat /\/ +" Highlight `for` keyword in `impl ... for ... {}` statement. This line must +" be put after previous `syn match` line to overwrite it. +syn match rustKeyword /\%(\.\+\)\@<=\/ +syn keyword rustRepeat in syn keyword rustTypedef type nextgroup=rustIdentifier skipwhite skipempty syn keyword rustStructure struct enum nextgroup=rustIdentifier skipwhite skipempty syn keyword rustUnion union nextgroup=rustIdentifier skipwhite skipempty contained @@ -26,14 +32,14 @@ syn match rustExistentialContextual /\/ +syn match rustDefault /\/ +syn keyword rustAwait await +syn match rustKeyword /\!\@!/ display syn keyword rustPubScopeCrate crate contained syn match rustPubScopeDelim /[()]/ contained @@ -57,22 +65,14 @@ syn match rustExternCrateString /".*"\_s*as/ contained nextgroup=rustIdentifie syn keyword rustObsoleteExternMod mod contained nextgroup=rustIdentifier skipwhite skipempty syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained -syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained - -syn region rustBoxPlacement matchgroup=rustBoxPlacementParens start="(" end=")" contains=TOP contained -" Ideally we'd have syntax rules set up to match arbitrary expressions. Since -" we don't, we'll just define temporary contained rules to handle balancing -" delimiters. -syn region rustBoxPlacementBalance start="(" end=")" containedin=rustBoxPlacement transparent -syn region rustBoxPlacementBalance start="\[" end="\]" containedin=rustBoxPlacement transparent -" {} are handled by rustFoldBraces - -syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end=")" contains=TOP nextgroup=rustMacroRepeatCount -syn match rustMacroRepeatCount ".\?[*+]" contained +syn match rustFuncName "\%(r#\)\=\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained + +syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end="),\=[*+]" contains=TOP syn match rustMacroVariable "$\w\+" +syn match rustRawIdent "\ = ({ + fs::read_dir("test_data") + .unwrap() + .cloned() + }) + .collect(); + + println!("Hello World\n"); + } + +Do: + /collect\ + ostatement();\\ + +Expect rust (issue #195): + fn main() { + let paths: Vec<_> = ({ + fs::read_dir("test_data") + .unwrap() + .cloned() + }) + .collect(); + statement(); + + println!("Hello World\n"); + } + +############################################ +# Issue #189 + +Given rust: + impl X for { + pub fn get(&self, key: &Q) -> Option> + where + K: Borrow, + Q: Ord + ?Sized, + { + self.inner.get(key).map(Entry::new) + } + } + +Do: + vip= + +Expect rust (issue #189): + impl X for { + pub fn get(&self, key: &Q) -> Option> + where + K: Borrow, + Q: Ord + ?Sized, + { + self.inner.get(key).map(Entry::new) + } + } + +############################################ +# Issue #189b + +Given rust: + impl X for { + pub fn get(&self, key: &Q) -> Option> + where + K: Borrow, + Q: Ord + ?Sized + { + self.inner.get(key).map(Entry::new) + } + } + +Do: + vip= + +Expect rust (issue #189b): + impl X for { + pub fn get(&self, key: &Q) -> Option> + where + K: Borrow, + Q: Ord + ?Sized + { + self.inner.get(key).map(Entry::new) + } + } + +############################################ +# Issue #189c + +Given rust: + impl X for { + pub fn get(&self, key: &Q) -> Option> + where K: Borrow, Q: Ord + ?Sized + { + self.inner.get(key).map(Entry::new) + } + } + +Do: + vip= + +Expect rust (issue #189b): + impl X for { + pub fn get(&self, key: &Q) -> Option> + where K: Borrow, Q: Ord + ?Sized + { + self.inner.get(key).map(Entry::new) + } + } + + +############################################ +# Issue #149 + +Given rust: + fn test() { + let t = "a + wah"; + } + +Do: + /wah\ + i#\\ + /;\o + statement();\\ + +# Disabled +# Expect rust (issue #149): + fn test() { + let t = "a + #wah"; + statement(); + } + + +############################################ +# Issue #77 + +Given rust: + fn test() { + } + +Do: + of(x, y,\z);\ + f((x, y),\z);\ + +# Disabled +# Expect rust (issue #77): + fn test() { + f(x, y, + z); + f((x, y), + z); + + } + +############################################ +# Issue #44 + +Given rust: + fn main() { + a + + let philosophers = vec![ + Philosopher::new("Judith Butler"), + Philosopher::new("Gilles Deleuze"), + Philosopher::new("Karl Marx"), + Philosopher::new("Emma Goldman"), + Philosopher::new("Michel Foucault"), + ]; + } + +Do: + /let\ + vip= + +# Disabled +# Expect rust (issue #44): + fn main() { + a + + let philosophers = vec![ + Philosopher::new("Judith Butler"), + Philosopher::new("Gilles Deleuze"), + Philosopher::new("Karl Marx"), + Philosopher::new("Emma Goldman"), + Philosopher::new("Michel Foucault"), + ]; + } + +############################################ +# Issue #5 + +Given rust: + fn f() { + if x && + y { + } + } + +Do: + vip= + +Expect rust (issue #5): + fn f() { + if x && + y { + } + } + +############################################ +# Issue #366 + +Given rust: + fn f() { + g(|_| { + h(); + }) + .unwrap(); + h(); + } + +Do: + vip= + +Expect rust (issue #366): + fn f() { + g(|_| { + h(); + }) + .unwrap(); + h(); + } + +Given rust: + fn f() { + let a = g(|_| { + h(); + }) + .unwrap(); + h(); + } + +Do: + vip= + +Expect rust (issue #366, variation #2): + fn f() { + let a = g(|_| { + h(); + }) + .unwrap(); + h(); + } + +############################################ + +Given rust: + fn f() { + let mut state = State::new( + backend, + header.clone(), + ).expect("Something"); + } + +Do: + vip= + +Expect rust (Trailing comma in call): + fn f() { + let mut state = State::new( + backend, + header.clone(), + ).expect("Something"); + } diff --git a/vim-config/plugins/rust.vim/test/run-tests b/vim-config/plugins/rust.vim/test/run-tests index a8c63b60..9e11ba5c 100755 --- a/vim-config/plugins/rust.vim/test/run-tests +++ b/vim-config/plugins/rust.vim/test/run-tests @@ -67,9 +67,9 @@ def image_exists(): def tests_on_docker(): res = docker_run("bash -lc 'python /home/vimtest/run-tests inside-docker'", ok_fail=True) if res == 0: - print "Tests OK" + print("Tests OK") else: - print "Tests Failed" + print("Tests Failed") sys.exit(1) def inside_docker(): @@ -92,7 +92,7 @@ def main(): return if not image_exists(): - print "Need to take image from remote" + print("Need to take image from remote") system("docker pull %s" % (IMAGE, )) if "-i" in sys.argv[1:]: diff --git a/vim-config/plugins/rust.vim/test/sample.rs b/vim-config/plugins/rust.vim/test/sample.rs old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/test/vimrc b/vim-config/plugins/rust.vim/test/vimrc old mode 100755 new mode 100644 diff --git a/vim-config/plugins/rust.vim/triagebot.toml b/vim-config/plugins/rust.vim/triagebot.toml new file mode 100644 index 00000000..fa0824ac --- /dev/null +++ b/vim-config/plugins/rust.vim/triagebot.toml @@ -0,0 +1 @@ +[assign]