-
Notifications
You must be signed in to change notification settings - Fork 154
Use Rubydex to document symbols instead of YARD #2524
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
Open
Morriar
wants to merge
6
commits into
main
Choose a base branch
from
at-rubydex-graph
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9db6ab3
Regenerate all RBIs
Morriar 5cda3f1
Add dependency to rubydex
Morriar 0959a90
Add Rubydex graph indexing for documentation
Morriar 07a5a6f
Remove dependency to yard-sorbet
Morriar 360fb5e
Document symbols using Rubydex instead of YARD
Morriar a7c1387
Regenerate all RBIs
Morriar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # typed: strict | ||
| # frozen_string_literal: true | ||
|
|
||
| module Tapioca | ||
| module Gem | ||
| module Listeners | ||
| class Documentation < Base | ||
| IGNORED_COMMENTS = [ | ||
| ":doc:", | ||
| ":nodoc:", | ||
| "typed:", | ||
| "frozen_string_literal:", | ||
| "encoding:", | ||
| "warn_indent:", | ||
| "shareable_constant_value:", | ||
| "rubocop:", | ||
| "@requires_ancestor:", | ||
| ] #: Array[String] | ||
|
|
||
| #: (Pipeline pipeline, Rubydex::Graph gem_graph) -> void | ||
| def initialize(pipeline, gem_graph) | ||
| super(pipeline) | ||
|
|
||
| @gem_graph = gem_graph | ||
| end | ||
|
|
||
| private | ||
|
|
||
| #: (String line) -> bool | ||
| def rbs_comment?(line) | ||
| line.start_with?(": ", "| ") | ||
| end | ||
|
|
||
| # @override | ||
| #: (ConstNodeAdded event) -> void | ||
| def on_const(event) | ||
| event.node.comments = documentation_comments(event.symbol) | ||
| end | ||
|
|
||
| # @override | ||
| #: (ScopeNodeAdded event) -> void | ||
| def on_scope(event) | ||
| event.node.comments = documentation_comments(event.symbol) | ||
| end | ||
|
|
||
| # @override | ||
| #: (MethodNodeAdded event) -> void | ||
| def on_method(event) | ||
| name = if event.constant.singleton_class? | ||
| "#{event.symbol}::<#{event.symbol.split("::").last}>##{event.node.name}()" | ||
| else | ||
| "#{event.symbol}##{event.node.name}()" | ||
| end | ||
| event.node.comments = documentation_comments(name, sigs: event.node.sigs) | ||
| end | ||
|
|
||
| #: (String name, ?sigs: Array[RBI::Sig]) -> Array[RBI::Comment] | ||
| def documentation_comments(name, sigs: []) | ||
| declaration = @gem_graph[name] | ||
| # For attr_writer methods (name ending in =), fall back to reader docs | ||
| if declaration.nil? && name.end_with?("=()") | ||
| declaration = @gem_graph[name.delete_suffix("=()") + "()"] | ||
| end | ||
| # For singleton methods (Class::<Class>#method()), fall back to instance method docs. | ||
| # This handles module_function and extend self methods which Rubydex indexes | ||
| # only under the instance method name. | ||
| if declaration.nil? && name.include?("::<") | ||
| declaration = @gem_graph[name.sub(/::<[^>]+>#/, "#")] | ||
| end | ||
| return [] unless declaration | ||
|
|
||
| comments = declaration.definitions.flat_map(&:comments) | ||
| comments.uniq! | ||
| return [] if comments.empty? | ||
|
|
||
| lines = comments | ||
| .map { |comment| comment.string.gsub(/^#+ ?/, "") } | ||
| .reject { |line| IGNORED_COMMENTS.any? { |comment| line.include?(comment) } || rbs_comment?(line) } | ||
|
|
||
| # Strip leading and trailing blank lines, matching YARD's behavior | ||
| lines = lines.drop_while(&:empty?).reverse.drop_while(&:empty?).reverse | ||
|
|
||
| lines.map! { |line| RBI::Comment.new(line) } | ||
| end | ||
|
|
||
| # @override | ||
| #: (NodeAdded event) -> bool | ||
| def ignore?(event) | ||
| event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.