lib/raap/rbs.rb in raap-0.6.0 vs lib/raap/rbs.rb in raap-0.8.0

- old
+ new

@@ -24,9 +24,51 @@ raise ArgumentError, "empty method type" if method_type == "" ::RBS::Parser.parse_method_type(method_type, require_eof: true) or raise end + def self.parse_member(member_type) + _, _, decls = ::RBS::Parser.parse_signature(<<~RBS) + module MemberScope + #{member_type} + end + RBS + decl = decls.first or raise + raise unless decl.is_a?(::RBS::AST::Declarations::Module) + + member = decl.members.first or raise + raise unless member.is_a?(::RBS::AST::Members::Attribute) + + member.tap do |m| + m = __skip__ = m + _shift_location(m.type, -m.location.start_pos) + _shift_location(m, -m.location.start_pos) + end + end + + def self._shift_location(localable, shift) + return if localable.location.nil? + + l = localable.instance_variable_get("@location") + localable.instance_variable_set( + "@location", + ::RBS::Location.new( + buffer: ::RBS::Buffer.new( + name: l.buffer.name, + content: l.buffer.content[-shift..l.end_pos], + ), + start_pos: l.start_pos + shift, + end_pos: l.end_pos + shift, + ) + ) + case localable + when ::RBS::Types::Union + localable.types.each { |t| _shift_location(t, shift) } + when ::RBS::Types::Optional + _shift_location(localable.type, shift) + end + end + def self.find_alias_decl(type_name, method_name) env.class_decls[type_name].decls.each do |d| d.decl.members.each do |member| case member when ::RBS::AST::Members::Alias