pocke / rbs_rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RBS Rails writes blanks

DalenW opened this issue · comments

Somewhere along the line, RBS rails now generates blank model RBS files. I updated an old public repo I had to demonstrate this. (ignore the terrible code lol)

M6Securities/manius-market#57

Everything is running at the latest version. I did a little bit of digging, and it seems the issue is with this:

def format_rbs(rbs)
  StringIO.new.tap do |io|
    RBS::Writer.new(out: io).write(decls)
   end
end

Whatever RBS::Writer is generating, is blank. I don't know much else beyond that.

Same problem. It doesn't support rbs 3

Temporary fix:

Add gem 'rbs', '~> 2' or gem 'rbs_rails', git: 'https://github.com/mrdev023/rbs_rails.git', branch: 'master' in Gemfile

@DalenW

EDIT:

# parse_signature return 3 elements
def self.parse_signature(source)
    buf = buffer(source)
    dirs, decls = _parse_signature(buf, buf.last_position)

    [buf, dirs, decls]
end

# And write filter by type
def write(contents)
    dirs = contents.select {|c| c.is_a?(AST::Directives::Base) } #: Array[AST::Directives::t]
    decls = contents.select {|c| c.is_a?(AST::Declarations::Base) } #: Array[AST::Declarations::t]
    [...]
end

# It can be fixed with this code
def format_rbs(rbs)
    decls = RBS::Parser.parse_signature(rbs)
    decls = decls[1] + decls[2] if RBS::VERSION.start_with? '3.'
    StringIO.new.tap do |io|
        RBS::Writer.new(out: io).write(decls)
    end.string
end

Thanks for the fix! I'll have to give it a try when I get a chance.

This issue has been fixed so I close it.