docscribe 1.4.2 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +601 -139
  3. data/exe/docscribe-client +105 -0
  4. data/lib/docscribe/cli/check_for_comments.rb +183 -0
  5. data/lib/docscribe/cli/config_builder.rb +107 -53
  6. data/lib/docscribe/cli/formatters/json.rb +294 -0
  7. data/lib/docscribe/cli/formatters/sarif.rb +235 -0
  8. data/lib/docscribe/cli/formatters/text.rb +208 -0
  9. data/lib/docscribe/cli/formatters.rb +26 -0
  10. data/lib/docscribe/cli/generate.rb +56 -62
  11. data/lib/docscribe/cli/init.rb +14 -6
  12. data/lib/docscribe/cli/options.rb +206 -89
  13. data/lib/docscribe/cli/rbs_gen.rb +529 -0
  14. data/lib/docscribe/cli/run.rb +433 -154
  15. data/lib/docscribe/cli/server.rb +135 -0
  16. data/lib/docscribe/cli/sigs.rb +366 -0
  17. data/lib/docscribe/cli/update_types.rb +103 -0
  18. data/lib/docscribe/cli.rb +21 -24
  19. data/lib/docscribe/config/defaults.rb +7 -2
  20. data/lib/docscribe/config/emit.rb +17 -0
  21. data/lib/docscribe/config/filtering.rb +17 -24
  22. data/lib/docscribe/config/loader.rb +19 -17
  23. data/lib/docscribe/config/plugin.rb +1 -1
  24. data/lib/docscribe/config/rbs.rb +39 -7
  25. data/lib/docscribe/config/sorbet.rb +22 -16
  26. data/lib/docscribe/config/sorting.rb +1 -1
  27. data/lib/docscribe/config/template.rb +10 -1
  28. data/lib/docscribe/config/utils.rb +11 -9
  29. data/lib/docscribe/config.rb +10 -6
  30. data/lib/docscribe/infer/ast_walk.rb +1 -1
  31. data/lib/docscribe/infer/literals.rb +6 -11
  32. data/lib/docscribe/infer/names.rb +2 -3
  33. data/lib/docscribe/infer/params.rb +14 -16
  34. data/lib/docscribe/infer/raises.rb +3 -5
  35. data/lib/docscribe/infer/returns.rb +615 -151
  36. data/lib/docscribe/infer.rb +29 -26
  37. data/lib/docscribe/inline_rewriter/collector.rb +159 -164
  38. data/lib/docscribe/inline_rewriter/doc_block.rb +145 -115
  39. data/lib/docscribe/inline_rewriter/doc_builder.rb +1032 -723
  40. data/lib/docscribe/inline_rewriter/source_helpers.rb +48 -48
  41. data/lib/docscribe/inline_rewriter/tag_sorter.rb +82 -85
  42. data/lib/docscribe/inline_rewriter.rb +485 -488
  43. data/lib/docscribe/lru_cache.rb +49 -0
  44. data/lib/docscribe/parsing.rb +28 -9
  45. data/lib/docscribe/plugin/base/collector_plugin.rb +2 -1
  46. data/lib/docscribe/plugin/base/tag_plugin.rb +0 -1
  47. data/lib/docscribe/plugin/context.rb +28 -18
  48. data/lib/docscribe/plugin/registry.rb +25 -26
  49. data/lib/docscribe/plugin/tag.rb +9 -14
  50. data/lib/docscribe/plugin.rb +17 -16
  51. data/lib/docscribe/server.rb +608 -0
  52. data/lib/docscribe/types/provider_chain.rb +4 -2
  53. data/lib/docscribe/types/rbs/collection_loader.rb +2 -2
  54. data/lib/docscribe/types/rbs/provider.rb +177 -51
  55. data/lib/docscribe/types/rbs/type_formatter.rb +224 -83
  56. data/lib/docscribe/types/signature.rb +22 -42
  57. data/lib/docscribe/types/sorbet/base_provider.rb +29 -21
  58. data/lib/docscribe/types/sorbet/rbi_provider.rb +6 -5
  59. data/lib/docscribe/types/sorbet/source_provider.rb +6 -4
  60. data/lib/docscribe/types/yard/formatter.rb +100 -0
  61. data/lib/docscribe/types/yard/parser.rb +240 -0
  62. data/lib/docscribe/types/yard/types.rb +52 -0
  63. data/lib/docscribe/version.rb +1 -1
  64. metadata +38 -1
@@ -31,7 +31,7 @@ module Docscribe
31
31
  class << self
32
32
  # Infer exception classes raised or rescued within an AST node.
33
33
  #
34
- # @param [Parser::AST::Node] node
34
+ # @param [Parser::AST::Node] node constant AST node to resolve
35
35
  # @return [Array<String>]
36
36
  def infer_raises_from_node(node)
37
37
  Raises.infer_raises_from_node(node)
@@ -47,9 +47,9 @@ module Docscribe
47
47
  # - trailing `:` for keyword args
48
48
  #
49
49
  # @param [String] name internal parameter name representation
50
- # @param [String, nil] default_str source for the default expression
51
- # @param [String] fallback_type
52
- # @param [Boolean] treat_options_keyword_as_hash
50
+ # @param [String?] default_str source for the default expression
51
+ # @param [String] fallback_type default type when uncertain
52
+ # @param [Boolean] treat_options_keyword_as_hash treat options: as Hash
53
53
  # @return [String]
54
54
  def infer_param_type(name, default_str, fallback_type: FALLBACK_TYPE, treat_options_keyword_as_hash: true)
55
55
  Params.infer_param_type(
@@ -62,7 +62,7 @@ module Docscribe
62
62
 
63
63
  # Parse a standalone expression source string for inference helpers.
64
64
  #
65
- # @param [String, nil] src
65
+ # @param [String?] src expression source to parse
66
66
  # @return [Parser::AST::Node, nil]
67
67
  def parse_expr(src)
68
68
  Params.parse_expr(src)
@@ -70,7 +70,7 @@ module Docscribe
70
70
 
71
71
  # Infer a return type from full method source.
72
72
  #
73
- # @param [String, nil] method_source
73
+ # @param [String?] method_source method definition source
74
74
  # @return [String]
75
75
  def infer_return_type(method_source)
76
76
  Returns.infer_return_type(method_source)
@@ -78,7 +78,7 @@ module Docscribe
78
78
 
79
79
  # Infer a return type from an already parsed `:def` / `:defs` node.
80
80
  #
81
- # @param [Parser::AST::Node] node
81
+ # @param [Parser::AST::Node] node constant AST node to resolve
82
82
  # @return [String]
83
83
  def infer_return_type_from_node(node)
84
84
  Returns.infer_return_type_from_node(node)
@@ -90,28 +90,32 @@ module Docscribe
90
90
  # - `:normal` => the normal return type
91
91
  # - `:rescues` => rescue-branch conditional return info
92
92
  #
93
- # @param [Parser::AST::Node] node
94
- # @param [String] fallback_type
95
- # @param [Boolean] nil_as_optional
96
- # @param [nil] core_rbs_provider core RBS type lookup provider
97
- # @param [nil] param_types parameter name -> type map
98
- # @return [Hash]
99
- def returns_spec_from_node(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true, core_rbs_provider: nil,
100
- param_types: nil)
93
+ # @param [Parser::AST::Node] node constant AST node to resolve
94
+ # @param [String] fallback_type default type when uncertain
95
+ # @param [Boolean] nil_as_optional render nil as optional
96
+ # @param [Docscribe::Types::RBS::Provider?] core_rbs_provider core RBS type lookup provider
97
+ # @param [Hash<String, String>?] param_types parameter name -> type map
98
+ # @param [String?] container
99
+ # @param [Docscribe::Types::ProviderChain?] signature_provider
100
+ # @return [Hash<Symbol, String, Array<(Array<String>, String)>>]
101
+ def returns_spec_from_node(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true, core_rbs_provider: nil, # rubocop:disable Metrics/ParameterLists
102
+ param_types: nil, container: nil, signature_provider: nil)
101
103
  Returns.returns_spec_from_node(
102
104
  node,
103
105
  fallback_type: fallback_type,
104
106
  nil_as_optional: nil_as_optional,
105
107
  core_rbs_provider: core_rbs_provider,
106
- param_types: param_types
108
+ param_types: param_types,
109
+ container: container,
110
+ signature_provider: signature_provider
107
111
  )
108
112
  end
109
113
 
110
114
  # Infer the type of the last expression in an AST node.
111
115
  #
112
- # @param [Parser::AST::Node, nil] node
113
- # @param [String] fallback_type
114
- # @param [Boolean] nil_as_optional
116
+ # @param [Parser::AST::Node, nil] node constant AST node to resolve
117
+ # @param [String] fallback_type default type when uncertain
118
+ # @param [Boolean] nil_as_optional render nil as optional
115
119
  # @return [String, nil]
116
120
  def last_expr_type(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true)
117
121
  Returns.last_expr_type(
@@ -123,7 +127,6 @@ module Docscribe
123
127
 
124
128
  # Convert a constant AST node into its fully qualified name.
125
129
  #
126
- # @param [Parser::AST::Node, nil] n
127
130
  # @param [Parser::AST::Node, nil] node constant AST node to resolve
128
131
  # @return [String, nil]
129
132
  def const_full_name(node)
@@ -132,8 +135,8 @@ module Docscribe
132
135
 
133
136
  # Infer a YARD-ish type string from a literal AST node.
134
137
  #
135
- # @param [Parser::AST::Node, nil] node
136
- # @param [String] fallback_type
138
+ # @param [Parser::AST::Node, nil] node constant AST node to resolve
139
+ # @param [String] fallback_type default type when uncertain
137
140
  # @return [String]
138
141
  def type_from_literal(node, fallback_type: FALLBACK_TYPE)
139
142
  Literals.type_from_literal(node, fallback_type: fallback_type)
@@ -141,10 +144,10 @@ module Docscribe
141
144
 
142
145
  # Unify two inferred type strings conservatively.
143
146
  #
144
- # @param [String, nil] type_a
145
- # @param [String, nil] type_b
146
- # @param [String] fallback_type
147
- # @param [Boolean] nil_as_optional
147
+ # @param [String, nil] type_a first type to unify
148
+ # @param [String, nil] type_b second type to unify
149
+ # @param [String] fallback_type default type when uncertain
150
+ # @param [Boolean] nil_as_optional render nil as optional
148
151
  # @return [String]
149
152
  def unify_types(type_a, type_b, fallback_type: FALLBACK_TYPE, nil_as_optional: true)
150
153
  Returns.unify_types(