Skip to content
Browse files

allow Gemfile gems to be parsed and required

  • Loading branch information...
1 parent f4c550e commit 8d7c6c081be8289630873144826eaed0770b90a5 tek committed Aug 6, 2013
Showing with 34 additions and 0 deletions.
  1. +26 −0 autoload/rubycomplete.vim
  2. +8 −0 doc/ft-ruby-omni.txt
View
26 autoload/rubycomplete.vim
@@ -266,6 +266,28 @@ class VimRubyCompletion
end
end
+ def load_gems
+ fpath = VIM::evaluate("get(g:, 'rubycomplete_gemfile_path', 'Gemfile')")
+ return unless File.file?(fpath) && File.readable?(fpath)
+ want_bundler = VIM::evaluate("get(g:, 'rubycomplete_use_bundler')")
+ parse_file = !want_bundler
+ begin
+ require 'bundler'
+ Bundler.setup
+ Bundler.require
+ rescue Exception
+ parse_file = true
+ end
+ if parse_file
+ File.new(fpath).each_line do |line|
+ begin
+ require $1 if /\s*gem\s*['"]([^'"]+)/.match(line)
+ rescue Exception
+ end
+ end
+ end
+ end
+
def load_buffer_class(name)
dprint "load_buffer_class(%s) START" % name
classdef = get_buffer_entity(name, 's:GetBufferRubyClass("%s")')
@@ -588,6 +610,10 @@ class VimRubyCompletion
load_rails
end
+ want_gems = VIM::evaluate("get(g:, 'rubycomplete_load_gemfile')")
+ load_gems unless want_gems.to_i.zero?
+
+
input = VIM::Buffer.current.line
cpos = VIM::Window.current.cursor[1] - 1
input = input[0..cpos]
View
8 doc/ft-ruby-omni.txt
@@ -36,5 +36,13 @@ Notes:
project. The feature is disabled by default, to enable it add >
let g:rubycomplete_rails = 1
< to your vimrc
+ - Vim can parse a Gemfile, in case gems are being implicitly required. To
+ activate the feature: >
+ let g:rubycomplete_load_gemfile = 1
+< To specify an alternative path, use: >
+ let g:rubycomplete_gemfile_path = 'Gemfile.aux'
+< To use Bundler.require instead of parsing the Gemfile, set: >
+ let g:rubycomplete_use_bundler = 1
+<
vim:tw=78:sw=4:ts=8:ft=help:norl:

0 comments on commit 8d7c6c0

Please sign in to comment.
Something went wrong with that request. Please try again.