Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ee6853d

Browse files
author
piou
committed
Initial
1 parent 657c3ef commit ee6853d

File tree

4 files changed

+146
-1
lines changed

4 files changed

+146
-1
lines changed

‎README.md

100644100755
Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
1-
# vim-solargraph
1+
vim-solargraph
2+
===============
3+
24
vim plugin (wrapper) for Solargraph - IDE tools for the Ruby language.
5+
6+
7+
NOTES
8+
-----
9+
10+
Please consider this as a first prototype ALPHA version, just to prove that it can be done.
11+
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+
14+
15+
INSTALLATION
16+
------------
17+
18+
TODO
19+
20+
#### vim-plug
21+
22+
23+
24+
25+
### Vim package
26+
27+
$
28+
$
29+
$ git clone https://github.com/hail2u/vim-css3-syntax.git
30+
31+
32+
33+
### Manual
34+
35+
Download `vim-solargraph.tar.gz` from GitHub, extract it, and copy the contents
36+
to your `~/.vim` directory.
37+
38+
39+
40+
41+
42+
AUTHOR
43+
------
44+
45+
George Lazaridis <glaz330-vim@yahoo.com>

‎ftplugin/ruby.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"setlocal completefunc=solargraph#CompleteSolar
2+
setlocal omnifunc=solargraph#CompleteSolar

‎plugin/main.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'rest-client'
2+
require 'json'
3+
4+
class VimSolargraph
5+
def initialize
6+
VIM::message "Parsing files..."
7+
@cw = VIM::Window.current
8+
@cb = VIM::Buffer.current
9+
10+
@text = VIM::evaluate( %Q(join(getline(1, '$'), "\\n")) ) + "\n"
11+
@filename = VIM::evaluate("expand('%:p')")
12+
@line = @cw.cursor[0] - 1
13+
@column = @cw.cursor[1]
14+
@workspace = VIM::evaluate('getcwd()')
15+
16+
#puts @text.size
17+
#puts @text
18+
#puts @filename
19+
#puts @line
20+
#puts @column
21+
#puts @workspace
22+
end
23+
24+
25+
def suggest
26+
#RestClient.post "http://localhost:7657/prepare"
27+
data = RestClient.post "http://localhost:7657/suggest",
28+
{
29+
"text": @text,
30+
"filename": @filename,
31+
"line": @line,
32+
"column": @column,
33+
"workspace": @workspace,
34+
"with_snippets": nil
35+
}
36+
37+
response = JSON.parse(data.body).to_hash
38+
39+
#puts response["suggestions"].collect { |x| x["insert"]}
40+
return response["suggestions"].collect { |x| x["insert"]}
41+
end
42+
43+
end

‎plugin/solargraph.vim

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /