开发者

rails.vim with ruby omnicompletion giving "Error loading rails environment" error

I'm trying to get up and working with vim with ruby on rails and am having a few problems with omni-completion.

I have downloaded the rails.vim plugin for vim, which appears to be installed, with a vim call

:Rails! 

gives

rails.vim 4.3 (Rails-model-arb)

Calls to rails.vim specific functions like :Rcontroller work a dream so it all looks very promising. My problem is with omni-completion and syntax highlighting, when I ruby file for example Blog/app/models/post.rb with the following contents

1 class Post < ActiveRecord::Base
2   validates :name,  :presence => true
3   validates :title, :presence => true,
4                     :length   => { :minimum => 5 }
5   has_[<C-X><C-O> or <C-X><C-U> or <C-X><C-P>]
6 end

I expect supertab to use the rails omni-completion to provide me with options such as "has_many" etc. I'm a little muddled up as to what each of vims completion types do (keyword local completion, omni completion, user defined completion) from the rails documentation it suggests that user defined completion should provide this functionality. When try it gives the following error:

-- User defined completion (^U^N^P) Pattern not found
Press ENTER or type command to continue

when I try the first time:

Error loading rails environment
Problem loading class "Post", was it already completed?
Press ENTER or type command to continue

when I try another time it gives me -- Omni completion (^O^N^P) Pattern not found

However omnicompletion does work in many cases, for example if i type meth it will give me a list with method, method_defined?, method_missing, methods to choose from.

Im using pathogen to handle my vim files but my .vimrc file contains the following relavent lines.

set nocompatible
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
syntax on

filetype plugin on
filetype indent on

"set ofu=syntaxcomplete#Complete
set completeopt+=longest,menu,preview

" For code completion with a drop down menu
"au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
let g:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']
let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover']
let g:SuperTabContextDiscoverDiscovery = ["&completefunc:<c-x><c-u>", "&omnifunc:<c-x><c-o>"]

" If you prefer the Omni-Completion tip window to close when a selection is
" " made, these lines close it on movement in insert mode or when leaving
" " insert mode
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif

" Set up java autocompletion
:setlocal completefunc=javacomplete#CompleteParamsInfo
au FileType java set omnifunc=javacomplete#CompleteParamsInfo

" Adding ruby completion??
" Turn on language specific omnifuncs
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1

rails.vim is in the ~/.vim/bundle/ra开发者_如何学Cils directory, supertab works fine and is installed under ~/.vim/bundle/supertab

I've spent such a long time trying to figure this small thing out but have had no success! Does anyone have any ideas on where I should go from this? I believe it could be something todo with the supertab definitions in the .vimrc file, or the ruby omni-completion definitions.

If I remove the line

autocmd FileType ruby,eruby let g:rubycomplete_rails = 1

from the .vimrc file the error loading rails error disappears but of course there is no completion of the text, only a user defined completion error.

This is my first post on StackOverflow after a lot of viewing, I hope I have supplied all the relavent details!

I installed vim with MacPorts and my current version is vim @7.3.146_0+huge+perl+python27+ruby, ruby is enabled but macports wanted to install its own version, thus 1.8.7 is installed under /opt/local/ruby despite me using rvm and having 1.9.2 installed with rails 3.0.7. This could perhaps be the problem? I haven't found a way of telling macports to use a version of ruby which is already installed though.

Thanks for all your help!


I think the ruby completion is being overridden by the java line:

:setlocal completefunc=javacomplete#CompleteParamsInfo

If I comment that line out I can go into a model and do

has_<C-X><C-U>

to autocomplete has_many. (You shouldn't even need the autocmd FileType ruby,eruby ... lines.)

And yes it's smart in that n<C-X><C-U> will give you named_scope in a model but number_to_currency and friends in a view.

However rails.vim will not autocomplete custom methods, though I'm sure there are plugins out there that add that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜