yard-sorbet 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +9 -0
  3. data/.gitignore +40 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +47 -0
  6. data/.travis.yml +7 -0
  7. data/CHANGELOG.md +10 -0
  8. data/Gemfile +14 -0
  9. data/LICENSE +201 -0
  10. data/README.md +17 -0
  11. data/Rakefile +11 -0
  12. data/lib/yard-sorbet.rb +12 -0
  13. data/lib/yard-sorbet/directives.rb +24 -0
  14. data/lib/yard-sorbet/sig_handler.rb +131 -0
  15. data/lib/yard-sorbet/sig_to_yard.rb +91 -0
  16. data/lib/yard-sorbet/struct_handler.rb +94 -0
  17. data/lib/yard-sorbet/version.rb +6 -0
  18. data/sorbet/config +2 -0
  19. data/sorbet/rbi/gems/ast.rbi +47 -0
  20. data/sorbet/rbi/gems/byebug.rbi +1039 -0
  21. data/sorbet/rbi/gems/codecov.rbi +19 -0
  22. data/sorbet/rbi/gems/coderay.rbi +91 -0
  23. data/sorbet/rbi/gems/docile.rbi +31 -0
  24. data/sorbet/rbi/gems/jaro_winkler.rbi +14 -0
  25. data/sorbet/rbi/gems/method_source.rbi +63 -0
  26. data/sorbet/rbi/gems/parallel.rbi +81 -0
  27. data/sorbet/rbi/gems/parser.rbi +920 -0
  28. data/sorbet/rbi/gems/pry-byebug.rbi +149 -0
  29. data/sorbet/rbi/gems/pry.rbi +1964 -0
  30. data/sorbet/rbi/gems/rainbow.rbi +117 -0
  31. data/sorbet/rbi/gems/rake.rbi +635 -0
  32. data/sorbet/rbi/gems/rspec-core.rbi +1686 -0
  33. data/sorbet/rbi/gems/rspec-expectations.rbi +387 -0
  34. data/sorbet/rbi/gems/rspec-mocks.rbi +819 -0
  35. data/sorbet/rbi/gems/rspec-support.rbi +270 -0
  36. data/sorbet/rbi/gems/rspec.rbi +14 -0
  37. data/sorbet/rbi/gems/rubocop-rspec.rbi +889 -0
  38. data/sorbet/rbi/gems/rubocop.rbi +7139 -0
  39. data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
  40. data/sorbet/rbi/gems/simplecov-html.rbi +30 -0
  41. data/sorbet/rbi/gems/simplecov.rbi +225 -0
  42. data/sorbet/rbi/gems/site_ruby.rbi +114 -0
  43. data/sorbet/rbi/gems/unicode-display_width.rbi +16 -0
  44. data/sorbet/rbi/gems/yard.rbi +1181 -0
  45. data/sorbet/rbi/hidden-definitions/errors.txt +3045 -0
  46. data/sorbet/rbi/hidden-definitions/hidden.rbi +4469 -0
  47. data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +8684 -0
  48. data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +4222 -0
  49. data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +111 -0
  50. data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +543 -0
  51. data/spec/data/sig_handler.rb.txt +196 -0
  52. data/spec/data/struct_handler.rb.txt +25 -0
  53. data/spec/spec_helper.rb +111 -0
  54. data/spec/yard_sorbet/sig_handler_spec.rb +233 -0
  55. data/spec/yard_sorbet/struct_handler_spec.rb +48 -0
  56. data/yard-sorbet.gemspec +27 -0
  57. metadata +159 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '01297d9a9e47af3e48b7aef782f9ffd60fe41476567ef1e7e986ae38a1b24880'
4
- data.tar.gz: e612bbdc440d264051f58c95c744a48753d31b6ec6ea94dec928101c9612c54b
3
+ metadata.gz: '0877d9e7c2166c05eaf8b6e758ca07e046258053458a33cc6847b8103ba998b0'
4
+ data.tar.gz: 1a2ec7ab8d6e8036c53a816053e91abb117a7330fb52aaeba692a5331d2f597b
5
5
  SHA512:
6
- metadata.gz: 391fb61ef58440411978c3508666fa7accd43d5987b0f80f91506bb01991aef4e1801b40c428cb2fc7bad8e1ae55dd4a13ac7a02d90a603e007aee8f306a8c86
7
- data.tar.gz: 5b4749046bc5d4da734d81924de6f46de540aa2d750ad1d53e3c50723da36241aa905d75e0e888d34c3322ee15f0df8f7ea2565ef8ab249010b4d2b6b0583a24
6
+ metadata.gz: 8c32134d99eb150900275db0a7c34f7e3e1c08deb1c6fbee35d8303aa3ed0ad98dc1453268fc2a97a4f23fdf9c5969f2edff6bfc62ba271e8c9af70708ab385c
7
+ data.tar.gz: e3de167e4393f4a832e65e4d91459e17f7218423e392df25b405c0cdbf3a16e9f4ebaefd3f3ec71efc6b62330942cef98267545c7410305487efabbacf805715
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ Gemfile.lock
33
+ .ruby-version
34
+ .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
38
+
39
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
40
+ # .rubocop-https?--*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,47 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.4
7
+
8
+ Layout/ClassStructure:
9
+ Enabled: true
10
+ # doesn't recognize sorbet magic comments
11
+ Layout/EmptyLineAfterMagicComment:
12
+ Enabled: false
13
+ Layout/LineLength:
14
+ Enabled: false
15
+ Metrics/AbcSize:
16
+ Enabled: false
17
+ Metrics/BlockLength:
18
+ Enabled: false
19
+ Metrics/BlockNesting:
20
+ Enabled: false
21
+ Metrics/ClassLength:
22
+ Enabled: false
23
+ Metrics/CyclomaticComplexity:
24
+ Enabled: false
25
+ Metrics/MethodLength:
26
+ Enabled: false
27
+ Metrics/PerceivedComplexity:
28
+ Enabled: false
29
+ Naming/FileName:
30
+ Exclude:
31
+ - lib/yard-sorbet.rb
32
+ RSpec/ExampleLength:
33
+ Enabled: false
34
+ RSpec/MultipleExpectations:
35
+ Enabled: false
36
+ Style/AccessModifierDeclarations:
37
+ EnforcedStyle: inline
38
+ Style/ClassAndModuleChildren:
39
+ EnforcedStyle: compact
40
+ Style/NegatedIf:
41
+ Enabled: false
42
+ Style/NegatedWhile:
43
+ Enabled: false
44
+ Style/Next:
45
+ Enabled: false
46
+ Style/IfUnlessModifier:
47
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # master
2
+
3
+ # 0.0.1 / 2020-01-24
4
+
5
+ - [#1](https://github.com/dduugg/yard-sorbet/pull/1): Add `T::Struct` support.
6
+ - [#3](https://github.com/dduugg/yard-sorbet/pull/3): Rename require path to be conistent with gem name.
7
+
8
+ # 0.0.0 / 2020-01-05
9
+
10
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'codecov', '~> 0.1.16'
6
+ gem 'pry-byebug'
7
+ gem 'rake', '~> 13.0'
8
+ gem 'rspec', '~> 3.9'
9
+ gem 'rubocop', '~> 0.78.0'
10
+ gem 'rubocop-rspec', '~> 1.37'
11
+ gem 'simplecov', '~> 0.17.1'
12
+ gem 'sorbet', '~> 0.5.5200'
13
+ gem 'sorbet-runtime', '~> 0.5.5200'
14
+ gem 'yard', '~> 0.9.22'
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # yard-sorbet
2
+ [![Gem Version](https://badge.fury.io/rb/yard-sorbet.svg)](https://badge.fury.io/rb/yard-sorbet)
3
+ [![Build Status](https://travis-ci.com/dduugg/yard-sorbet.svg?branch=master)](https://travis-ci.com/dduugg/yard-sorbet)
4
+ [![codecov](https://codecov.io/gh/dduugg/yard-sorbet/branch/master/graph/badge.svg)](https://codecov.io/gh/dduugg/yard-sorbet)
5
+
6
+ A YARD [plugin](https://rubydoc.info/gems/yard/file/docs/GettingStarted.md#Plugin_Support) that parses Sorbet type annotations
7
+
8
+ ## Install
9
+
10
+ ```shell
11
+ gem install yard-sorbet
12
+ ```
13
+
14
+ ## Usage
15
+ ```bash
16
+ yard doc --plugin sorbet
17
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :lint do
8
+ sh 'rubocop'
9
+ end
10
+
11
+ task default: %i[lint spec]
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ # typed: strong
3
+ require 'sorbet-runtime'
4
+ require 'yard'
5
+
6
+ # top-level namespace
7
+ module YARDSorbet; end
8
+
9
+ require_relative 'yard-sorbet/directives.rb'
10
+ require_relative 'yard-sorbet/sig_handler'
11
+ require_relative 'yard-sorbet/sig_to_yard'
12
+ require_relative 'yard-sorbet/struct_handler'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # typed: strict
3
+
4
+ # Extract & re-add directives to a docstring
5
+ module YARDSorbet::Directives
6
+ def self.extract_directives(docstring)
7
+ parser = YARD::DocstringParser.new.parse(docstring)
8
+ # Directives are already parsed at this point, and there doesn't
9
+ # seem to be an API to tweeze them from one node to another without
10
+ # managing YARD internal state. Instead, we just extract them from
11
+ # the raw text and re-attach them.
12
+ directives = parser.raw_text&.split("\n")&.select do |line|
13
+ line.start_with?('@!')
14
+ end || []
15
+
16
+ [parser.to_docstring, directives]
17
+ end
18
+
19
+ def self.add_directives(docstring, directives)
20
+ directives.each do |directive|
21
+ docstring.concat("\n#{directive}")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,131 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ # A YARD Handler for Sorbet type declarations
5
+ class YARDSorbet::SigHandler < YARD::Handlers::Ruby::Base
6
+ extend T::Sig
7
+ handles :class, :module, :singleton_class?
8
+
9
+ sig { returns(String).checked(:never) }
10
+ def process
11
+ # Find the list of declarations inside the class
12
+ class_def = statement.children.find { |c| c.type == :list }
13
+ class_contents = class_def.children
14
+
15
+ class_contents.each_with_index do |child, i|
16
+ next unless type_signature?(child)
17
+
18
+ next_statement = class_contents[i + 1]
19
+ if %i[def defs command].include?(next_statement&.type) && !next_statement.docstring
20
+ # Swap the method definition docstring and the sig docstring.
21
+ # Parse relevant parts of the `sig` and include them as well.
22
+ docstring, directives = YARDSorbet::Directives.extract_directives(child.docstring)
23
+ parsed_sig = parse_sig(child)
24
+ enhance_tag(docstring, :abstract, parsed_sig)
25
+ enhance_tag(docstring, :return, parsed_sig)
26
+ if next_statement.type != :command
27
+ parsed_sig[:params]&.each do |name, types|
28
+ enhance_param(docstring, name, types)
29
+ end
30
+ end
31
+ next_statement.docstring = docstring.to_raw
32
+ YARDSorbet::Directives.add_directives(next_statement.docstring, directives)
33
+ child.docstring = nil
34
+ end
35
+ end
36
+ end
37
+
38
+ private def enhance_param(docstring, name, types)
39
+ tag = docstring.tags.find { |t| t.tag_name == 'param' && t.name == name }
40
+ if tag
41
+ docstring.delete_tag_if { |t| t == tag }
42
+ tag.types = types
43
+ else
44
+ tag = YARD::Tags::Tag.new(:param, '', types, name)
45
+ end
46
+ docstring.add_tag(tag)
47
+ end
48
+
49
+ private def enhance_tag(docstring, type, parsed_sig)
50
+ return if !parsed_sig[type]
51
+
52
+ tag = docstring.tags.find { |t| t.tag_name == type.to_s }
53
+ if tag
54
+ docstring.delete_tags(type)
55
+ else
56
+ tag = YARD::Tags::Tag.new(type, '')
57
+ end
58
+ if parsed_sig[type].is_a?(Array)
59
+ tag.types = parsed_sig[type]
60
+ end
61
+ docstring.add_tag(tag)
62
+ end
63
+
64
+ private def parse_sig(sig_node)
65
+ parsed = {}
66
+ parsed[:abstract] = false
67
+ parsed[:params] = {}
68
+ found_params = T.let(false, T::Boolean)
69
+ found_return = T.let(false, T::Boolean)
70
+ bfs_traverse(sig_node, exclude: %i[array hash]) do |n|
71
+ if n.source == 'abstract'
72
+ parsed[:abstract] = true
73
+ elsif n.source == 'params' && !found_params
74
+ found_params = true
75
+ sibling = T.must(sibling_node(n))
76
+ bfs_traverse(sibling, exclude: %i[array call hash]) do |p|
77
+ if p.type == :assoc
78
+ param_name = p.children.first.source[0...-1]
79
+ types = YARDSorbet::SigToYARD.convert(p.children.last)
80
+ parsed[:params][param_name] = types
81
+ end
82
+ end
83
+ elsif n.source == 'returns' && !found_return
84
+ found_return = true
85
+ parsed[:return] = YARDSorbet::SigToYARD.convert(T.must(sibling_node(n)))
86
+ elsif n.source == 'void'
87
+ parsed[:return] ||= ['void']
88
+ end
89
+ end
90
+ parsed
91
+ end
92
+
93
+ # Returns true if the given node is part of a type signature.
94
+ private def type_signature?(node)
95
+ loop do
96
+ return false if node.nil?
97
+ return false unless %i[call vcall fcall].include?(node.type)
98
+ return true if T.unsafe(node).method_name(true) == :sig
99
+
100
+ node = node.children.first
101
+ end
102
+ end
103
+
104
+ private def sibling_node(node)
105
+ found_sibling = T.let(false, T::Boolean)
106
+ node.parent.children.each do |n|
107
+ if found_sibling
108
+ return n
109
+ end
110
+
111
+ if n == node
112
+ found_sibling = true
113
+ end
114
+ end
115
+ nil
116
+ end
117
+
118
+ # @yield [YARD::Parser::Ruby::AstNode]
119
+ private def bfs_traverse(node, exclude: [])
120
+ queue = [node]
121
+ while !queue.empty?
122
+ n = T.must(queue.shift)
123
+ yield n
124
+ n.children.each do |c|
125
+ if !exclude.include?(c.type)
126
+ queue.push(c)
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end