pocke / rbs_rails

Apache License 2.0
285 stars 33 forks source link

FIX: RBS Rails writes blanks with RBS 3 #246

Closed mrdev023 closed 1 year ago

mrdev023 commented 1 year ago

Fix ISSUE #242

# 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

https://github.com/ruby/rbs/compare/v2.8.4...v3.0.4

image

mrdev023 commented 1 year ago

@pocke

pocke commented 1 year ago

Thanks!