Skip to content

Instantly share code, notes, and snippets.

@tk0miya
Created May 30, 2023 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk0miya/785c3bc17c7b6d8e6e68fdb865fcea8c to your computer and use it in GitHub Desktop.
Save tk0miya/785c3bc17c7b6d8e6e68fdb865fcea8c to your computer and use it in GitHub Desktop.
diff --git a/lib/rbs/prototype/rb.rb b/lib/rbs/prototype/rb.rb
index 646ed909..628e9878 100644
--- a/lib/rbs/prototype/rb.rb
+++ b/lib/rbs/prototype/rb.rb
@@ -109,8 +109,26 @@ module RBS
# Give up detect super class e.g. `class Foo < Struct.new(:bar)`
nil
end
+
+ const_to_name!(class_name).namespace.ascend.reject(&:empty?).reverse_each do |module_name|
+ _, name = module_name.split
+
+ mod = AST::Declarations::Module.new(
+ name: TypeName.new(name: name, namespace: Namespace.empty),
+ type_params: [],
+ self_types: [],
+ members: [],
+ annotations: [],
+ location: nil,
+ comment: comments[node.first_lineno - 1]
+ )
+
+ decls.push mod
+ decls = mod.members
+ end
+
kls = AST::Declarations::Class.new(
- name: const_to_name!(class_name),
+ name: TypeName.new(name: const_to_name!(class_name).name, namespace: Namespace.empty),
super_class: super_class,
type_params: [],
members: [],
diff --git a/test/rbs/rb_prototype_test.rb b/test/rbs/rb_prototype_test.rb
index d0955b75..142a50bd 100644
--- a/test/rbs/rb_prototype_test.rb
+++ b/test/rbs/rb_prototype_test.rb
@@ -19,6 +19,9 @@ module Foo
end
class Bar < Struct.new(:bar)
+end
+
+class Baz::Qux
end
EOR
@@ -35,6 +38,11 @@ module Foo
end
class Bar
+end
+
+module Baz
+ class Qux
+ end
end
EOF
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment