diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-04-05 15:19:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-05 15:19:21 +0200 |
commit | 63d3a42f82d386c94eb9e11641d04ada4150c5e5 (patch) | |
tree | 5617e7270df9be072037c251fc49f4b0f9fb77e4 /doc/tools | |
parent | 4011429e574a4d7a31725c38d92dd34925487dc7 (diff) | |
parent | d80bc5cbbab71fb9b8f25ec56a0baa5b4cee68a9 (diff) |
Merge pull request #27465 from neikeq/road-to-lang-agnostic-docs-is-going-to-be-tough
EditorHelp: Improve enum ref resolving and add constant ref support
Diffstat (limited to 'doc/tools')
-rwxr-xr-x | doc/tools/makerst.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py index 40dde48432..dc6d270c08 100755 --- a/doc/tools/makerst.py +++ b/doc/tools/makerst.py @@ -702,7 +702,11 @@ def rstize_text(text, state): # type: (str, State) -> str escape_post = False if tag_text in state.classes: - tag_text = make_type(tag_text, state) + if tag_text == state.current_class: + # We don't want references to the same class + tag_text = '``{}``'.format(tag_text) + else: + tag_text = make_type(tag_text, state) escape_post = True else: # command cmd = tag_text @@ -757,14 +761,25 @@ def rstize_text(text, state): # type: (str, State) -> str elif cmd.startswith("constant"): found = False - if method_param in class_def.constants: - found = True - else: - for enum in class_def.enums.values(): - if method_param in enum.values: - found = True - break + # Search in the current class + search_class_defs = [class_def] + + if param.find('.') == -1: + # Also search in @GlobalScope as a last resort if no class was specified + search_class_defs.append(state.classes["@GlobalScope"]) + + for search_class_def in search_class_defs: + if method_param in search_class_def.constants: + class_param = search_class_def.name + found = True + + else: + for enum in search_class_def.enums.values(): + if method_param in enum.values: + class_param = search_class_def.name + found = True + break if not found: print_error("Unresolved constant '{}', file: {}".format(param, state.current_class), state) @@ -917,6 +932,9 @@ def make_enum(t, state): # type: (str, State) -> str if c in state.classes and e not in state.classes[c].enums: c = "@GlobalScope" + if not c in state.classes and c.startswith("_"): + c = c[1:] # Remove the underscore prefix + if c in state.classes and e in state.classes[c].enums: return ":ref:`{0}<enum_{1}_{0}>`".format(e, c) print_error("Unresolved enum '{}', file: {}".format(t, state.current_class), state) |