|
| 1 | + |
| 2 | +if exists("g:loaded_vim_solargraph") |
| 3 | + finish |
| 4 | +endif |
| 5 | +let g:loaded_vim_solargraph = 1 |
| 6 | + |
| 7 | + |
| 8 | +let s:plugindir = expand('<sfile>:p:h') . "/main.rb" |
| 9 | +execute 'rubyfile ' . s:plugindir |
| 10 | + |
| 11 | +function! RubySolar() |
| 12 | + "echom "Hello, world!" |
| 13 | + ruby << EOF |
| 14 | + ko = VimSolargraph.new |
| 15 | + VIM::command("return #{ko.suggest.inspect}") |
| 16 | +EOF |
| 17 | +endfunction |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +function! solargraph#CompleteSolar(findstart, base) |
| 22 | + if a:findstart |
| 23 | + " locate the start of the word |
| 24 | + let line = getline('.') |
| 25 | + let start = col('.') - 1 |
| 26 | + while start > 0 && line[start - 1] =~ '\a' |
| 27 | + let start -= 1 |
| 28 | + endwhile |
| 29 | + return start |
| 30 | + else |
| 31 | + " find classes matching "a:base" |
| 32 | + let res = [] |
| 33 | + let matches=RubySolar() |
| 34 | + for m in matches |
| 35 | + if m =~ '^' . a:base |
| 36 | + call add(res, m) |
| 37 | + endif |
| 38 | + endfor |
| 39 | + return res |
| 40 | + endif |
| 41 | +endfun |
| 42 | + |
| 43 | + |
| 44 | +"" https://github.com/ctrlpvim/ctrlp.vim/issues/59 |
| 45 | +"" Or else use https://github.com/dbakker/vim-projectroot |
| 46 | +function! s:setcwd() |
| 47 | + if exists("g:SessionLoad") | retu | en |
| 48 | + let cph = expand('%:p:h', 1) |
| 49 | + if cph =~ '^.\+://' | retu | en |
| 50 | + for mkr in ['.git/', '.hg/', '.svn/', '.bzr/', '_darcs/', '.vimprojects'] |
| 51 | + let wd = call('find'.(mkr =~ '/$' ? 'dir' : 'file'), [mkr, cph.';']) |
| 52 | + if wd != '' | let &acd = 0 | brea | en |
| 53 | + endfo |
| 54 | + exe 'lc!' fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '.', '')) |
| 55 | +endfunction |
| 56 | + |
| 57 | +autocmd BufEnter * call s:setcwd() |
0 commit comments