From 3dca325f6ea48e8213c9ab7c504960fbf782d94a Mon Sep 17 00:00:00 2001 From: IdanArye Date: Thu, 29 Aug 2013 21:03:25 +0300 Subject: [PATCH] Vim plugin working on Windows and Linux, and support default import paths. --- editors/vim/README.md | 16 ++++++++++++++-- editors/vim/autoload/dcomplete.vim | 23 +++++++++++++++++++++-- editors/vim/ftplugin/d.vim | 8 ++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/editors/vim/README.md b/editors/vim/README.md index 315fe16..49b9be1 100644 --- a/editors/vim/README.md +++ b/editors/vim/README.md @@ -1,6 +1,6 @@ A plugin for using DCD with vim. -Tested on Linux +Tested on Linux(and a bit on Windows) Installation and Configuration ============================== @@ -9,13 +9,25 @@ Put the autoload and ftplugin folders in your vim runtime path. Compile DCD and put both dcd-client and dcd-server in your path, or set the global variable `g:dcd\_path` to where you put DCD. +You can set `g:dcd\_importPath` to an import path(or list of import paths) to +use when starting the server. You should do so for Phobos and DRuntime - since +DCD does not add them for you. On Linux it should be: + +```vim +let g:dcd_importPath=['/usr/include/d','/usr/include/d/druntime/import'] +``` + +On windows you need to look for the path in dmd's installation. + +Import paths are globbed with Vim's globbing function. + Usage =================== When the filetype is D, use the `DCDstartServer` command to start the server and the `DCDstopServer` command to stop the server. Use the `DCDaddPath` command to add an import path to the server. Make sure you -escape spaces! +escape spaces! Import paths are globbed with Vim's globbing function. Use the `DCD` command to send arbitary commands to the server via the client. The syntax is the same as with `dcd-client`, so you can use it without diff --git a/editors/vim/autoload/dcomplete.vim b/editors/vim/autoload/dcomplete.vim index f8f5307..1cabb34 100644 --- a/editors/vim/autoload/dcomplete.vim +++ b/editors/vim/autoload/dcomplete.vim @@ -44,7 +44,7 @@ endfunction "Get the DCD server command path function! dcomplete#DCDserver() if exists('g:dcd_path') - return shellescape(g:dcd_path).(has('win32') ? '\' : '/').'dcd-server' + return shellescape(g:dcd_path.(has('win32') ? '\' : '/').'dcd-server') else return 'dcd-server' end @@ -53,12 +53,31 @@ endfunction "Get the DCD client command path function! dcomplete#DCDclient() if exists('g:dcd_path') - return shellescape(g:dcd_path).(has('win32') ? '\' : '/').'dcd-client' + return shellescape(g:dcd_path.(has('win32') ? '\' : '/').'dcd-client') else return 'dcd-client' end endfunction +"Use Vim's globbing on a path pattern or a list of patterns and translate them +"to DCD's syntax. +function! dcomplete#globImportPath(pattern) + if(type(a:pattern)==type([])) + return join(map(a:pattern,'dcomplete#globImportPath(v:val)'),' ') + else + return join(map(glob(a:pattern,0,1),'"-I".shellescape(v:val)'),' ') + endif +endfunction + +"Get the default import path when starting a server and translate them to +"DCD's syntax. +function! dcomplete#initImportPath() + if exists('g:dcd_importPath') + return dcomplete#globImportPath(g:dcd_importPath) + endif + return '' +endfunction + "Run DCD to get autocompletion results function! s:runDCDToGetAutocompletion() diff --git a/editors/vim/ftplugin/d.vim b/editors/vim/ftplugin/d.vim index 830245a..176c9c6 100644 --- a/editors/vim/ftplugin/d.vim +++ b/editors/vim/ftplugin/d.vim @@ -1,6 +1,10 @@ setlocal omnifunc=dcomplete#Complete -command! -buffer DCDstartServer execute '!'.dcomplete#DCDserver().' > /dev/null &' +if has('win32') + command! -buffer DCDstartServer execute '!start '.dcomplete#DCDserver().' '.dcomplete#initImportPath() +else + command! -buffer DCDstartServer execute '!'.dcomplete#DCDserver().' '.dcomplete#initImportPath().' > /dev/null &' +endif command! -buffer -nargs=? DCD execute '!'.dcomplete#DCDclient().' '. command! -buffer DCDstopServer DCD --shutdown -command! -buffer -nargs=1 -complete=dir DCDaddPath DCD -I +command! -buffer -nargs=+ -complete=dir DCDaddPath execute 'DCD '.dcomplete#globImportPath([])