summaryrefslogtreecommitdiffstats
path: root/autoload/rust.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2019-03-04 09:15:44 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2019-03-04 09:15:44 +0100
commited677c34d55a0e025b7008f29419498a3989cde2 (patch)
tree62efef78ed05b2b4e61efb21e40a6b337359eb8e /autoload/rust.vim
parentc161994e9607399a7b365ab274592bfc4f100306 (diff)
downloadvim-polyglot-ed677c34d55a0e025b7008f29419498a3989cde2.tar.gz
vim-polyglot-ed677c34d55a0e025b7008f29419498a3989cde2.zip
Update
Diffstat (limited to 'autoload/rust.vim')
-rw-r--r--autoload/rust.vim59
1 files changed, 43 insertions, 16 deletions
diff --git a/autoload/rust.vim b/autoload/rust.vim
index 81f8c635..d5a2e29f 100644
--- a/autoload/rust.vim
+++ b/autoload/rust.vim
@@ -5,23 +5,59 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
" Last Modified: May 27, 2014
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
-" Jump {{{1
-
-function! rust#Load()
+function! rust#Load()
" Utility call to get this script loaded, for debugging
endfunction
function! rust#GetConfigVar(name, default)
" Local buffer variable with same name takes predeence over global
- if has_key(b:, a:name)
+ if has_key(b:, a:name)
return get(b:, a:name)
endif
- if has_key(g:, a:name)
+ if has_key(g:, a:name)
return get(g:, a:name)
endif
return a:default
endfunction
+" Include expression {{{1
+
+function! rust#IncludeExpr(fname) abort
+ " Remove leading 'crate::' to deal with 2018 edition style 'use'
+ " statements
+ let l:fname = substitute(a:fname, '^crate::', '', '')
+
+ " Remove trailing colons arising from lines like
+ "
+ " use foo::{Bar, Baz};
+ let l:fname = substitute(l:fname, ':\+$', '', '')
+
+ " Replace '::' with '/'
+ let l:fname = substitute(l:fname, '::', '/', 'g')
+
+ " When we have
+ "
+ " use foo::bar::baz;
+ "
+ " we can't tell whether baz is a module or a function; and we can't tell
+ " which modules correspond to files.
+ "
+ " So we work our way up, trying
+ "
+ " foo/bar/baz.rs
+ " foo/bar.rs
+ " foo.rs
+ while l:fname !=# '.'
+ let l:path = findfile(l:fname)
+ if !empty(l:path)
+ return l:fname
+ endif
+ let l:fname = fnamemodify(l:fname, ':h')
+ endwhile
+ return l:fname
+endfunction
+
+" Jump {{{1
function! rust#Jump(mode, function) range
let cnt = v:count1
@@ -487,14 +523,6 @@ function! rust#Test(all, options) abort
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
-
let saved = getpos('.')
try
let func_name = s:SearchTestFunctionNameUnderCursor()
@@ -504,11 +532,10 @@ function! rust#Test(all, options) abort
echohl None
return
endif
- let spec = mod_name . '::' . func_name
if a:options ==# ''
- execute cmd . 'cargo test --manifest-path' manifest spec
+ execute cmd . 'cargo test --manifest-path' manifest func_name
else
- execute cmd . 'cargo test --manifest-path' manifest spec a:options
+ execute cmd . 'cargo test --manifest-path' manifest func_name a:options
endif
return
finally