Skip to content

Commit 2aeba8c

Browse files
author
piou
committed
Update README + add dbakker/vim-projectroot dependency
1 parent bcefb0e commit 2aeba8c

File tree

3 files changed

+144
-24
lines changed

3 files changed

+144
-24
lines changed

README.md

Lines changed: 139 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,164 @@ vim plugin (wrapper) for Solargraph - IDE tools for the Ruby language.
77
NOTES
88
-----
99

10-
Please consider this as a first prototype ALPHA version, just to prove that it can be done.
10+
Please consider this as a first prototype **pre ALPHA** version, just to prove that it can be done.
11+
1112
I am not familiar with vimscript, so most of vimscript code is trial and error + a lot of googling.
12-
This plugin was written in 10 hours after the initial idea.
13+
This plugin was written in 10 hours after the initial idea (first commit).
1314

1415

1516
INSTALLATION
1617
------------
1718

18-
TODO
19+
I've tested this only on Linux. If you think you can make it work on Windows or Mac please submit a patch.
20+
21+
22+
### Prerequisites (my setup)
23+
24+
25+
* Install Ruby (2.4.1)
26+
* Compile vim with `+ruby` support
27+
* `gem install json rest-client solargraph`
28+
* Install [dbakker/vim-projectroot](https://github.com/dbakker/vim-projectroot)
29+
1930

2031
#### vim-plug
2132

33+
Add the following
34+
35+
`Plug 'hackhowtofaq/vim-solargraph'`
36+
37+
38+
### Manual (Not ready yet)
39+
40+
Download `vim-solargraph.tar.gz` from GitHub, extract it, and copy the contents to your `~/.vim` directory.
41+
42+
43+
### neocomplete
44+
45+
If you are using [neocomplete](https://github.com/Shougo/neocomplete.vim) keep reading.
46+
47+
The following is my neocomplete setup. I am still experimenting, trying to find the optimal settings for ruby code.
48+
49+
```vim
50+
" neocomplete {
51+
52+
" Neosnipet
53+
" Note: It must be "imap" and "smap". It uses <Plug> mappings.
54+
" SuperTab like snippets' behavior.
55+
imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
56+
\ "\<Plug>(neosnippet_expand_or_jump)"
57+
\: pumvisible() ? "\<C-n>" : "\<TAB>"
58+
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
59+
\ "\<Plug>(neosnippet_expand_or_jump)"
60+
\: "\<TAB>"
61+
62+
let g:acp_enableAtStartup = 0
63+
let g:neocomplete#enable_at_startup = 1
64+
let g:neocomplete#auto_completion_start_length = 1
65+
let g:neocomplete#enable_refresh_always = 1
66+
let g:neocomplete#enable_fuzzy_completion = 0
67+
let g:neocomplete#enable_smart_case = 1
68+
let g:neocomplete#enable_auto_delimiter = 1
69+
let g:neocomplete#enable_auto_select = 1
70+
let g:neocomplete#enable_underbar_completion = 1
71+
let g:neocomplete#enable_camel_case_completion = 1
72+
73+
if !exists('g:neocomplete#force_omni_input_patterns')
74+
let g:neocomplete#force_omni_input_patterns = {}
75+
endif
76+
let g:neocomplete#force_omni_input_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
77+
78+
" Define keyword.
79+
if !exists('g:neocomplete#keyword_patterns')
80+
let g:neocomplete#keyword_patterns = {}
81+
endif
82+
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
83+
84+
" Enable heavy omni completion.
85+
if !exists('g:neocomplete#sources#omni#input_patterns')
86+
let g:neocomplete#sources#omni#input_patterns = {}
87+
endif
88+
89+
if !exists('g:neocomplete#same_filetypes')
90+
let g:neocomplete#same_filetypes = {}
91+
endif
92+
let g:neocomplete#same_filetypes.ruby = 'eruby'
93+
94+
let g:neocomplete#data_directory = $HOME . '/.vim/cache/neocomplete'
95+
96+
" Enable omni-completion.
97+
autocmd Filetype ruby,eruby setlocal omnifunc=solargraph#CompleteSolar
98+
99+
" } neocomplete
100+
```
101+
102+
103+
WORKSPACE (solargraph)
104+
---------
105+
106+
A folder having one of the following entries in it, is assumed to be the workspace folder.
107+
108+
```
109+
['.projectroot', '.git', '.hg', '.svn', '.bzr', '_darcs', 'build.xml']
110+
```
111+
112+
113+
114+
USAGE
115+
-----
116+
117+
* Download something big :P [discourse](https://github.com/discourse/discourse/archive/v1.8.5.tar.gz)?
118+
119+
OR
120+
121+
* Create file `a.rb` and paste
122+
123+
```ruby
124+
# a.rb
125+
class A
126+
def testInstanceA
127+
end
128+
129+
def self.testClassA
130+
end
131+
end
132+
```
133+
134+
* Create file `a.rb` and paste
135+
136+
```ruby
137+
# b.rb
138+
class B
139+
def testInstanceB
140+
end
141+
142+
def self.testClassB
143+
end
144+
end
145+
```
22146

147+
* Start solargraph server `$ solargraph server`
23148

24149

25-
### Vim package
150+
* Create file `test.rb`
26151

27-
$
28-
$
29-
$ git clone https://github.com/
152+
```ruby
153+
# test.rb
30154

155+
ca = A.new
156+
A.te # <---- You should see testClassA
157+
ca.te # <---- You should see testInstanceA
31158

32159

33-
### Manual
160+
cb = B.new
161+
B.te # <---- You should see testClassB
162+
cb.te # <---- You should see testInstanceB
34163

35-
Download `vim-solargraph.tar.gz` from GitHub, extract it, and copy the contents
36-
to your `~/.vim` directory.
164+
```
37165

38166

167+
Without `neocomplete` use `CTRL+x CTRL+o` shortcut to autocomplete after the dot `.`
39168

40169

41170

ftplugin/ruby.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
"setlocal completefunc=solargraph#CompleteSolar
22
setlocal omnifunc=solargraph#CompleteSolar
3-
"call RubySolarPrepare()
43
execute RubySolarPrepare()

plugin/solargraph.vim

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,24 @@ execute 'rubyfile ' . s:plugindir
1212
"" https://github.com/ctrlpvim/ctrlp.vim/issues/59
1313
"" Or else use https://github.com/dbakker/vim-projectroot
1414
"function! s:setcwd()
15-
function! s:Setcwd()
16-
if exists("g:SessionLoad") | retu | en
15+
function! s:rubySolarSetcwd()
1716
let cph = expand('%:p:h', 1)
18-
if cph =~ '^.\+://' | retu | en
19-
for mkr in ['.git/', '.hg/', '.svn/', '.bzr/', '_darcs/', '.vimprojects']
20-
let wd = call('find'.(mkr =~ '/$' ? 'dir' : 'file'), [mkr, cph.';'])
21-
if wd != '' | let &acd = 0 | brea | en
22-
endfo
23-
"exe 'lc!' fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '.', ''))
24-
"echomsg fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '', ''))
25-
let s:workspace = fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '', ''))
26-
return s:workspace
17+
"echomsg projectroot#guess(cph)
18+
return projectroot#guess(cph)
2719
endfunction
2820

2921

3022
function! RubySolar()
3123
"echom "Hello, world!"
3224
ruby << EOF
33-
ko = VimSolargraph.new( VIM::evaluate("s:Setcwd()") )
25+
ko = VimSolargraph.new( VIM::evaluate("s:rubySolarSetcwd()") )
3426
VIM::command("return #{ko.suggest.inspect}")
3527
EOF
3628
endfunction
3729

3830
function! RubySolarPrepare()
3931
ruby << EOF
40-
ko = VimSolargraph.new( VIM::evaluate("s:Setcwd()") )
32+
ko = VimSolargraph.new( VIM::evaluate("s:rubySolarSetcwd()") )
4133
ko.prepare
4234
EOF
4335
endfunction

0 commit comments

Comments
 (0)