-
Notifications
You must be signed in to change notification settings - Fork 451
Fix cross-reference resolution for constants #1539
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
Changes from 3 commits
b48030b
2e07821
20b3cd1
f2bfddd
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 |
|---|---|---|
|
|
@@ -132,47 +132,56 @@ def initialize(context) | |
| end | ||
|
|
||
| ## | ||
| # Returns a method reference to +name+. | ||
| # Returns a method, attribute or constant reference to +name+ | ||
| # if it exists in the containing context object. It returns | ||
| # nil otherwise. | ||
| # | ||
| # For example, this method would decompose name = 'A::CONSTANT' into a | ||
| # container object A and a symbol 'CONSTANT', and it would try to find | ||
| # 'CONSTANT' in A. | ||
|
|
||
| def resolve_method(name) | ||
| def resolve_local_symbol(name) | ||
| ref = nil | ||
| type = nil | ||
| container = nil | ||
|
|
||
| if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then | ||
| case name | ||
| when /#{CLASS_REGEXP_STR}::([A-Z]\w*)\z/o then | ||
| symbol = $2 | ||
| container = @context.find_symbol_module($1) | ||
| when /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o then | ||
| type = $2 | ||
| if '.' == type # will find either #method or ::method | ||
| method = $3 | ||
| symbol = $3 | ||
| else | ||
| method = "#{type}#{$3}" | ||
| symbol = "#{type}#{$3}" | ||
| end | ||
| container = @context.find_symbol_module($1) | ||
| elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then | ||
| when /^([.#]|::)#{METHOD_REGEXP_STR}/o then | ||
| type = $1 | ||
| if '.' == type | ||
| method = $2 | ||
| symbol = $2 | ||
| else | ||
| method = "#{type}#{$2}" | ||
| symbol = "#{type}#{$2}" | ||
| end | ||
| container = @context | ||
| else | ||
| type = nil | ||
| container = nil | ||
| end | ||
|
|
||
| if container then | ||
| unless RDoc::TopLevel === container then | ||
| if '.' == type then | ||
| if 'new' == method then # AnyClassName.new will be class method | ||
| ref = container.find_local_symbol method | ||
| ref = container.find_ancestor_local_symbol method unless ref | ||
| if 'new' == symbol then # AnyClassName.new will be class method | ||
| ref = container.find_local_symbol symbol | ||
| ref = container.find_ancestor_local_symbol symbol unless ref | ||
| else | ||
| ref = container.find_local_symbol "::#{method}" | ||
| ref = container.find_ancestor_local_symbol "::#{method}" unless ref | ||
| ref = container.find_local_symbol "##{method}" unless ref | ||
| ref = container.find_ancestor_local_symbol "##{method}" unless ref | ||
| ref = container.find_local_symbol "::#{symbol}" | ||
| ref = container.find_ancestor_local_symbol "::#{symbol}" unless ref | ||
| ref = container.find_local_symbol "##{symbol}" unless ref | ||
| ref = container.find_ancestor_local_symbol "##{symbol}" unless ref | ||
| end | ||
| else | ||
| ref = container.find_local_symbol method | ||
| ref = container.find_ancestor_local_symbol method unless ref | ||
| ref = container.find_local_symbol symbol | ||
| ref = container.find_ancestor_local_symbol symbol unless ref | ||
|
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. How about checking for constant after this line? ref = container.find_constant_named(symbol[2..]) if !ref && type == '::'Treating For background, current codebase of RDoc is hard to maintain. Removing complexity, fixing misleading code and refactoring is in a highest priority for me as a maintainer of RDoc. Adding an explicit constant-name regexp extraction is also a good idea. if /#{CLASS_REGEXP_STR}::([A-Z]\w*)\z/o =~ name then
type = 'const'
container = @context.find_symbol_module($1)
symbol = $2
elsif ... |
||
| end | ||
| end | ||
| end | ||
|
|
@@ -197,7 +206,7 @@ def resolve(name, text) | |
| @context.find_symbol name | ||
| end | ||
|
|
||
| ref = resolve_method name unless ref | ||
| ref = resolve_local_symbol name unless ref | ||
|
|
||
| # Try a page name | ||
| ref = @store.page name if not ref and name =~ /^[\w.\/]+$/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,9 @@ class C11 | |
| def C11 | ||
| end | ||
|
|
||
| class C12 < C1 | ||
| end | ||
|
|
||
| module M1 | ||
| def m | ||
| end | ||
|
|
||
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.
Just one more thing. Can you revert this change? because this is only a coding style change.
I think other part of this pull request looks good 👍
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.
Sure, no problem. Addressed in f2bfddd. Thanks!