Code Completion

Here is the code:

require 'date'


dob = "08/04/1957"
d=Date.strptime(dob,"%m/%d/%Y")
puts d.month


When I type the last line "puts d." I get code completion for object and kernel but not Date. If I type "puts d.class" I get Date.
Why do I not get code completion for Date? BTW, If I just run the above code it works.

0

Hello Ron,

Here is the code:



require 'date'


dob = "08/04/1957"
d=Date.strptime(dob,"%m/%d/%Y")
puts d.month


When I type the last line "puts d." I get code completion for object and kernel but not Date. If I type "puts d.class" I get Date.
Why do I not get code completion for Date? BTW, If I just run the above code it works.

This happens because RubyMine wasn't able to infer the return type of call Date.strptime(dob,"%m/%d/%Y").
Our type inference system tries to extract type from comment of method in this case and cannot cope with it because it's description doesn't have any callseqs within.
Type inference engine depth restriction is insufficient in this case. So it's assumed that this is Object class type.

Regards,
Oleg

0

Hello Ron,

As a workaround you can copy the attached file explicit_types.rb to $RUBYMINE_INSTALLATION_FOLDER$/rb/scripts/
RubyMine API is not officially published yet but we'll definitely get it published before official release.

Regards,
Oleg



Attachment(s):
explicit_types.rb.zip
0

This link doesn't exist.

0

This is too complicated. I'm going back to Textmate.

0

What is complicated? If you don't want extend RM's code insight or wait until we improve something in type inference - you shouldn't write any extensions and RM will be still cleverer than TextMate

0

I've never written a Ruby extension.

0

Ron,

It was optional and isn't required by RubyMine's workflow.  

Also probably we didn't understand each other because I only mentioned extension to RubyMine using RubyMine's API in Ruby language and I didn't suggest to write extension for Ruby language or Ruby Core library. Several our users asked as to create some API in Ruby language for improving RubyMine code insight in their projects. API isn't ready yet but it is possible to use it and I gave your a link to an example.

0

I got it to work. I guess I don't understand why if it was that simple why wasn't it there in the first place?

0

Hi Roman, Netbeans 6.8m1 method return type support, it is a great idea.  I think we can introduce # :tyep:=>Date for variable to implement type inference, and it is very simple.



require 'date'
dob = "08/04/1975"
# :type:=>Date
date = Date.strptime(dob, "%m/%d/%Y")
puts date.month



# :type:=>Date  can help us resolve some simple problems, and "Ruby API for defining dynamic types" is the best, but some guys can not accept it.
0

Linux_china,

RubyMine also supports NB return type annotations, we added support several 1.5 EAP builds ago. But it isn't possible to annotate files from Ruby SDK or gems =)

0

Hi guys,

NB type annotations are supported only for methods return types now. We'll easily add them for local variables too if people really use them.

Regards,
Oleg

0

It is very useful for me.  I can not add annotation for third gem, but now I can use it for my variables.  

0

:) It is very useful for me.  I can not add annotation for third gem, but now I can use it for my variables.  

Done, this annotation will be available in next public build.

0

Trying to understand state of this a little better (resurrected this thread from a while ago).

My understanding is that with RM 3.0.1 the completion still does not take into account the return types of methods and shows methods only from Object/Kernel. Is that correct?

(Do I still have to extract the attached Ruby script and do something on my own to make completion work?)

thanks,
Kedar

0

My understanding is that with RM 3.0.1 the completion still does not take into account the return types of methods and shows methods only from Object/Kernel. Is that correct?

No, in general RubyMine infers return types where it can. At the moment the above example with Date is too complicated for our return type infer algorithm. So in the example as a workaround you may specify type explicitly using type annotations. I took a look on Date object implementation, most likely RubyMine doesn't infer Date.strptime type only due to some minor bugs or rare usecases in type inference algorithm.

0

In this particular case RubyMine cannot infer type, because of call depth restrictions during Infer Types Analyzis. Sorry for the inconveniences.

Regards,
Oleg

0

Is there some documentation or blog post available explaining how to use comments to improve type inference? I'm trying to do stuff like this but it doesn't work.


# :type: => User
def foo
  User.get(1)
end

foo.[invoke code completion]

0

What about being able to select type if Rubymine can't infer type?    

Like say I have a "params[:name]", it would be nice of I could quickly define the type (permenantly in a project config file).   If params[:name] is a string, Rubymine can't see it and you loose the code completion string methods.   I'd rather be able to specify the type insidie Rubymine real fast to see the string methods than go out to the API because I can't remember the exact method name I'm thinking of.

0

OK. Thanks.

How about the type annotations? Do I need to learn them separately?
And it seems that yardoc is the way to go when it comes to documenting the Ruby code the Javadoc style. So, can we configure RubyMine to use yardoc annotations when available for type inference?

Regards,
Kedar

0

And it seems that yardoc is the way to go when it comes to documenting the Ruby code the Javadoc style. So, can we configure RubyMine to use yardoc annotations when available for type inference?

Yard support isn't implemented, please vote for http://youtrack.jetbrains.net/issue/RUBY-5590.

0

Reno,

Good idea, please submit a feature request at http://youtrack.jetbrains.net/issues/ruby

0

Probably file with "User" class definition isn't required in a context of your example.

Screen shot 2011-01-09 at 1.20.57 PM.png

Is it rails application?

0

请先登录再写评论。