Code completion limitation

Can the code completion capability within RubyMine find methods defined in other user-defined classes? Or is it just limited to the currently edited user-defined class and built-in Ruby/Rails classes?

Thanks,
Mark

14 comments

Hello Mark,

Can the code completion capability within RubyMine find methods
defined in other user-defined classes? Or is it just limited to the
currently edited user-defined class and built-in Ruby/Rails classes?


Of course, it can find methods in other user-defined classes.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

I'm using version 2.0.1, and I must not have it setup correctly then.

For example, lets say in class Sale I create the method calcTotal. If I am editing the class Register and in the code have a local variable 's' that is a reference to a Sale object, then when I type :

     s.c

I would have thought the code completion capability would have suggested calcTotal as one of the possibilities. I know it would in a Java/C++ IDE, but that's because those languages are compiled. This example I mention here doesn't work in TextMate, they only look within the currently edited file. I was just hoping you all had found a way to make it happen in Ruby.

Even if it can't, RubyMine is now my main IDE on my Mac.

Thanks,
Mark

0

Hello Mark,

Is this a Rails or a plain Ruby project? How exactly do you initialize the
variable?

I'm using version 2.0.1, and I must not have it setup correctly then.

For example, lets say in class Sale I create the method calcTotal. If
I am editing the class Register and in the code have a local variable
's' that is a reference to a Sale object, then when I type :

s.c

I would have thought the code completion capability would have
suggested calcTotal as one of the possibilities. I know it would in a
Java/C++ IDE, but that's because those languages are compiled. This
example I mention here doesn't work in TextMate, they only look within
the currently edited file. I was just hoping you all had found a way
to make it happen in Ruby.

Even if it can't, RubyMine is now my main IDE on my Mac.

Thanks,
Mark
---
Original message URL:
http://www.jetbrains.net/devnet/message/5257943#5257943

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

I loaded a directory that is a Rails project.

The two classes I have in that example are plain Ruby classes (not a subclass of ActiveRecord) within the project. All I was hoping for is that when I define methods in one class, then when I have a variable in another class that I'm editing that is referencing an object of that other class (and I know that is difficult in languages like Ruby and Smalltalk), the the code completion might give me a suggestion.

So back to the example, lets say that somewhere within the Register class I have the following code:

     s = Sale.new_instance

     ....

      s.c  <--- when I type this I would like to see all the methods defined in the class Sale that start with the letter 'c'.

But in order to do this the system would have to assume the variable 's' at this point is referencing an object of the class Sale. But in order to do this it would have needed to look into the Sale class and see a class method named new_instance and know that it's returning an object of type Sale. That's a neat trick given the extreme late bound nature of Ruby.

Mark

0

Please show a "new_instance" implementation, I suppose that RM wasn't able to infer return type from a method source code.

0

It's a very simple class method...

  def self.new_instance
    self.new
  end


But none the methods I define within that class show up in a code completion box when editing a reference to an object that class within another class.

Like I said, it would be a nice feature to have.

Mark
0

I think I see the problem.

I'm and old Smalltalker (been coding in Smalltalk since 1981), and I use self alot---even in class methods.

So that class method new_instance:

  def self.new_instance
    self.new
  end


Does a self new.

I just edited my code and replaced self with the name of the class (for example)

class Sale

  def self.new_instance
    Sale.new
  end


Now the code completion works.

You all (if you want) would need a way to interpret what self references in order for this to work.

Thanks,
Mark
0

It seems this works on my machine
Screen shot 2010-03-09 at 16.35.10.png

0

Is class Register in a different file???

Within the same file it works...not in a different file.

Mark

0

There is some bug in RubyMine type inference because sometimes methods from Sale class disappears in autocompletion list (even if all is defined in one file). We will check it.

0

Like I said, when I changed self.new within that class method to be explicit, i.e., Sale.new, the code completion logic works in other files.

Mark

0

I didn't manage to reproduce the bug in RubyMine 2.0.1 (my previous post was related to RM 2.0 build). Also I extracted Sale class to sale.rb and all also works ok.

0

In my case both variants works. Do you know some minimal scenario to reproduce it?

My example:
Project contains only 2 files: sale.rb and register.rb

# sale.rb
class Sale   def self.new_instance1     self.new   end   def self.new_instance2     Sale.new   end   def my_sale_method; end end



# register.rb

require "sale" class Register   def some     Sale.new_instance1.;     Sale.new_instance2.;   end end



In both cases autocompletion list contains my_sale_method
0

Well...i'll see if I can come up with a simple example.

I'm coding in Ruby (and not Rails) so there may be some limitations in terms of typing.

For example, if I'm iterating over a collection:

@my_sales.each {|a_sale| a_sale. <====

There is no way for RM to know that a_sale is an object of type Sale because how would RM know that I'm only putting instances of type Sale into the array @my_sales.

Java can only do it because in the iteration code I would have had to cast a_sale into a Sale ((Sale) a_sale)) in order for the IDE to know for code completion to  show methods defined in Sale.

RM could show a list of all instance methods that are user defined...it would be a long list, but it's better than nothing.

Thanks,
Mark

0

Please sign in to leave a comment.