Added `--doc` and `--symbolLocation` support to the Vim plugin

This commit is contained in:
IdanArye 2014-01-31 22:18:34 +02:00
parent d6930becc6
commit 1f7a9444e4
3 changed files with 34 additions and 0 deletions

View File

@ -56,6 +56,12 @@ Use `DCDclearCache` to clear the DCD server cache.
When the server is running, use `CTRL`+`x` `CTRL`+`o` in a D buffer to use DCD When the server is running, use `CTRL`+`x` `CTRL`+`o` in a D buffer to use DCD
completion. completion.
When the server is running, use the `DCDdoc` to print the doc-string of symbol
under the cursor.
When the server is running, use the `DCDsymbolLocation` to print jump to the
declaration of the symbol under the cursor.
Conflicts Conflicts
========= =========
This plugin conflicts with the DScanner plugin, as both use the `dcomplete` This plugin conflicts with the DScanner plugin, as both use the `dcomplete`

View File

@ -107,6 +107,28 @@ function! dcomplete#runDCDOnCurrentBufferPosition(args)
return s:runDCDOnBufferBytePosition(line2byte('.')+col('.')-1,a:args) return s:runDCDOnBufferBytePosition(line2byte('.')+col('.')-1,a:args)
endfunction endfunction
"Find where the symbol under the cursor is declared and jump there
function! dcomplete#runDCDtoJumpToSymbolLocation()
let l:scanResult=split(s:runDCDOnBufferBytePosition(line2byte('.')+col('.')-1,'--symbolLocation'),"\n")[0]
let l:resultParts=split(l:scanResult,"\t")
if 2!=len(l:resultParts)
echo 'Not found!'
return
endif
if l:resultParts[0]!='stdin'
execute 'edit '.l:resultParts[0]
endif
let l:symbolByteLocation=str2nr(l:resultParts[1])
if l:symbolByteLocation<1
echo 'Not found!'
return
endif
execute 'goto '.(l:symbolByteLocation+1)
endfunction
"Run DCD on the current buffer with the supplied position "Run DCD on the current buffer with the supplied position
function! s:runDCDOnBufferBytePosition(bytePosition,args) function! s:runDCDOnBufferBytePosition(bytePosition,args)
let l:tmpFileName=tempname() let l:tmpFileName=tempname()
@ -116,6 +138,9 @@ function! s:runDCDOnBufferBytePosition(bytePosition,args)
silent exec "write ".l:tmpFileName silent exec "write ".l:tmpFileName
let &fileformat=l:oldFileFormat let &fileformat=l:oldFileFormat
let scanResult=system(dcomplete#DCDclient().' '.a:args.' --cursorPos='.a:bytePosition.' <'.shellescape(l:tmpFileName)) let scanResult=system(dcomplete#DCDclient().' '.a:args.' --cursorPos='.a:bytePosition.' <'.shellescape(l:tmpFileName))
if v:shell_error
throw scanResult
endif
call delete(l:tmpFileName) call delete(l:tmpFileName)
return scanResult return scanResult
endfunction endfunction

View File

@ -12,3 +12,6 @@ command! -buffer -nargs=? DCDonCurrentBufferPosition echo dcomplete#runDCDOnCurr
command! -buffer DCDstopServer DCD --shutdown command! -buffer DCDstopServer DCD --shutdown
command! -buffer -nargs=+ -complete=dir DCDaddPath execute 'DCD '.dcomplete#globImportPath([<f-args>]) command! -buffer -nargs=+ -complete=dir DCDaddPath execute 'DCD '.dcomplete#globImportPath([<f-args>])
command! -buffer DCDclearCache DCD --clearCache command! -buffer DCDclearCache DCD --clearCache
command! -buffer DCDdoc DCDonCurrentBufferPosition --doc
command! -buffer DCDsymbolLocation call dcomplete#runDCDtoJumpToSymbolLocation()