RubyMine and WxRuby 2.0.1 (win32) - code completion?
Hi,
trying to start a project using the newest WxRuby (2.0.1) under RubyMine using the WxRuby autoinstaller executable under Windows XP.
Pretty good success so far, but code completion/autocomplete would be a big help.
I cannot seem to get code completion to bring up classes or constants from the Wx:: namespace.
I have added the following paths under Preferences/Project Structure/Load Path:
c:/wxruby/ruby/lib/ruby/site_ruby/1.9.1
c:/wxruby/ruby/lib/ruby/site_ruby/1.9.1/wx
c:/wxruby/ruby/lib/ruby/site_ruby/1.9.1/wx/classes
I'm too much of a newbie to know any better, but I think the reason is that WxRuby is using a binary-only wrapper for the wxwidgets library.
From wx.rb:
# This wrapper serves three functions:
# 1. It loads the binary library 'wxruby2.so' or 'wxruby.dll', while
# still allowing applications to just require 'wx'.
# 2. It sets up the version information
# 3. It loads in ruby extensions to the core Wx classes.
The ruby extensions "rubify" the otherwise very c++-like library using lots of metaprogramming techniques. So maybe it's just not possible to get code completion here.
Any insight would be appreciated.
Lutz
请先登录再写评论。
Hell Lutz,
Have you configure Ruby SDK for c:/wx/ruby/bin/ruby.exe in RM | Settings | Ruby SDK and Gems ?
I've tried example from getting started and noticed that wx.rb contains code
RM cannot analyze this code and understand that it should require all ruby scripts from wx/classes. Thus lots of Wx classes/modules/methods/constants definitions are missed in RubyMine.
Matz Ruby interpreter also contains native part. RM cannot parse binary libs so we generated stubs for native Ruby methods, constants, class and modules declarations and RM use stubs for code insight features. Probably some of Wx constants are defined in native part of WxRuby.
I've filed feature request for Wx support - http://youtrack.jetbrains.net/issue/RUBY-5157
This load path is only for autocompletion/resolve of require path argument. Your ruby interpreter contain these folders in LOADPATH and RM should understand it automatically
Roman,
Thank you for your comments. You are fast :-) I have set up the Ruby SDK, in fact, it is the only ruby sdk on this machine.
I am able to create WxRuby windows, menus, buttons etc in a running application.
I will play with this some more. I was actually using their all-in-one installer (ruby 1.9.1.243 bundled). I will take the path names out again and check into the LOADPATH.
>> Matz Ruby interpreter also contains native part. RM cannot parse binary libs so we generated *stubs* for native methods, constants, class and modules declarations and RM use stubs for code insight features. Probably your constants >> are defined in native part of WxRuby or WxRuby automatically requires several ruby scripts and RM doesn't know about it.
That's what I am thinking also. The idea to define stubs for CodeInsight sounds intriguing, but surely I cannot just do something like this:
I tried redefining WX:: namespace constants in a stub, of course I'm getting a warning that the constants are already defined.
I may have to introduce constants like these for autocomplete to work:
Wx_YES = Wx::YES
unless someone has a better idea...
Thank you very much for filing a feature request for Wx support. I like the library because it pretty much works right out of the box under ruby 1.9.1/Windows without tracking down dependencies and gem building hell.
Again, thanks for your fast reply.
Lutz
For Ruby interpreter we've wrote stubs generator using 'rdoc' API. (E.g. it processes ruby C sources and we fetch information about classes/modules using smth like this:
Yes =). You shouldn't require this files on runtime. E.g. look at [RubyMine Installation direcotry]/rubystubs/builtin.rb. The file is attached for RubyMine's static code analyzed but file will not be really required on runtime. You can create stub script which requires all files from:
and add require call for your stub to [RubyMine Installation direcotry]/rubystubs/builtin.rb. We will consider adding some Ruby API for such use cases in next version for RubyMine