module RDoc::RbsSupport
RBS type signature support. Loads type information from .rbs files and validates inline annotations.
Public Class Methods
Source
# File lib/rdoc/rbs_support.rb, line 37 def self.load_signatures(*dirs) loader = RBS::EnvironmentLoader.new(core_root: nil) dirs.each { |dir| loader.add(path: Pathname(dir)) } env = RBS::Environment.new loader.load(env: env) signatures = {} env.class_decls.each do |type_name, entry| class_name = type_name.to_s.delete_prefix('::') entry.each_decl do |decl| decl.members.each do |member| case member when RBS::AST::Members::MethodDefinition key = member.singleton? ? "#{class_name}::#{member.name}" : "#{class_name}##{member.name}" sigs = member.overloads.map { |o| o.method_type.to_s } signatures[key] = sigs.join("\n") when RBS::AST::Members::AttrReader, RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor key = "#{class_name}.#{member.name}" signatures[key] = member.type.to_s end end end end signatures end
Loads RBS signatures from the given directories. Returns a Hash mapping “ClassName#method_name” => “type sig string”.
Source
# File lib/rdoc/rbs_support.rb, line 71 def self.merge_into_store(store, signatures) store.all_classes_and_modules.each do |cm| cm.method_list.each do |method| next if method.type_signature key = method.singleton ? "#{cm.full_name}::#{method.name}" : "#{cm.full_name}##{method.name}" method.type_signature = signatures[key] if signatures[key] end cm.attributes.each do |attr| next if attr.type_signature key = "#{cm.full_name}.#{attr.name}" attr.type_signature = signatures[key] if signatures[key] end end end
Merges loaded RBS signatures into the store’s code objects. Inline #: annotations take priority and are not overwritten.
Source
# File lib/rdoc/rbs_support.rb, line 15 def self.validate_method_type(sig) RBS::Parser.parse_method_type(sig, require_eof: true) nil rescue RBS::ParsingError => e e.message end
Validates an RBS method type signature string. Returns nil if valid, or an error message string if invalid.
Source
# File lib/rdoc/rbs_support.rb, line 26 def self.validate_type(sig) RBS::Parser.parse_type(sig, require_eof: true) nil rescue RBS::ParsingError => e e.message end
Validates an RBS type signature string. Returns nil if valid, or an error message string if invalid.