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.
- checksums.yaml +4 -4
- data/README.md +601 -139
- data/exe/docscribe-client +105 -0
- data/lib/docscribe/cli/check_for_comments.rb +183 -0
- data/lib/docscribe/cli/config_builder.rb +107 -53
- data/lib/docscribe/cli/formatters/json.rb +294 -0
- data/lib/docscribe/cli/formatters/sarif.rb +235 -0
- data/lib/docscribe/cli/formatters/text.rb +208 -0
- data/lib/docscribe/cli/formatters.rb +26 -0
- data/lib/docscribe/cli/generate.rb +56 -62
- data/lib/docscribe/cli/init.rb +14 -6
- data/lib/docscribe/cli/options.rb +206 -89
- data/lib/docscribe/cli/rbs_gen.rb +529 -0
- data/lib/docscribe/cli/run.rb +433 -154
- data/lib/docscribe/cli/server.rb +135 -0
- data/lib/docscribe/cli/sigs.rb +366 -0
- data/lib/docscribe/cli/update_types.rb +103 -0
- data/lib/docscribe/cli.rb +21 -24
- data/lib/docscribe/config/defaults.rb +7 -2
- data/lib/docscribe/config/emit.rb +17 -0
- data/lib/docscribe/config/filtering.rb +17 -24
- data/lib/docscribe/config/loader.rb +19 -17
- data/lib/docscribe/config/plugin.rb +1 -1
- data/lib/docscribe/config/rbs.rb +39 -7
- data/lib/docscribe/config/sorbet.rb +22 -16
- data/lib/docscribe/config/sorting.rb +1 -1
- data/lib/docscribe/config/template.rb +10 -1
- data/lib/docscribe/config/utils.rb +11 -9
- data/lib/docscribe/config.rb +10 -6
- data/lib/docscribe/infer/ast_walk.rb +1 -1
- data/lib/docscribe/infer/literals.rb +6 -11
- data/lib/docscribe/infer/names.rb +2 -3
- data/lib/docscribe/infer/params.rb +14 -16
- data/lib/docscribe/infer/raises.rb +3 -5
- data/lib/docscribe/infer/returns.rb +615 -151
- data/lib/docscribe/infer.rb +29 -26
- data/lib/docscribe/inline_rewriter/collector.rb +159 -164
- data/lib/docscribe/inline_rewriter/doc_block.rb +145 -115
- data/lib/docscribe/inline_rewriter/doc_builder.rb +1032 -723
- data/lib/docscribe/inline_rewriter/source_helpers.rb +48 -48
- data/lib/docscribe/inline_rewriter/tag_sorter.rb +82 -85
- data/lib/docscribe/inline_rewriter.rb +485 -488
- data/lib/docscribe/lru_cache.rb +49 -0
- data/lib/docscribe/parsing.rb +28 -9
- data/lib/docscribe/plugin/base/collector_plugin.rb +2 -1
- data/lib/docscribe/plugin/base/tag_plugin.rb +0 -1
- data/lib/docscribe/plugin/context.rb +28 -18
- data/lib/docscribe/plugin/registry.rb +25 -26
- data/lib/docscribe/plugin/tag.rb +9 -14
- data/lib/docscribe/plugin.rb +17 -16
- data/lib/docscribe/server.rb +608 -0
- data/lib/docscribe/types/provider_chain.rb +4 -2
- data/lib/docscribe/types/rbs/collection_loader.rb +2 -2
- data/lib/docscribe/types/rbs/provider.rb +177 -51
- data/lib/docscribe/types/rbs/type_formatter.rb +224 -83
- data/lib/docscribe/types/signature.rb +22 -42
- data/lib/docscribe/types/sorbet/base_provider.rb +29 -21
- data/lib/docscribe/types/sorbet/rbi_provider.rb +6 -5
- data/lib/docscribe/types/sorbet/source_provider.rb +6 -4
- data/lib/docscribe/types/yard/formatter.rb +100 -0
- data/lib/docscribe/types/yard/parser.rb +240 -0
- data/lib/docscribe/types/yard/types.rb +52 -0
- data/lib/docscribe/version.rb +1 -1
- metadata +38 -1
|
@@ -15,12 +15,11 @@ module Docscribe
|
|
|
15
15
|
# - special-casing `options:` as `Hash` when enabled
|
|
16
16
|
# - literal defaults via AST parsing
|
|
17
17
|
#
|
|
18
|
-
# @note module_function:
|
|
18
|
+
# @note module_function: defines #infer_param_type (visibility: private)
|
|
19
19
|
# @param [String] name parameter name as used internally (may include `*`, `**`, `&`, or trailing `:`)
|
|
20
|
-
# @param [String
|
|
20
|
+
# @param [String?] default_str source for the default value expression
|
|
21
21
|
# @param [String] fallback_type type returned when inference is uncertain
|
|
22
22
|
# @param [Boolean] treat_options_keyword_as_hash whether `options:` should
|
|
23
|
-
# be treated specially as Hash
|
|
24
23
|
# @return [String]
|
|
25
24
|
def infer_param_type(name, default_str, fallback_type: FALLBACK_TYPE, treat_options_keyword_as_hash: true)
|
|
26
25
|
prefix_param_type(name) || inferred_param_type(name, default_str, fallback_type,
|
|
@@ -29,8 +28,7 @@ module Docscribe
|
|
|
29
28
|
|
|
30
29
|
# Return type for special parameter prefixes.
|
|
31
30
|
#
|
|
32
|
-
# @note module_function:
|
|
33
|
-
# @private
|
|
31
|
+
# @note module_function: defines #prefix_param_type (visibility: private)
|
|
34
32
|
# @param [String] name parameter name
|
|
35
33
|
# @return [String, nil]
|
|
36
34
|
def prefix_param_type(name)
|
|
@@ -43,12 +41,11 @@ module Docscribe
|
|
|
43
41
|
|
|
44
42
|
# Infer type for a regular or keyword parameter with optional default.
|
|
45
43
|
#
|
|
46
|
-
# @note module_function:
|
|
47
|
-
# @private
|
|
44
|
+
# @note module_function: defines #inferred_param_type (visibility: private)
|
|
48
45
|
# @param [String] name parameter name
|
|
49
|
-
# @param [String
|
|
50
|
-
# @param [String] fallback_type
|
|
51
|
-
# @param [Boolean] treat_options_keyword_as_hash
|
|
46
|
+
# @param [String?] default_str default expression source
|
|
47
|
+
# @param [String] fallback_type type returned when not special-cased
|
|
48
|
+
# @param [Boolean] treat_options_keyword_as_hash whether to treat 'options:' as Hash
|
|
52
49
|
# @return [String]
|
|
53
50
|
def inferred_param_type(name, default_str, fallback_type, treat_options_keyword_as_hash:)
|
|
54
51
|
if name.end_with?(':') && default_str.nil?
|
|
@@ -65,7 +62,7 @@ module Docscribe
|
|
|
65
62
|
|
|
66
63
|
# Return 'Hash' for a keyword parameter named 'options:' when special-cased, else fallback.
|
|
67
64
|
#
|
|
68
|
-
# @note module_function:
|
|
65
|
+
# @note module_function: defines #options_keyword_type (visibility: private)
|
|
69
66
|
# @param [String] name parameter name
|
|
70
67
|
# @param [Boolean] treat_options_keyword_as_hash whether to treat 'options:' as Hash
|
|
71
68
|
# @param [String] fallback_type type returned when not special-cased
|
|
@@ -76,9 +73,9 @@ module Docscribe
|
|
|
76
73
|
|
|
77
74
|
# Whether a keyword parameter named 'options:' with a hash default should be typed as Hash.
|
|
78
75
|
#
|
|
79
|
-
# @note module_function:
|
|
76
|
+
# @note module_function: defines #options_hash_keyword? (visibility: private)
|
|
80
77
|
# @param [String] name parameter name
|
|
81
|
-
# @param [String
|
|
78
|
+
# @param [String?] default_str default expression source
|
|
82
79
|
# @param [String] type inferred type
|
|
83
80
|
# @param [Boolean] treat_options_keyword_as_hash whether to treat 'options:' as Hash
|
|
84
81
|
# @return [Boolean]
|
|
@@ -90,17 +87,18 @@ module Docscribe
|
|
|
90
87
|
#
|
|
91
88
|
# Returns nil if the expression is empty or cannot be parsed.
|
|
92
89
|
#
|
|
93
|
-
# @note module_function:
|
|
94
|
-
# @param [String
|
|
90
|
+
# @note module_function: defines #parse_expr (visibility: private)
|
|
91
|
+
# @param [String?] src expression source
|
|
95
92
|
# @raise [Parser::SyntaxError]
|
|
96
93
|
# @return [Parser::AST::Node, nil]
|
|
94
|
+
# @return [nil] if Parser::SyntaxError
|
|
97
95
|
def parse_expr(src)
|
|
98
96
|
return nil if src.nil? || src.strip.empty?
|
|
99
97
|
|
|
100
98
|
buffer = Parser::Source::Buffer.new('(param)')
|
|
101
99
|
buffer.source = src
|
|
102
100
|
Docscribe::Parsing.parse_buffer(buffer)
|
|
103
|
-
rescue Parser::SyntaxError
|
|
101
|
+
rescue Parser::SyntaxError # steep:ignore
|
|
104
102
|
nil
|
|
105
103
|
end
|
|
106
104
|
end
|
|
@@ -16,7 +16,7 @@ module Docscribe
|
|
|
16
16
|
#
|
|
17
17
|
# Returns unique exception names in discovery order.
|
|
18
18
|
#
|
|
19
|
-
# @note module_function:
|
|
19
|
+
# @note module_function: defines #infer_raises_from_node (visibility: private)
|
|
20
20
|
# @param [Parser::AST::Node] node method or expression node to inspect
|
|
21
21
|
# @return [Array<String>]
|
|
22
22
|
def infer_raises_from_node(node)
|
|
@@ -41,8 +41,7 @@ module Docscribe
|
|
|
41
41
|
# - `Foo` => `["Foo"]`
|
|
42
42
|
# - `[Foo, Bar]` => `["Foo", "Bar"]`
|
|
43
43
|
#
|
|
44
|
-
# @note module_function:
|
|
45
|
-
# #exception_names_from_rescue_list (instance visibility: private)
|
|
44
|
+
# @note module_function: defines #exception_names_from_rescue_list (visibility: private)
|
|
46
45
|
# @param [Parser::AST::Node, nil] exc_list rescue exception list node
|
|
47
46
|
# @return [Array<String>]
|
|
48
47
|
def exception_names_from_rescue_list(exc_list)
|
|
@@ -57,8 +56,7 @@ module Docscribe
|
|
|
57
56
|
|
|
58
57
|
# Collect exception names from a `raise` or `fail` send node.
|
|
59
58
|
#
|
|
60
|
-
# @note module_function:
|
|
61
|
-
# @private
|
|
59
|
+
# @note module_function: defines #collect_send_raise (visibility: private)
|
|
62
60
|
# @param [Array<String>] raises accumulator
|
|
63
61
|
# @param [Parser::AST::Node] node send node
|
|
64
62
|
# @return [void]
|