-
Notifications
You must be signed in to change notification settings - Fork 449
Change PrismRuby not to depend on hack that stores module nesting information to context.parent #1580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Change PrismRuby not to depend on hack that stores module nesting information to context.parent #1580
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,11 +59,6 @@ def with_container(container, singleton: false) | |||||||||||||
| @container = container | ||||||||||||||
| @singleton = singleton | ||||||||||||||
| @in_proc_block = false | ||||||||||||||
| unless singleton | ||||||||||||||
| # Need to update module parent chain to emulate Module.nesting. | ||||||||||||||
| # This mechanism is inaccurate and needs to be fixed. | ||||||||||||||
| container.parent = old_container | ||||||||||||||
| end | ||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this part to container.parent = old_container if !singleton && container.is_a?(RDoc::NormalClass)will minimize crossref difference of generated HTML between two parsers.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you this some examples of the diffs caused by this? It's not entirely clear to me.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really complicated. In class A; class B; class C; class D; class E; end; end; end; end; end
# Parent chain is:
# F → E → D → C → B → A → toplevel
class A::B::C
# Method comment A::B B::C C::D D::E
# (B::C is not linked because RDoc only search A::B::C and toplevel)
def f; end
module D::E
end
end
# Parent chain is updated. This imitates module nesting
# E → C → toplevel (changed)
# B → A → toplevel, D → C (unchanged)
# `B::C` in method comment is not linked because it can't be found from CSame situation for modules. It's strange that parent chain is not updated. Maybe bug or workaround for something. module M; module N; module O; module P; module Q; end; end; end; end; end
# Parent chain is:
# R → Q → P → O → N → M → toplevel
module M::N::O
# Method comment M::N N::O O::P P::Q
# All linked because RDoc searches M::N::O, M::N, M and toplevel
def f; end
endParent chain is emulating module nesting, used in crossref resolve, include/extend name resolve, superclass name resolve, etc. In this pull request, parent will no longer updated. Parent will exactly represent module/class owner, not module nesting. class RDoc::TopLevel < RDoc::Context
##
# Returns the NormalClass "Object", creating it if not found.
# (NormalClass can't be resolved in this module nesting but we often write this kind of comment)
def object_class
end
end
|
||||||||||||||
| @module_nesting.push([container, singleton]) | ||||||||||||||
| yield container | ||||||||||||||
| ensure | ||||||||||||||
|
|
@@ -482,12 +477,15 @@ def add_attributes(names, rw, line_no) | |||||||||||||
| end | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| # Adds includes/extends. Module name is resolved to full before adding. | ||||||||||||||
|
|
||||||||||||||
| def add_includes_extends(names, rdoc_class, line_no) # :nodoc: | ||||||||||||||
| return if @in_proc_block | ||||||||||||||
| comment, directives = consecutive_comment(line_no) | ||||||||||||||
| handle_code_object_directives(@container, directives) if directives | ||||||||||||||
| names.each do |name| | ||||||||||||||
| ie = @container.add(rdoc_class, name, '') | ||||||||||||||
| resolved_name = resolve_constant_path(name) | ||||||||||||||
| ie = @container.add(rdoc_class, resolved_name || name, '') | ||||||||||||||
| ie.store = @store | ||||||||||||||
| ie.line = line_no | ||||||||||||||
| ie.comment = comment | ||||||||||||||
|
|
@@ -590,7 +588,7 @@ def find_or_create_module_path(module_name, create_mode) | |||||||||||||
| else | ||||||||||||||
| @module_nesting.reverse_each do |nesting, singleton| | ||||||||||||||
| next if singleton | ||||||||||||||
| mod = nesting.find_module_named(root_name) | ||||||||||||||
| mod = nesting.get_module_named(root_name) | ||||||||||||||
| break if mod | ||||||||||||||
| # If a constant is found and it is not a module or class, RDoc can't document about it. | ||||||||||||||
| # Return an anonymous module to avoid wrong document creation. | ||||||||||||||
|
|
@@ -601,9 +599,9 @@ def find_or_create_module_path(module_name, create_mode) | |||||||||||||
| mod ||= add_module.call(last_nesting, root_name, :module) | ||||||||||||||
| end | ||||||||||||||
| path.each do |name| | ||||||||||||||
| mod = mod.find_module_named(name) || add_module.call(mod, name, :module) | ||||||||||||||
| mod = mod.get_module_named(name) || add_module.call(mod, name, :module) | ||||||||||||||
| end | ||||||||||||||
| mod.find_module_named(name) || add_module.call(mod, name, create_mode) | ||||||||||||||
| mod.get_module_named(name) || add_module.call(mod, name, create_mode) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| # Resolves constant path to a full path by searching module nesting | ||||||||||||||
|
|
@@ -614,10 +612,10 @@ def resolve_constant_path(constant_path) | |||||||||||||
| mod = nil | ||||||||||||||
| @module_nesting.reverse_each do |nesting, singleton| | ||||||||||||||
| next if singleton | ||||||||||||||
| mod = nesting.find_module_named(owner_name) | ||||||||||||||
| mod = nesting.get_module_named(owner_name) | ||||||||||||||
| break if mod | ||||||||||||||
| end | ||||||||||||||
| mod ||= @top_level.find_module_named(owner_name) | ||||||||||||||
| mod ||= @top_level.get_module_named(owner_name) | ||||||||||||||
| [mod.full_name, path].compact.join('::') if mod | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -657,7 +655,8 @@ def add_constant(constant_name, rhs_name, start_line, end_line) | |||||||||||||
| if rhs_name =~ /^::/ | ||||||||||||||
| @store.find_class_or_module(rhs_name) | ||||||||||||||
| else | ||||||||||||||
| @container.find_module_named(rhs_name) | ||||||||||||||
| full_name = resolve_constant_path(rhs_name) | ||||||||||||||
| @store.find_class_or_module(full_name) | ||||||||||||||
| end | ||||||||||||||
| if mod && constant.document_self | ||||||||||||||
| a = @container.add_module_alias(mod, rhs_name, constant, @top_level) | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add examples here?
Looks like it's for
But in some cases this might not work either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added.
There are three cases I know.