Sublime3, ruby programming, autocomplete - show a class' methods (like java, actually) - ruby

I am new to Sublime and to Ruby. I have been developing Java for 10+ years, and what I miss, is: autocomplete, in the meaning of:
using: Sublime3 (ok if had to switch to 2 to get this option) + Rails.
issue: I want: I type: "MyClass. [DOT]" say: I type the dot
and then: a list of methods of this class are displayed. These methods that are defined by default (as of heritage), and those that I have defined, in the class definition.
I am aware of the 'duck-typing' style, such: also these methods, that this object itself is able to use, would be a plus.
While, I would be happy with the first two (heritage and self.methods).
Yes I am aware that the Ruby-community is sort of pure coding; I like it also, and I also appreciate an editor that helps.
I have read through answers in GITHUB, and I could not figure out if that is existing or not .. it seems, the Ruby-people do not understand this Java-coding idea.
Thank you for any link or answer.

Sublime is a text editor, is not an IDE. In the Java world you are likely used to write your code with IDE (such as Netbeans, Eclipse, Intellij IDEA), I have never seen Java developers using a pure text editor.
There are some IDE for Ruby. However, the highly dynamic and loosely typed nature of Ruby makes it really hard to provide an accurate IntelliSense code completion. Both the assumption that the Ruby community pretends to be pure, or Ruby-people do not understand Java-coding idea are simply wrong. Several Ruby developers approached the language from Java, therefore they are perfectly aware of how the Java world works.
If you feel more comfortable with an IDE, try to search for a Ruby one. RubyMine is a great product, and if you come from Java world you may already be familiar with Intellij IDEA. There are also plugins for Netbeans and Eclipse, but the runtime evaluation capabilities of RubyMine are far superior and it's also the most up-to-date.
Most of text editors, such as TextMate, Sublime Text, Atom, etc understands Ruby and provide Ruby syntax highlighting and additional features, some of them even autocompletion, but IDE-level features as you would expect from the Java world.

Autocomplete is possible in Sublime - there are several packages for Python, including the excellent Anaconda plugin. Coverage for Ruby isn't quite as deep, but I did find SublimeRsense which may fit your needs. The README implies that it's for Atom, but I think that's just left over from another repo. I'm not a Rubyist, so I didn't install it, but the directions looked pretty straightforward.
That being said, depending on your personal preferences and knowledge, an IDE may work better for you. Of course, it'll take up a lot more room on your HD and in memory, and may get in your way at times, but with that comes many more features that you won't find in a text editor, even one as advanced as Sublime. Try them both out, and use what works for you. Personally, I prefer Sublime over IDEs, as I find many of their "features" annoying, but you'll have to see what best matches your style and needs.

Related

Better autocomplete in VIM

All,
I have been working with vim for some time now, and love everything about it - there is only one thing I really miss from IDEs like RubyMine, and that is advanced autocompletion.
For reference, here is my standard VIM setup: https://github.com/wrwright/.vim
I have tried ctags with omnicomplete + supertab, and the one major element I miss is the ability to bring up a context sensitive list of attributes/constants/methods. For example, as I learn RubyMotion, I'd love to have some help remembering iOS SDK constants/attributes/methods, but my VIM autocomplete stops with suggesting class names..or if it does suggest methods/attributes, it lists a ton of methods/attributes that don't even apply to the class I'm working with.
I'd like to (simple example) be able to type UIColor.bl and have it autocomplete with UIColor.blueColor (or suggest if there are multiple options that start with "bl" that are properties of UIColor.
RubyMine does this very well, and if I can get VIM to be similarly smart with autocomplete it would be heavenly (and a great boon while learning RubyMotion/iOS Development.
I have also tried SnipMate (and even a RubyMotion tailored variation at https://github.com/rcyrus/snipmate-snippets-rubymotion), but that doesn't seem to offer the features I'm looking for either.
Relatively satisfied with stock Vim's omnicomplete + vim-ruby and vim-rails having completion abilities on par with NetBeans but with all the bells&whistles of Vim and much lower resource requirements, of course.
From my .vimrc concerning completion options :
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
One thing that I have had a bit of luck with Rubymotion is YouCompleteMe and enabling tag Support. you will need a lot of ram(YCM uses ~2GB when indexing a large tag file) because the tags that rubymotion uses are about 40k tags.
The downside is that the rubymotion people don't seem to want to review pull requests and provide any feedback so I am not sure if they will add the needed things to the rake task that creates the tag files for ycm to work correctly out of the box.
To get it to work you need to set the tags files correct
set tags=./tags;,tags;
and then you need to setup ycm to complete off tags.
let g:ycm_collect_identifiers_from_tags_files = 1
you need to make the ctags file compatible with ycm as well. This pull request does that. You need to add a language field to the ctags creation and then change bridgesupport to ruby.
pull request for that
after that you need to run rake ctags in the root of your project.
If you don't want to modify the project.rb file you could probably create your own rake task that does pretty much the same thing.
Yes, Vim is an awesome... text editor.
As such, it can't be expected to match any IDE's "code awareness". Furthermore, it completely relies on the community for providing more than default support for a given language. If google or the rubymotion site didn't help you to find a serious "autocompletion" solution I doubt you'll find it here.
The process explained in the blog post below sounds ok, if not very precise on the vim configuration front.
http://rayhightower.com/blog/2013/02/12/automatic-ctags-with-rubymotion-and-vim/

How to improve Netbeans for ruby slow performance?

I am developing Ruby application with Netbeans because of its automatic code completion and its inline help system.
But when Netbeans try to autocomplete the source code while typing, the typing looks like stopped.
Is there any way to improve this experience? Maybe by disabling the code completion, inline help system, syntax highlighting, etc?
You can disable extended type inference for methods (ie code completion -- showing what methods are available on an object) or rdoc (the inline help) from the NetBeans preferences. These settings are found under the Miscellaneous tab, under Ruby, in the section labeled "Enable extended type inference".
You can disable syntax highlighting by removing the appropriate file associations. This can be done under the Miscellaneous tab in the preferences, under "Files".
However you may consider exploring alternative editors or IDEs, as (depending upon which other features of the IDE you use or depend on) you may find that NetBeans is still slow and not providing much of an advantage over a simpler editor. I have also found the performance of RubyMine to be better than NetBeans for ruby projects, and there's something to be said for using a tool thats designed from the bottom up for the job you're trying to accomplish.

What are the most important IDE features missing in Vim?

I have been programming almost exclusively in Vim since 1/1/2001, and I feel that Vim fulfulls all my needs as an editor/IDE, but I can't help but wonder if perhaps there have been some new killer features developed for other IDEs in the last decade that would allow me to be more productive than I can be using Vim. So I ask: What are the most important IDE features missing in Vim??
Integrated debugging with all the fanciness that Visual Studio/Eclipse provide (thread debugging, etc etc)
Autocomplete with inline documentation support for methods/properties
Build and run from 'within' the editor application
I miss the excellent refactoring support and code tips from tools such as Resharper. Regexs are powerful for code modification, but understanding the code as Resharper does is just a tad better IMO.
Fortunately I can get both Resharper and Vim in Visual Studio so I am happy.
The real question is: what do VIM have that IDEs are missing.
I find that refactoring would be a real nice thing to have. Changing a java package name in vim with lots of source files can be pretty cumbersome.
Originally the refactoring was the killer feature that made us switch from Emacs. I have now used Eclipse extensively for Java for the last 6 years, and I expect any replacement to have:
Refactoring: Rename variables, functions, change method signatures (including all calls to it).
Debugging: "You are here" "Your current variables are" plus stuff like "go to the defined class for this object" or "go to the actual type for this object". I belive the latter requires quite a bit of integration between debugger and editor.
Code replacement while debugging. Change code, press Ctrl-S and the code in your debugging session is updated with what you just changed. A killer feature for big programs.
Navigation: Simple navigation of class hierarchy (please show me all implementations of this method in this interface and similar).
Javadoc integration - Eclipse can show javadoc just by hovering the mouse over an identifier.
Plus some more :)
Edit: I occasionally miss the Emacs functionality inside Eclipse, but the Eclipse editor has become stronger so it is not so bad anymore. In this regard the Save Action allowing a Format at every save was a killer. This ensures that changes show up properly in the source repository.
Search in files: In most editors, there is a separate window doing the search in files, and simultaneously editing can continue on the main window. The search results are updated as and when they are found. Also the current results can be viewed by clicking on it, even when the searching is ongoing, without waiting for the entire search to be completed.(whereas in cim one has to wait till vimgrep/ctags has finished to view the results)
This is particularly useful for search in large number of files.
So basically something like a search in background and simultaneously show results which can be clicked on to view them simultaneously.
(something like Microsoft Visual Studio 6.0 does)
The things I missed were code completion and debugging. That's why I started using eclim http://eclim.sourceforge.net/index.html so I could use vim for what it does best and eclipse when I actually need it. Try it out - it's a fantastic combination.
It's like the old question "What's worn under a kilt?"
Answer: "Nothing. Everything's in perfect working order!".
But seriously, I'd like to see a more intuitive (easy to use) help system added to Vim.
There is nothing missing in Vim that an IDE has. The only thing we could argue about is; Vim needs to be customized and IDE comes out of the box.
Let me comment the other answeres and how to solve such "needs".
build
As mentioned, use :make and learn how to customize it.
refactoring
Use the very well known ropevim (for Python), it makes a great reafactoring tool. You won't need more than that. There are many others, search for your language.
Autocompletion
I use this snippet together with mapping to TAB (I think supertab plugin does that)
" python stuff
python << EOF
import os
import sys
import vim
for p in sys.path:
if os.path.isdir(p):
vim.command(r"set path+=%s" % (p.replace(" ", r"\ ")))
EOF
" tags for python libs
set tags+=~/.vim/tags/python.ctags
autocmd FileType python,mako set omnifunc=pythoncomplete#Complete
autocmd FileType html,mako set omnifunc=htmlcomplete#Complete
autocmd FileType html,mako set omnifunc=htmlcomplete#CompleteTags
autocmd FileType mako set filetype=mako.html.js
Help system
in Vim is perfect, you just have to learn it's system. It has it's own conventions how are things organized.
Debugging
I don't know for other languages than Python, but running pdb and !python % does it's job.

Ruby source code analyzer (something like pylint)

Does Ruby have any tools along the lines of pylint for analyzing source code for errors and simple coding standards?
It would be nice if it could be integrated with cruisecontrolrb for continuous integration.
Or does everyone write such good tests that they don't need source code checkers!
I reviewed a bunch of Ruby tools that are available here
http://devver.wordpress.com/2008/10/03/ruby-tools-roundup/
most of the tools were mentioned by webmat, but if you want more information I go pretty in depth with examples.
I also highly recommend using Metric-Fu it gives you a on gem/plugin install of 3 of the more popular tools and is built with cruisecontrolrb integration in mind.
The creator has a great post that should help get you up and running in no time.
http://jakescruggs.blogspot.com/2008/04/dead-simple-rails-metrics-with-metricfu.html
There has been a lot of activity in Ruby tools lately which I think is a good sign of a growing and maturing language.
Check these out:
on Ruby Inside, an article presenting Towelie, Flay and Simian, all tools to find code duplication
Towelie
flay
Simian (a more general tool that supports Ruby among other languages)
reek: a code smell detector for Ruby
Roodi: checks the style of your Ruby code
flog: a code complexity analyzer
rcov: will give you a C0 (if I remember correctly) code coverage analysis. But be careful though. 100% coverage is very costly and doesn't mean perfect code.
heckle: changes your code in subtle manners and runs your test suite to see if it catches it. Brutal :-)
Since they're all command-line tools they can all be integrated simply as cc.rb tasks. Just whip out your regex skillz to pick the important part of the output.
I recommend you first try them out by hand to see if they play well with your codebase and if you like the info they give you. Once you find a few that give you value, then spend time integrating them in your cc.
One recently-updated interesting-looking tool is Ruby Object Oriented Design Inferometer - roodi for short. It's at v1.3.0, so I'm guessing it's fairly mature.
I haven't tried it myself, because my code is of course already beyond reproach (hah).
As for test coverage (oh dear, I haven't tried this one either) there's rcov
Also (look, I am definitely going to try some of these today. One at least) you might care to take a look at flog and flay for another style checker and a refactoring candidate finder.
There's also the built-in warnings you can enable with a quick:
ruby -w
Or setting the global variable $VERBOSE to true at any point.
Code metrics on ruby toolbox website.
Rubocop is a widely-used static code analyzer.
I just released Excellent which implements several checks on Ruby code. It combines roodi, reek and flog and also adds some Rails specific checks:
gem sources -a http://gems.github.com
sudo gem install simplabs-excellent
May be helpful...

A couple of questions on the architecture of Ruby

I am primarily a fluent .NET developer (as can be seen from the amount of posts and threads I make about .NET), but I thought it would be good to learn RoR.
In doing so, I have a few questions about the architecture of the language (Ruby) and the framework (RoR):
1) In .NET, every object is derived from System but inherits System.Object. So when I type System., I get a list of namespaces and then in those namespaces, classes and more namespaces.
Does Ruby not have this sort of hierarchy?
2) In some cases, I don't get the intellisense. For example, I wrote the class as outlined here (http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer) but in the line recipients user.email, nothing comes up when I type "user.".
Any idea why?
Thank
Dave Thomas (Pragmatic Programmers) has an excellent screencast series on the Ruby object model/metaprogramming. We watched this in a local Ruby user's group. The series isn't free, but it's not expensive either. You might want to check out the free preview to see if you think it is worth your time.
And to give you an answer. Yes, everything in Ruby derives from Object. You can find the docs on this at http://corelib.rubyonrails.org/. Look for the Object class.
I'm not sure why you aren't getting intellisense, partly because you haven't specified your IDE. It's possible that you can't because you've added the method dynamically and no intellisense is available.
If we compare .NET to Rails then yes, there is this kind of hierarchy there. And in general, you can achieve this kind of hierarchy in any Ruby application via using modules.
I guess it's because of Ruby's dynamic nature.
Ruby is a pure OO language meaning that everything from classes to objects derive from the Object class.
Download NetBeans. There is full intellisense support for Ruby and Ruby on Rails.
http://www.netbeans.org/features/ruby/index.html
Intellisense support probably won't get you what you think it will get you. Because Ruby is a dynamic language, Intellisense, or code completion, is difficult. What you will find is that either the drop down is so flooded with possible completions as to be useless. Or in your case nothing at all.
It's not 100% useless, but I have never found it terribly valuable.

Resources