How to use TypeProf
for IDE
First, try it with an already-configured repository!
rbenv install 3.1.0
git clone https://github.com/mame/rbswiki
cd rbswiki && bundle install
rbs collection install
- install VSCode extension for TypeProf to your VSCode
- open the
rbswiki
folder by VSCode - open
lib/rbswiki/wiki.rb
If everything goes well, you will see guessed signatures for each method:
Troubleshooting
- Make sure that you are using ruby 3.1.0.
$ ruby -v
ruby 3.1p0 (2021-12-25 revision fb4df44d16) [x86_64-linux]
- Check if typeprof version is 0.21.2 or later.
$ bundle exec typeprof --version
typeprof 0.21
- Check if TypeProf can analyze
lib/rbswiki/wiki.rb
within one second.
$ bundle exec typeprof lib/rbswiki/wiki.rb
# TypeProf 0.21.2
# Classes
module RBSWiki
class Wiki
@content: Hash[String, String]
#...
- See the log of "Ruby TypeProf" in vscode's "OUTPUT" panel.
How to configure TypeProf for your code
- Write
gem "typeprof"
to yourGemfile
, and runbundle install
- Write
rbs_collection.yaml
, and runrbs collection install
- Test if TypeProf works well by running
bundle exec typeprof your_code.rb
- Open your repository with vscode
Troubleshooting
- Note that in bash,
~/.bashrc
and~/.bash_profile
do not contain scripts that assume that pseudo-TTYs are available (such as thebind
command).- TypeProf for IDE will run
typeprof --version
at startup to parse STDOUT and make sure the proper version is running. - If the
.bashrc
contains a command that requires a pseudo-TTY, such as thebind
command, unexpected error messages will be output to STDOUT, and the LSP server will stop because it fails to parse the execution results of thetypeprof
command.
- TypeProf for IDE will run
Protips, limitation, unimplemented features, ...
TypeProf for IDE is extremely preliminary! Please give it a try with a warm heart...
- Write a simple (type-level) test in each file with
if $0 == __FILE__
guard to guide TypeProf to infer method signatures. - Use
require
only for loading gems. To load your code, userequire_relative
instead ofrequire
. (Or, createbin/typeprof
and pass-Ilib
. TBD for details) - Currently, TypeProf for IDE loads
typeprof.rbs
at the top folder. (I'll need to improve it to readsig/
directory) - TypeProf for IDE analyzes each file within one second. Unfortunately, it takes very long to analyze big code, or complex code, or code that requires a big gem. In this case, TypeProf for IDE cannot show any guesses. Splitting a file or manually writing RBS may make the analysis faster. (TBD for details)
- Unfortunately, TypeProf may report some false positive errors that you cannot stop. I'll create an option to configure error level.
- TypeProf for IDE tries to invoke TypeProf as follows:
- If your repository has
bin/typeprof
executable, it is invoked. - Otherwise, it will try to invoke a command specified in VS
typeprof.server.path
. - Otherwise, it will try to invoke
bundle exec typeprof
. - Otherwise, it will try to invoke
typeprof
. - Otherwise, TypeProf for IDE gives up.
- If your repository has
- Some people says TypeProf for IDE works with vim! (TBD for details)
How to develop TypeProf for IDE
See the [TypeProf VSCode document]).