Dynamic definitions and types provider for ruby static analysis
ruby-type-inferenceproject is a completely new approach to tackle the problems of Ruby dynamic nature and provide more reliable symbol resolution and type inference. It collects some run time data to build type contracts for the methods.
Every time a method is being called, some arguments of particular types are being passed to it. Type Tracker collects all such argument combinations and then builds a special contract which satisfies all encountered argument type tuples.
The approach has its own pros and cons: * The obtained contracts utilize real-world usages of code of any complexity so it provides true results even if a method utilizes dynamic Ruby features heavily. * The completeness of the contracts obtained for a method highly depends on the coverage of that method, including its callees. That implies the need to merge the data obtained from the different sources (e.g. different projects using the same gem).
This implementation addresses the stated coverage problem by providing the possibility to merge any type contracts at any time.
For simple usage you need to install the Ruby Dynamic Code Insight plugin for RubyMine. Then this plugin will require the arg_scanner gem to be installed. See arg_scanner installation instruction if you have problems while installation.
After that, you will have the possibility to run your programs under type tracker:
Or you can run your programs in terminal via the
rubymine-type-trackerbinary (But you have to keep your project opened in RubyMine). E.g.:
rubymine-type-tracker bin/rails server
rubymine-type-trackerbinary is included into the arg_scanner gem.
See FEATURES.md for understanding what benefits you will have after running your program under type tracker.
arg_scanner) and processes it to a compact format.
The data stored may be used later for better code analysis and also can be shared with other users.
Code analysis clients (a RubyMine/IJ+Ruby plugin) use the contract data to provide features for the users such as code completion, better resolution, etc.
(todo) Signature server receives contracts anonymously from the users and provides a compiled contract collections for popular gems.
There are two possibilities to use the type tracker: (I) using IJ/RubyMine plugin or (II) requiring it from Ruby code.
The easiest way to run the plugin (and the most convenient for its development) is running it with special gradle task against IJ Ultimate snapshot:
The task will compile the plugin, run IJ Ultimate with plugin "installed" in it. There is no need in running anything manually in that case.
If you want to try it with existing RubyMine instance, you should:
File | Settings | Plugins | Install plugin from disk...
Note that due to API changes the plugin may be incompatible with older RM instances.
In order to collect the data for the script needs a contract server to be up and running; it could be run by running
sh ./gradlew contract-creator:runServer --args path-to-db.mv.dbwhere
path-to-db.mv.dbis path where type contracts will be stored (H2 database file).
Use the data collected by the contract server.
Any kind of ideas, use cases, contributions and questions are very welcome as the project is just incubating. Please feel free to create issues for any sensible request.