summaryrefslogtreecommitdiffstats
path: root/autoload/rust
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2018-12-26 10:41:57 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2018-12-26 10:41:57 +0100
commitd43b70d93987c94d15a352cf0026fb93d3317cc8 (patch)
tree74470b6cc30ddb4ef8ceb2ec557bc32ccccb5ebb /autoload/rust
parentec1c94306953b678bb36572897bd218fe6c76506 (diff)
downloadvim-polyglot-d43b70d93987c94d15a352cf0026fb93d3317cc8.tar.gz
vim-polyglot-d43b70d93987c94d15a352cf0026fb93d3317cc8.zip
Update
Diffstat (limited to '')
-rw-r--r--autoload/rust.vim39
-rw-r--r--autoload/rust/debugging.vim6
-rw-r--r--autoload/rustfmt.vim26
3 files changed, 50 insertions, 21 deletions
diff --git a/autoload/rust.vim b/autoload/rust.vim
index 77c38b7c..81f8c635 100644
--- a/autoload/rust.vim
+++ b/autoload/rust.vim
@@ -445,12 +445,12 @@ function! s:SearchTestFunctionNameUnderCursor() abort
let cursor_line = line('.')
" Find #[test] attribute
- if search('#\[test]', 'bcW') is 0
+ if search('\m\C#\[test\]', 'bcW') is 0
return ''
endif
" Move to an opening brace of the test function
- let test_func_line = search('^\s*fn\s\+\h\w*\s*(.\+{$', 'eW')
+ let test_func_line = search('\m\C^\s*fn\s\+\h\w*\s*(.\+{$', 'eW')
if test_func_line is 0
return ''
endif
@@ -462,19 +462,36 @@ function! s:SearchTestFunctionNameUnderCursor() abort
return ''
endif
- return matchstr(getline(test_func_line), '^\s*fn\s\+\zs\h\w*')
+ return matchstr(getline(test_func_line), '\m\C^\s*fn\s\+\zs\h\w*')
endfunction
function! rust#Test(all, options) abort
- let pwd = expand('%:p:h')
- if findfile('Cargo.toml', pwd . ';') ==# ''
+ let manifest = findfile('Cargo.toml', expand('%:p:h') . ';')
+ if manifest ==# ''
return rust#Run(1, '--test ' . a:options)
endif
- let pwd = shellescape(pwd)
+ if exists(':terminal')
+ let cmd = 'terminal '
+ else
+ let cmd = '!'
+ let manifest = shellescape(manifest)
+ endif
if a:all
- execute '!cd ' . pwd . ' && cargo test ' . a:options
+ if a:options ==# ''
+ execute cmd . 'cargo test --manifest-path' manifest
+ else
+ execute cmd . 'cargo test --manifest-path' manifest a:options
+ endif
+ return
+ endif
+
+ let mod_name = expand('%:t:r')
+ if mod_name ==# ''
+ echohl ErrorMsg
+ echo 'Cannot extract a module name from file name. Please add ! to command if you want to run all tests'
+ echohl None
return
endif
@@ -487,7 +504,13 @@ function! rust#Test(all, options) abort
echohl None
return
endif
- execute '!cd ' . pwd . ' && cargo test ' . func_name . ' ' . a:options
+ let spec = mod_name . '::' . func_name
+ if a:options ==# ''
+ execute cmd . 'cargo test --manifest-path' manifest spec
+ else
+ execute cmd . 'cargo test --manifest-path' manifest spec a:options
+ endif
+ return
finally
call setpos('.', saved)
endtry
diff --git a/autoload/rust/debugging.vim b/autoload/rust/debugging.vim
index ff88e00c..ba91c3bd 100644
--- a/autoload/rust/debugging.vim
+++ b/autoload/rust/debugging.vim
@@ -73,6 +73,12 @@ function! rust#debugging#Info() abort
echo l:output
version
+
+ if exists(":SyntasticInfo")
+ echo "----"
+ echo "Info from Syntastic:"
+ execute "SyntasticInfo"
+ endif
endfunction
function! rust#debugging#InfoToClipboard() abort
diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim
index 916736c0..7b8fdd91 100644
--- a/autoload/rustfmt.vim
+++ b/autoload/rustfmt.vim
@@ -24,18 +24,17 @@ endif
function! rustfmt#DetectVersion()
" Save rustfmt '--help' for feature inspection
silent let s:rustfmt_help = system(g:rustfmt_command . " --help")
- let s:rustfmt_unstable_features = 1 - (s:rustfmt_help !~# "--unstable-features")
+ let s:rustfmt_unstable_features = s:rustfmt_help =~# "--unstable-features"
" Build a comparable rustfmt version varible out of its `--version` output:
- silent let s:rustfmt_version = system(g:rustfmt_command . " --version")
- let s:rustfmt_version = matchlist(s:rustfmt_version, '\vrustfmt ([0-9]+[.][0-9]+[.][0-9]+)')
-
- if len(s:rustfmt_version) < 3
+ silent let l:rustfmt_version_full = system(g:rustfmt_command . " --version")
+ let l:rustfmt_version_list = matchlist(l:rustfmt_version_full,
+ \ '\vrustfmt ([0-9]+[.][0-9]+[.][0-9]+)')
+ if len(l:rustfmt_version_list) < 3
let s:rustfmt_version = "0"
else
- let s:rustfmt_version = s:rustfmt_version[1]
+ let s:rustfmt_version = l:rustfmt_version_list[1]
endif
-
return s:rustfmt_version
endfunction
@@ -46,7 +45,7 @@ if !exists("g:rustfmt_emit_files")
endif
if !exists("g:rustfmt_file_lines")
- let g:rustfmt_file_lines = 1 - (s:rustfmt_help !~# "--file-lines JSON")
+ let g:rustfmt_file_lines = s:rustfmt_help =~# "--file-lines JSON"
endif
let s:got_fmt_error = 0
@@ -87,11 +86,9 @@ function! s:RustfmtCommandRange(filename, line1, line2)
let l:write_mode = s:RustfmtWriteMode()
let l:rustfmt_config = s:RustfmtConfig()
- " FIXME: When --file-lines gets to be stable, enhance this version range checking
+ " FIXME: When --file-lines gets to be stable, add version range checking
" accordingly.
- let l:unstable_features =
- \ (s:rustfmt_unstable_features && (s:rustfmt_version < '1.'))
- \ ? '--unstable-features' : ''
+ let l:unstable_features = s:rustfmt_unstable_features ? '--unstable-features' : ''
let l:cmd = printf("%s %s %s %s %s --file-lines '[%s]' %s", g:rustfmt_command,
\ l:write_mode, g:rustfmt_options,
@@ -119,6 +116,8 @@ function! s:RunRustfmt(command, tmpname, fail_silently)
mkview!
let l:stderr_tmpname = tempname()
+ call writefile([], l:stderr_tmpname)
+
let l:command = a:command . ' 2> ' . l:stderr_tmpname
if a:tmpname ==# ''
@@ -133,7 +132,8 @@ function! s:RunRustfmt(command, tmpname, fail_silently)
if exists("*systemlist")
silent let out = systemlist(l:command, l:buffer)
else
- silent let out = split(system(l:command, l:buffer), '\r\?\n')
+ silent let out = split(system(l:command,
+ \ join(l:buffer, "\n")), '\r\?\n')
endif
else
if exists("*systemlist")