Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable rbs collection support #53

Merged
merged 1 commit into from
Sep 21, 2021

Conversation

pocke
Copy link
Member

@pocke pocke commented Sep 11, 2021

This patch adds rbs collection feature to TypeProf.
See ruby/rbs#589 for more details of rbs collection.

TypeProf will behave the following by this patch.

  • If rbs_collection.yaml exists in the current directory, TypeProf loads libraries' RBSs from the config file.
  • If --collection PATH option is specified, TypeProf loads libraries' RBSs from the specified file.
  • If --no-collection option is specified, Typeprof ignores rbs_collection.yaml.
  • If rbs_collection.yaml doesn't exist and no options are specified, TypeProf does nothing about rbs collection feature.

The option names are the exactly same as rbs command's options.

Testing

I've confirmed the feature works with the following procedure.

  1. put the following files
    • Gemfile
      source 'https://rubygems.org'
      
      gem 'ast'
    • Gemfile.lock
      GEM
        remote: https://rubygems.org/
        specs:
          ast (2.4.2)
      
      PLATFORMS
        x86_64-linux
      
      DEPENDENCIES
        ast
      
      BUNDLED WITH
         2.2.27
      
    • rbs_collection.yaml
      # Download sources
      sources:
        - name: ruby/gem_rbs_collection
          remote: https://github.com/ruby/gem_rbs_collection.git
          revision: main
          repo_dir: gems
      
      # A directory to install the downloaded RBSs
      path: .gem_rbs_collection
      
      gems:
        # Skip loading rbs gem's RBS.
        # It's unnecessary if you don't use rbs as a library.
        - name: rbs
          ignore: true
      
    • test.rb
      require 'ast'
      
      class C
        def x(node)
          node.children
        end
      end
      
      node = AST::Node.new(:x, [:foo, 42])
      C.new.x node
      
  2. Run rbs collection install to install RBS for ast gem
  3. Run typeprof test.rb
    • It displays the following result.
      $ typeprof test.rb
      warning: rbs collection is experimental, and the behavior may change until RBS v2.0
      # TypeProf 0.15.3
      
      # Classes
      class C
        def x: (AST::Node node) -> Array[untyped]
      end
      
    • It is aware of ast gem's type 💪

@pocke pocke force-pushed the Enable_rbs_collection_support branch from bf5626d to 988ae84 Compare September 14, 2021 14:28
@pocke pocke force-pushed the Enable_rbs_collection_support branch from 988ae84 to 4a3804a Compare September 17, 2021 10:57
@pocke pocke changed the title WIP Enable rbs collection support Enable rbs collection support Sep 17, 2021
@pocke pocke marked this pull request as ready for review September 17, 2021 11:04
@mame mame merged commit 921fa49 into ruby:master Sep 21, 2021
@pocke pocke deleted the Enable_rbs_collection_support branch September 21, 2021 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants