I got "Rubymine type annotations" in the Development Roadmap, and anybody can explain what are rubymine type annotations? What can we benefit from these annotations?
This feature is planned to RubyMine 1.5 and isn't available in current version. Usually it is hard to inference type of method parameters, some ruby methods and etc. due to Ruby dynamic nature. So we suggest to add optional type annotations in comments, that will help RubyMine's type inference. E.g. something like this
# @name => :string, # @age => :integer def create_user(name, age) # here RubyMine will know that name is a string and age is integer # so age.chars() will be considered as error
User(name, age).new end
#or
# @id => :integer # @return => :SomeUser || :OtherUser def find_something(:id) # very sophisticated implementation end
If you annotate code your type inference will be smarter, otherwise RubyMine will try to inference type as usual.
I got "Rubymine type annotations" in the Development Roadmap, and anybody can explain what are rubymine type annotations? What can we benefit from these annotations? :)
We are planning to include some kind of type annotations in our type system to allow developers explicitly declare types for methods, parameters etc. This will be discussed, but seems it will be something like described in issue: http://www.jetbrains.net/jira/browse/RUBY-3196. Another point is that we are planning to provide some scripting API (to write code in Jruby) to allow developers to improve our existing type inference engine.
It'd be a nice touch if you could keep track of the parameter types passed/returned through the tests, and then automatically update these annotations for the developer.
E.g. If I have the model method
def full_address(address1, address2)
"#{address1} -- #{address2}"
end
and I make the following call from my unit test,
full_address('123 easy st','apt 116')
there's no reason you could keep track of the fact that full_address was passed two string and returned a string and update the YARD annotations accordingly.
Obviously there's the complicating issue of varying type being passed depending upon the calling context but the above may be a nice simple case to start with. Plus it would encourage developers to write tests since they'd reap the reward of better code inspection and auto generated Yard documentation/annotations. :)
It'd be a nice touch if you could keep track of the parameter types passed/returned through the tests, and then automatically update these annotations for the developer.
E.g. If I have the model method
def full_address(address1, address2)
"#{address1} -- #{address2}"
end
and I make the following call from my unit test,
full_address('123 easy st','apt 116')
there's no reason you could keep track of the fact that full_address was passed two string and returned a string and update the YARD annotations accordingly.
Actually this described approach can be divided into 2 separate ideas:
Track all the invocations of the given method and infer types of passed parameter from the invocations information. The problem is that this is a quite aggresive computation task for the RubyMine to perform it on the fly.
Hack your ruby tests to change methods annotations on the fly (via method objects) at runtime. RubyMine already supports Netbeans-like type annotation in comments, so if you modify source code from tests, RubyMine will pick up these type annotations.
Hi,
This feature is planned to RubyMine 1.5 and isn't available in current version. Usually it is hard to inference type of method parameters, some ruby methods and etc. due to Ruby dynamic nature. So we suggest to add optional type annotations in comments, that will help RubyMine's type inference. E.g. something like this
If you annotate code your type inference will be smarter, otherwise RubyMine will try to inference type as usual.
Hello chenlibing,
We are planning to include some kind of type annotations in our type system to allow developers explicitly declare types for methods, parameters etc.
This will be discussed, but seems it will be something like described in issue: http://www.jetbrains.net/jira/browse/RUBY-3196.
Another point is that we are planning to provide some scripting API (to write code in Jruby) to allow developers to improve our existing type inference engine.
So, stay tuned!
Thanks,
Oleg
I see that this is planned for Rubymine 3.1.
It'd be a nice touch if you could keep track of the parameter types passed/returned through the tests, and then automatically update these annotations for the developer.
E.g. If I have the model method
def full_address(address1, address2)
"#{address1} -- #{address2}"
end
and I make the following call from my unit test,
full_address('123 easy st','apt 116')
there's no reason you could keep track of the fact that full_address was passed two string and returned a string and update the YARD annotations accordingly.
Obviously there's the complicating issue of varying type being passed depending upon the calling context but the above may be a nice simple case to start with. Plus it would encourage developers to write tests since they'd reap the reward of better code inspection and auto generated Yard documentation/annotations. :)
Hello Jim,
Actually this described approach can be divided into 2 separate ideas:
The problem is that this is a quite aggresive computation task for the RubyMine to perform it on the fly.
Regards,
Oleg