├── .gitignore
├── LICENSE
├── README.md
├── doc
└── ruby-autocomplete.txt
└── ftplugin
└── ruby.vim
/.gitignore:
--------------------------------------------------------------------------------
1 | tags
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Philip Mayer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vim-ruby-autocomplete
2 | Vim/Neovim ruby autocompletion with help of solargraph and vim language server
3 |
4 | This plugin is based on following blog
5 | [post](https://blog.schembri.me/post/solargraph-in-vim/) by [Jamie Schembri](https://github.com/shkm).
6 |
7 | ## Demo
8 | 
9 |
10 |
11 | Tested on:
12 | * Arch Linux (Manjaro)
13 | * Ruby 2.6.\*
14 |
15 | ## Requirements
16 | This plugin supports linux only
17 |
18 | ### Gems
19 | * gem install solargraph rdoc irb rubocop yarn
20 |
21 | Add gem bins to PATH in your .bashrc:
22 | * Check your ruby version!
23 | * PATH=$PATH:$HOME/.gem/ruby/your-ruby-version/bin
24 |
25 | ### Vim Plugins
26 | * [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)
27 |
28 | ## Configuration
29 | By default the plugin will start solargraph each time if vim is opened.
30 | Additional you can add/modify this hotkeys to refactor and go to definition:
31 | ``` vim
32 | nnoremap :call LanguageClient_contextMenu()
33 | nnoremap K :call LanguageClient#textDocument_hover()
34 | nnoremap gd :call LanguageClient#textDocument_definition()
35 | nnoremap :call LanguageClient#textDocument_rename()
36 | ```
37 | You can also add a .solargraph.yml
to your project root folder to include/exclude
38 | ruby files or require additional gems:
39 | ``` yml
40 | ---
41 | include:
42 | - "**/*.rb"
43 | exclude:
44 | - spec/**/*
45 | - test/**/*
46 | - vendor/**/*
47 | require:
48 | - rails
49 | reporters: []
50 | domains: []
51 | plugins: []
52 | ```
53 |
54 | ## Usage
55 | By default completion can be triggered with CTRL-X + CTRL-O
56 |
57 | Follwing optional variables are available for your .vimrc
58 | ``` vim
59 | let g:ruby_autocomplete_solargraph = ''
60 | " If you dont use rvm the path should be like:
61 | " ~/.gem/ruby//bin/solargraph
62 |
63 | ```
64 |
65 | ### [Completor](https://github.com/maralla/completor.vim)
66 | Add following in your .vimrc:
67 | ``` vim
68 | let g:completor_ruby_omni_trigger = '([$\w]{1,}|\.[\w]*|::[$\w]*)$'
69 | ```
70 |
71 | ### [MUComplete](https://github.com/lifepillar/vim-mucomplete) and [Supertab](https://github.com/ervandew/supertab)
72 | On default configuration pushich TAB
should do the trick.
73 |
74 | ### [Neocomplete](https://github.com/Shougo/neocomplete.vim)
75 | ``` vim
76 | let g:neocomplete#sources#omni#input_patterns = {
77 | \ "ruby" : '[^. *\t]\.\w*\|\h\w*::',
78 | \}
79 |
80 | ```
81 |
82 | ## Documentation
83 | For additional information write follwing in Vim:
84 | ``` vim
85 | :help ruby-autocomplete
86 |
87 | ```
88 |
89 | ## Issues
90 | Sometimes the solargraph socket server will not start by default
91 | than you need to restart vim.
92 |
93 | ## TODO
94 | * Async startup of solargraph instead of synchronous waiting time
95 |
96 | ## See also
97 | There are similiar plugins to vim-ruby-autocomplete but I couldn't get them to work
98 | on my systems. That was the initial idea to write this small plugin.
99 | * [vim-solargraph](https://github.com/hackhowtofaq/vim-solargraph)
100 | * [vim-monster](https://github.com/osyo-manga/vim-monster)
101 | * [deoplete-solargraph](https://github.com/uplus/deoplete-solargraph) (deoplete only)
102 |
--------------------------------------------------------------------------------
/doc/ruby-autocomplete.txt:
--------------------------------------------------------------------------------
1 | *ruby-autocomplete* Vim version 8.1 Last change: 2019 Mar 07
2 |
3 | Author: Shadowsith
4 | Source: https://github.com/Shadowsith/vim-ruby-autocomplete
5 | License: MIT
6 |
7 | ==============================================================================
8 | CONTENTS *ruby-autocomplete-contents*
9 |
10 | 1. Introduction................ |ruby-autocomplete-introduction|
11 | 2. Requirements................ |ruby-autocomplete-requirements|
12 | 3. Installation................ |ruby-autocomplete-installation|
13 | 4. Configuration............... |ruby-autocomplete-configuration|
14 | 5. Getting started............. |ruby-autocomplete-getting-started|
15 | 6. Completion methods.......... |ruby-autocomplete-methods|
16 | 7. Troubeshooting.............. |ruby-autocomplete-troubeshooting|
17 | 8. Providing feedback.......... |ruby-autocomplete-feedback|
18 |
19 | ==============================================================================
20 | 1. Introduction *ruby-autocomplete-introduction*
21 |
22 | vim-ruby-autocomplete is a small plugin to easy use the solargraph ruby
23 | completion server with help of LanguageClient-neovim for Vim8/Neovim.
24 |
25 | It is only a wrapper that starts/stops solargraph for you and provides
26 | information how to use this plugin with vim completion engines like
27 | completor or deoplete and was made because existing ruby-completion plugins
28 | didn't worked for the author.
29 |
30 | Tested system configurations:
31 | - Arch/Manjaro Linux
32 | - Ruby 2.6.*
33 | - Vim 8.1
34 | - Terminal: Konsole
35 |
36 | ==============================================================================
37 | 2. Requirements *ruby-autocomplete-requirements*
38 |
39 | To use this plugin you need Vim8 or Neovim with python support installed.
40 |
41 | As additional third-party-requirements you have to install ruby and
42 | following gems:
43 |
44 | $ gem install rdoc yarn solargraph irb rubocop
45 |
46 | After Solargraph has installed you need to add the follwing line
47 | into your .bashrc:
48 |
49 | PATH=$PATH:$HOME/.gem/ruby//bin
50 |
51 | This ensures that your cli finds your solargraph binary files.
52 |
53 | You also need the LanguageClient-neovim plugin by autozimu:
54 | https://github.com/autozimu/LanguageClient-neovim
55 |
56 | ==============================================================================
57 | 3. Installation *ruby-autocomplete-installation*
58 |
59 | It is very recommended to use one of various plugin managers for vim
60 | to install vim-ruby-autocomplete and the required LanguageClient-neovim.
61 |
62 | Please read the instructions of one of them how to install the plugin:
63 | * Pathogen https://github.com/tpope/vim-pathogen
64 | * Vundle https://github.com/VundleVim/Vundle.vim
65 | * Vim-Plug https://github.com/junegunn/vim-plug
66 | * Dein https://github.com/Shougo/dein.vim
67 |
68 | ==============================================================================
69 | 4. Configuration *ruby-autocomplete-configuration*
70 |
71 | You need to add following variable to your .vimrc:
72 |
73 | let g:ruby_autocomplete_solargraph =
74 |
75 | The path should be something like
76 | ~/.gem/ruby//bin/solargraph
77 |
78 | When correctly installed the plugin will autostart Solargraph every time
79 | after Vim has started. It will use stdio mode and works directly.
80 |
81 | T==============================================================================
82 | 5. Getting started *ruby-autocomplete-getting-started*
83 |
84 | If all requirements are installed correctly you can test the autocompletion
85 | by execute the Vim's omnifunc hotkey
86 |
87 | If you are more familiar with to trigger autocompletion you could
88 | add this setting on your .vimrc:
89 |
90 | ==============================================================================
91 | 6. Completion methods *ruby-autocomplete-methods*
92 |
93 | If you use Vim as active developing plattform it is recommended to use one
94 | of serveral completion engines. Here are a view examples how to setup them
95 | with this plugin.
96 |
97 | MUComplete/Supertab:
98 | With both plugins completion should be enabled on pushing tab.
99 |
100 | Completor:
101 | let g:completor_ruby_omni_trigger = '([$\w]{1,}|\.[\w]*|::[$\w]*)$'
102 |
103 | Neocomplete:
104 | let g:neocomplete#sources#omni#input_patterns = {
105 | \ "ruby" : '[^. *\t]\.\w*\|\h\w*::',
106 | \}
107 |
108 |
109 | ==============================================================================
110 | 7. Troubeshooting *ruby-autocomplete-troubeshooting*
111 |
112 | If errors occur / autocompletion does not work please be sure that:
113 |
114 | - All requirements are installed correctly
115 | - Bash knows the PATH of solargraph
116 | $ solargraph help or $ which solargraph
117 | - Start the solargraph socket server and show if errors are thrown
118 | $ solargraph socket
119 | - In Vim open :terminal and test if solargraph is running:
120 | $ ps -aux | grep solargraph
121 | - Look if Vim throws errors on the status/execution line
122 |
123 | ==============================================================================
124 | 8. Providing feedback *ruby-autocomplete-feedback*
125 |
126 | If troubeshooting does not get a positive result for you write a issue
127 | at the GitHub Repository page:
128 |
129 | Please write given information in the post:
130 | - Linux OS and version
131 | - Ruby version
132 | - installed Vim package
133 | - terminal
134 |
135 | https://github.com/Shadowsith/vim-ruby-autocomplete
136 |
137 | You can also add feature requests or if you have a good idea and knowledge
138 | about VimScript you can fork this plugin and write pull requests.
139 |
140 |
--------------------------------------------------------------------------------
/ftplugin/ruby.vim:
--------------------------------------------------------------------------------
1 | let g:ruby_autocomplete_solargraph = get(g:, 'ruby_autocomplete_solargraph', 0)
2 |
3 | let g:LanguageClient_serverCommands = {
4 | \ 'ruby': [g:ruby_autocomplete_solargraph, 'stdio']
5 | \ }
6 |
7 | autocmd FileType ruby setlocal omnifunc=LanguageClient#complete
8 |
--------------------------------------------------------------------------------