Vim plugin working on Windows and Linux, and support default import paths.

This commit is contained in:
IdanArye 2013-08-29 21:03:25 +03:00
parent 7fc2737ce3
commit 3dca325f6e
3 changed files with 41 additions and 6 deletions

View File

@ -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

View File

@ -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()

View File

@ -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().' '.<q-args>
command! -buffer DCDstopServer DCD --shutdown
command! -buffer -nargs=1 -complete=dir DCDaddPath DCD -I<args>
command! -buffer -nargs=+ -complete=dir DCDaddPath execute 'DCD '.dcomplete#globImportPath([<f-args>])