Skip to content

Commit

Permalink
update rust vim plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchuette committed Jan 6, 2022
1 parent 2b881f7 commit 6add34d
Show file tree
Hide file tree
Showing 35 changed files with 737 additions and 206 deletions.
9 changes: 9 additions & 0 deletions vim-config/plugins/rust.vim/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions vim-config/plugins/rust.vim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/doc/tags
10 changes: 10 additions & 0 deletions vim-config/plugins/rust.vim/.vintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmdargs:
# Checking more strictly
severity: style_problem

policies:
# Disable a violation
ProhibitUnnecessaryDoubleQuote:
enabled: false
ProhibitImplicitScopeVariable:
enabled: false
28 changes: 28 additions & 0 deletions vim-config/plugins/rust.vim/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Hi, and thanks for reporting an issue with rust.vim.
Details about your environment will help us assist you.
Please edit this template!
-->

* rust.vim version: <!-- Describe if you use a Vim plugin manager, and you
can use it to tell which version of rust.vim you are running. -->

Steps to reproduce:

<!-- It's best to try to reproduce the issue with the master version of
rust.vim. The issue may already be fixed! -->
_?_

Expected vs. actual behavior:

_?_

Paste debugging info from the Rust Vim plugin via _one_ of the following
commands: `:RustInfo`, `:RustInfoToClipboard`, or `:RustInfoToFile <filename>`.
<!-- To ensure these commands are available, open a Rust source file first. -->

_?_
86 changes: 57 additions & 29 deletions vim-config/plugins/rust.vim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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
Empty file modified vim-config/plugins/rust.vim/after/syntax/rust.vim
100755 → 100644
Empty file.
38 changes: 35 additions & 3 deletions vim-config/plugins/rust.vim/autoload/cargo.vim
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion vim-config/plugins/rust.vim/autoload/cargo/quickfix.vim
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
62 changes: 43 additions & 19 deletions vim-config/plugins/rust.vim/autoload/rust.vim
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -491,22 +499,39 @@ 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('<Plug>(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' "\<Plug>(MatchitNormalForward)"
endif
if line('.') < cursor_line
return ''
endif

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 '
" <count> 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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions vim-config/plugins/rust.vim/autoload/rust/debugging.vim
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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]))
Expand Down
Empty file modified vim-config/plugins/rust.vim/autoload/rust/delimitmate.vim
100755 → 100644
Empty file.
18 changes: 18 additions & 0 deletions vim-config/plugins/rust.vim/autoload/rust/tags.vim
Original file line number Diff line number Diff line change
@@ -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:
Loading

0 comments on commit 6add34d

Please sign in to comment.