docscribe 1.5.0 → 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 +140 -13
- data/exe/docscribe-client +105 -0
- data/lib/docscribe/cli/config_builder.rb +1 -1
- data/lib/docscribe/cli/generate.rb +11 -17
- data/lib/docscribe/cli/options.rb +17 -2
- data/lib/docscribe/cli/rbs_gen.rb +1 -1
- data/lib/docscribe/cli/run.rb +230 -9
- data/lib/docscribe/cli/server.rb +135 -0
- data/lib/docscribe/cli/sigs.rb +5 -5
- data/lib/docscribe/cli.rb +20 -31
- data/lib/docscribe/config/defaults.rb +2 -1
- data/lib/docscribe/config/filtering.rb +1 -1
- data/lib/docscribe/config/loader.rb +5 -7
- data/lib/docscribe/config/rbs.rb +2 -2
- data/lib/docscribe/config/sorbet.rb +15 -6
- data/lib/docscribe/config/template.rb +1 -0
- data/lib/docscribe/config.rb +8 -2
- data/lib/docscribe/infer/params.rb +1 -1
- data/lib/docscribe/infer/returns.rb +81 -19
- data/lib/docscribe/infer.rb +7 -3
- data/lib/docscribe/inline_rewriter/doc_builder.rb +14 -8
- data/lib/docscribe/inline_rewriter/source_helpers.rb +1 -1
- data/lib/docscribe/inline_rewriter.rb +14 -20
- data/lib/docscribe/lru_cache.rb +49 -0
- data/lib/docscribe/parsing.rb +2 -2
- data/lib/docscribe/plugin/registry.rb +1 -1
- data/lib/docscribe/plugin.rb +1 -1
- data/lib/docscribe/server.rb +608 -0
- data/lib/docscribe/types/rbs/provider.rb +120 -10
- data/lib/docscribe/types/sorbet/base_provider.rb +7 -4
- data/lib/docscribe/types/sorbet/rbi_provider.rb +3 -2
- data/lib/docscribe/types/sorbet/source_provider.rb +3 -2
- data/lib/docscribe/version.rb +1 -1
- metadata +7 -2
data/lib/docscribe/config.rb
CHANGED
|
@@ -11,14 +11,20 @@ module Docscribe
|
|
|
11
11
|
# @return [Hash<String, Object>]
|
|
12
12
|
attr_reader :raw
|
|
13
13
|
|
|
14
|
+
# @!attribute [r] config_path
|
|
15
|
+
# @return [String?]
|
|
16
|
+
attr_reader :config_path
|
|
17
|
+
|
|
14
18
|
# Create a configuration object from a raw config hash.
|
|
15
19
|
#
|
|
16
20
|
# Missing keys are filled from {DEFAULT} via deep merge.
|
|
17
21
|
#
|
|
22
|
+
# @param [String?] config_path optional path to the config file
|
|
18
23
|
# @param [Hash<String, Object>] raw user-provided config hash
|
|
19
24
|
# @return [void]
|
|
20
|
-
def initialize(
|
|
21
|
-
@raw = deep_merge(DEFAULT, raw
|
|
25
|
+
def initialize(config_path: nil, **raw)
|
|
26
|
+
@raw = deep_merge(DEFAULT, raw)
|
|
27
|
+
@config_path = config_path
|
|
22
28
|
end
|
|
23
29
|
end
|
|
24
30
|
end
|
|
@@ -90,7 +90,7 @@ module Docscribe
|
|
|
90
90
|
# @note module_function: defines #parse_expr (visibility: private)
|
|
91
91
|
# @param [String?] src expression source
|
|
92
92
|
# @raise [Parser::SyntaxError]
|
|
93
|
-
# @return [Parser::AST::Node, nil]
|
|
93
|
+
# @return [Parser::AST::Node, nil]
|
|
94
94
|
# @return [nil] if Parser::SyntaxError
|
|
95
95
|
def parse_expr(src)
|
|
96
96
|
return nil if src.nil? || src.strip.empty?
|
|
@@ -14,7 +14,7 @@ module Docscribe
|
|
|
14
14
|
# @note module_function: defines #infer_return_type (visibility: private)
|
|
15
15
|
# @param [String?] method_source full method definition source
|
|
16
16
|
# @raise [Parser::SyntaxError]
|
|
17
|
-
# @return [String]
|
|
17
|
+
# @return [String]
|
|
18
18
|
# @return [FALLBACK_TYPE] if Parser::SyntaxError
|
|
19
19
|
def infer_return_type(method_source)
|
|
20
20
|
return FALLBACK_TYPE if method_source.nil? || method_source.strip.empty?
|
|
@@ -67,16 +67,19 @@ module Docscribe
|
|
|
67
67
|
# @param [Boolean] nil_as_optional whether `nil` unions should be rendered as optional types
|
|
68
68
|
# @param [Object?] core_rbs_provider core RBS type lookup provider
|
|
69
69
|
# @param [Hash<String, String>?] param_types parameter name -> type map
|
|
70
|
+
# @param [String?] container
|
|
71
|
+
# @param [Docscribe::Types::ProviderChain?] signature_provider
|
|
70
72
|
# @return [Object]
|
|
71
|
-
def returns_spec_from_node(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true, core_rbs_provider: nil,
|
|
72
|
-
param_types: nil)
|
|
73
|
+
def returns_spec_from_node(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true, core_rbs_provider: nil, # rubocop:disable Metrics/ParameterLists
|
|
74
|
+
param_types: nil, container: nil, signature_provider: nil)
|
|
73
75
|
body = extract_def_body(node)
|
|
74
76
|
spec = { normal: FALLBACK_TYPE, rescues: [] } #: Hash[Symbol, untyped]
|
|
75
77
|
return spec unless body
|
|
76
78
|
|
|
77
79
|
types = build_local_variable_types(body, core_rbs_provider: core_rbs_provider, param_types: param_types)
|
|
78
80
|
populate_returns_spec(spec, body, types, fallback_type: fallback_type, nil_as_optional: nil_as_optional,
|
|
79
|
-
core_rbs_provider: core_rbs_provider, param_types: param_types
|
|
81
|
+
core_rbs_provider: core_rbs_provider, param_types: param_types,
|
|
82
|
+
container: container, signature_provider: signature_provider)
|
|
80
83
|
spec
|
|
81
84
|
end
|
|
82
85
|
|
|
@@ -235,7 +238,7 @@ module Docscribe
|
|
|
235
238
|
# @return [String, nil]
|
|
236
239
|
def handle_lvar_node(node, **opts)
|
|
237
240
|
name = node.children[0].to_s
|
|
238
|
-
opts[:local_var_types]
|
|
241
|
+
lookup_lvar_type(name, opts[:local_var_types], opts[:param_types]) || opts[:fallback_type]
|
|
239
242
|
end
|
|
240
243
|
|
|
241
244
|
# Handle `:ivar` node for last_expr_type — look up instance variable in local_var_types.
|
|
@@ -608,11 +611,8 @@ module Docscribe
|
|
|
608
611
|
def handle_block_node(node, **opts)
|
|
609
612
|
send_node = node.children[0]
|
|
610
613
|
if send_node&.type == :send
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
rbs_type = resolve_rbs_for_send(recv, meth, opts[:core_rbs_provider], opts[:local_var_types],
|
|
614
|
-
opts[:param_types])
|
|
615
|
-
return rbs_type if rbs_type
|
|
614
|
+
type = send_rbs_type(send_node.children[0], send_node.children[1], **opts)
|
|
615
|
+
return type if type
|
|
616
616
|
end
|
|
617
617
|
|
|
618
618
|
run_last_expr_type(node.children[2], **opts)
|
|
@@ -628,11 +628,8 @@ module Docscribe
|
|
|
628
628
|
recv = node.children[0]
|
|
629
629
|
meth = node.children[1]
|
|
630
630
|
|
|
631
|
-
if opts[:core_rbs_provider]
|
|
632
|
-
|
|
633
|
-
opts[:param_types])
|
|
634
|
-
return rbs_type if rbs_type
|
|
635
|
-
end
|
|
631
|
+
rbs_type = send_rbs_type(recv, meth, **opts) if opts[:core_rbs_provider]
|
|
632
|
+
return rbs_type if rbs_type
|
|
636
633
|
|
|
637
634
|
compound_type = infer_from_compound_assign(node, **opts)
|
|
638
635
|
return compound_type if compound_type
|
|
@@ -640,6 +637,25 @@ module Docscribe
|
|
|
640
637
|
Literals.type_from_literal(node, fallback_type: opts[:fallback_type])
|
|
641
638
|
end
|
|
642
639
|
|
|
640
|
+
# Resolve RBS return type for a send node, trying explicit receiver first,
|
|
641
|
+
# then falling back to the method's container for implicit self calls.
|
|
642
|
+
#
|
|
643
|
+
# @note module_function: defines #send_rbs_type (visibility: private)
|
|
644
|
+
# @param [Parser::AST::Node, nil] recv the receiver node
|
|
645
|
+
# @param [Symbol] meth the method name
|
|
646
|
+
# @param [Object] opts additional keyword options
|
|
647
|
+
# @return [String, nil]
|
|
648
|
+
def send_rbs_type(recv, meth, **opts)
|
|
649
|
+
rbs_type = resolve_rbs_for_send(recv, meth, opts[:core_rbs_provider], opts[:local_var_types],
|
|
650
|
+
opts[:param_types])
|
|
651
|
+
return rbs_type if rbs_type
|
|
652
|
+
|
|
653
|
+
rbs_type = resolve_rbs_for_send_with_signature_provider(recv, meth, **opts)
|
|
654
|
+
return rbs_type if rbs_type
|
|
655
|
+
|
|
656
|
+
container_rbs_return_type(meth, **opts) if recv.nil?
|
|
657
|
+
end
|
|
658
|
+
|
|
643
659
|
# Resolve RBS return type for a send node's receiver, if possible.
|
|
644
660
|
#
|
|
645
661
|
# Handles `:lvar`, chained `:send`, literal (`:int`, `:str`, etc.),
|
|
@@ -653,13 +669,59 @@ module Docscribe
|
|
|
653
669
|
# @param [Hash<String, String>, nil] param_types parameter name to type map
|
|
654
670
|
# @return [String, nil] resolved type or nil if unresolvable
|
|
655
671
|
def resolve_rbs_for_send(recv, meth, core_rbs_provider, local_var_types, param_types)
|
|
656
|
-
return nil unless core_rbs_provider
|
|
657
|
-
|
|
658
672
|
recv_type = receiver_rbs_type_name(recv, core_rbs_provider, local_var_types, param_types)
|
|
659
673
|
return nil unless recv_type
|
|
660
674
|
|
|
661
|
-
|
|
662
|
-
|
|
675
|
+
if core_rbs_provider
|
|
676
|
+
rbs = resolve_rbs_return_type(recv_type, meth, core_rbs_provider)
|
|
677
|
+
return rbs unless rbs == FALLBACK_TYPE
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
nil
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
# Resolve RBS return type via signature_provider fallback.
|
|
684
|
+
#
|
|
685
|
+
# Tries project-level RBS when core_rbs_provider fails.
|
|
686
|
+
#
|
|
687
|
+
# @note module_function: defines #resolve_rbs_for_send_with_signature_provider (visibility: private)
|
|
688
|
+
# @param [Parser::AST::Node, nil] recv the receiver node
|
|
689
|
+
# @param [Symbol] meth the method name
|
|
690
|
+
# @param [Object] opts additional keyword options
|
|
691
|
+
# @return [String, nil]
|
|
692
|
+
def resolve_rbs_for_send_with_signature_provider(recv, meth, **opts)
|
|
693
|
+
return nil unless opts[:signature_provider]
|
|
694
|
+
|
|
695
|
+
recv_type = receiver_rbs_type_name(recv, opts[:core_rbs_provider], opts[:local_var_types],
|
|
696
|
+
opts[:param_types])
|
|
697
|
+
return nil unless recv_type
|
|
698
|
+
|
|
699
|
+
opts[:signature_provider].signature_for(container: recv_type, scope: :instance, name: meth)&.return_type
|
|
700
|
+
end
|
|
701
|
+
|
|
702
|
+
# Resolve return type from the current method's container via RBS.
|
|
703
|
+
#
|
|
704
|
+
# Handles implicit self calls (recv is nil) by looking up the method
|
|
705
|
+
# on the container class.
|
|
706
|
+
#
|
|
707
|
+
# @note module_function: defines #container_rbs_return_type (visibility: private)
|
|
708
|
+
# @param [Symbol] meth the method name being called
|
|
709
|
+
# @param [Object] opts additional keyword options (must include :container and :core_rbs_provider)
|
|
710
|
+
# @return [String, nil] resolved type or nil if unresolvable
|
|
711
|
+
def container_rbs_return_type(meth, **opts)
|
|
712
|
+
return unless opts[:container]
|
|
713
|
+
|
|
714
|
+
if opts[:core_rbs_provider]
|
|
715
|
+
rbs = resolve_rbs_return_type(opts[:container], meth, opts[:core_rbs_provider])
|
|
716
|
+
return rbs unless rbs == FALLBACK_TYPE
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
if opts[:signature_provider]
|
|
720
|
+
sig = opts[:signature_provider].signature_for(container: opts[:container], scope: :instance, name: meth)
|
|
721
|
+
return sig.return_type if sig
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
nil
|
|
663
725
|
end
|
|
664
726
|
|
|
665
727
|
# Map a receiver AST node to its RBS type name string.
|
data/lib/docscribe/infer.rb
CHANGED
|
@@ -95,15 +95,19 @@ module Docscribe
|
|
|
95
95
|
# @param [Boolean] nil_as_optional render nil as optional
|
|
96
96
|
# @param [Docscribe::Types::RBS::Provider?] core_rbs_provider core RBS type lookup provider
|
|
97
97
|
# @param [Hash<String, String>?] param_types parameter name -> type map
|
|
98
|
+
# @param [String?] container
|
|
99
|
+
# @param [Docscribe::Types::ProviderChain?] signature_provider
|
|
98
100
|
# @return [Hash<Symbol, String, Array<(Array<String>, String)>>]
|
|
99
|
-
def returns_spec_from_node(node, fallback_type: FALLBACK_TYPE, nil_as_optional: true, core_rbs_provider: nil,
|
|
100
|
-
param_types: nil)
|
|
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
|
|
|
@@ -67,7 +67,7 @@ module Docscribe
|
|
|
67
67
|
# @param [Docscribe::Config] config Docscribe configuration object
|
|
68
68
|
# @param [Object] opts additional keyword options forwarded to doc_setup
|
|
69
69
|
# @raise [StandardError]
|
|
70
|
-
# @return [String, nil]
|
|
70
|
+
# @return [String, nil]
|
|
71
71
|
# @return [nil] if StandardError
|
|
72
72
|
def build(insertion, config:, **opts)
|
|
73
73
|
setup = doc_setup(insertion, config: config, **opts)
|
|
@@ -87,7 +87,7 @@ module Docscribe
|
|
|
87
87
|
# @param [Docscribe::Config] config Docscribe configuration object
|
|
88
88
|
# @param [Object] options additional keyword options forwarded to downstream methods
|
|
89
89
|
# @raise [StandardError]
|
|
90
|
-
# @return [String, nil]
|
|
90
|
+
# @return [String, nil]
|
|
91
91
|
# @return [nil] if StandardError
|
|
92
92
|
def build_merge_additions(insertion, existing_lines:, config:, **options)
|
|
93
93
|
setup = doc_setup(insertion, config: config, **options)
|
|
@@ -110,7 +110,7 @@ module Docscribe
|
|
|
110
110
|
# @param [Docscribe::Config] config Docscribe configuration object
|
|
111
111
|
# @param [Object] options additional keyword options forwarded to downstream methods
|
|
112
112
|
# @raise [StandardError]
|
|
113
|
-
# @return [Hash<Symbol, Object>]
|
|
113
|
+
# @return [Hash<Symbol, Object>]
|
|
114
114
|
# @return [Hash] if StandardError
|
|
115
115
|
def build_missing_merge_result(insertion, existing_lines:, config:, **options)
|
|
116
116
|
setup = doc_setup(insertion, config: config, **options)
|
|
@@ -187,7 +187,9 @@ module Docscribe
|
|
|
187
187
|
# @return [Hash<Symbol, Object>]
|
|
188
188
|
def resolve_doc_setup!(setup, node, name, config, opts)
|
|
189
189
|
external_sig = resolve_external_sig(setup[:container], setup[:scope], name, opts[:signature_provider])
|
|
190
|
-
returns_spec = compute_returns_spec(node, config, opts[:param_types], opts[:core_rbs_provider]
|
|
190
|
+
returns_spec = compute_returns_spec(node, config, opts[:param_types], opts[:core_rbs_provider],
|
|
191
|
+
signature_provider: opts[:signature_provider],
|
|
192
|
+
container: setup[:container])
|
|
191
193
|
normal_type = opts[:return_type_override] || external_sig&.return_type || returns_spec[:normal]
|
|
192
194
|
|
|
193
195
|
setup.merge(
|
|
@@ -229,11 +231,15 @@ module Docscribe
|
|
|
229
231
|
# @param [Docscribe::Config] config Docscribe configuration object
|
|
230
232
|
# @param [Hash<String, String>, nil] param_types hash accumulating parameter name-to-type mappings
|
|
231
233
|
# @param [Object] core_rbs_provider RBS type provider
|
|
234
|
+
# @param [Docscribe::Types::ProviderChain?] signature_provider
|
|
235
|
+
# @param [String?] container
|
|
232
236
|
# @return [Hash<Symbol, Object>]
|
|
233
|
-
def compute_returns_spec(node, config, param_types, core_rbs_provider
|
|
237
|
+
def compute_returns_spec(node, config, param_types, core_rbs_provider, # rubocop:disable Metrics/ParameterLists
|
|
238
|
+
signature_provider: nil, container: nil)
|
|
234
239
|
Docscribe::Infer.returns_spec_from_node(
|
|
235
240
|
node, fallback_type: config.fallback_type, nil_as_optional: config.nil_as_optional?,
|
|
236
|
-
param_types: param_types, core_rbs_provider: core_rbs_provider
|
|
241
|
+
param_types: param_types, core_rbs_provider: core_rbs_provider,
|
|
242
|
+
signature_provider: signature_provider, container: container
|
|
237
243
|
)
|
|
238
244
|
end
|
|
239
245
|
|
|
@@ -690,7 +696,7 @@ module Docscribe
|
|
|
690
696
|
# @note module_function: defines #extract_raise_types_from_line (visibility: private)
|
|
691
697
|
# @param [String] line a `@raise` doc line
|
|
692
698
|
# @raise [StandardError]
|
|
693
|
-
# @return [Array<String, nil>]
|
|
699
|
+
# @return [Array<String, nil>]
|
|
694
700
|
# @return [Array] if StandardError
|
|
695
701
|
def extract_raise_types_from_line(line)
|
|
696
702
|
return [] unless line.match?(/^\s*#\s*@raise\b/)
|
|
@@ -1998,7 +2004,7 @@ module Docscribe
|
|
|
1998
2004
|
# @note module_function: defines #safe_node_source (visibility: private)
|
|
1999
2005
|
# @param [Parser::AST::Node] node AST node whose source text to extract
|
|
2000
2006
|
# @raise [StandardError]
|
|
2001
|
-
# @return [String]
|
|
2007
|
+
# @return [String]
|
|
2002
2008
|
# @return [String] if StandardError
|
|
2003
2009
|
def safe_node_source(node)
|
|
2004
2010
|
node.loc.expression.source
|
|
@@ -260,7 +260,7 @@ module Docscribe
|
|
|
260
260
|
# @note module_function: defines #line_indent (visibility: private)
|
|
261
261
|
# @param [Parser::AST::Node] node target AST node
|
|
262
262
|
# @raise [StandardError]
|
|
263
|
-
# @return [String]
|
|
263
|
+
# @return [String]
|
|
264
264
|
# @return [String] if StandardError
|
|
265
265
|
def line_indent(node)
|
|
266
266
|
line = node.loc.expression.source_line
|
|
@@ -178,7 +178,7 @@ module Docscribe
|
|
|
178
178
|
# @param [Docscribe::Config] config the active Docscribe::Config
|
|
179
179
|
# @param [Object, nil] core_rbs_provider optional externally-provided core RBS provider
|
|
180
180
|
# @raise [StandardError]
|
|
181
|
-
# @return [Object, nil]
|
|
181
|
+
# @return [Object, nil]
|
|
182
182
|
# @return [nil] if StandardError
|
|
183
183
|
def load_core_rbs_provider(config, core_rbs_provider)
|
|
184
184
|
core_rbs_provider || (config.respond_to?(:core_rbs_provider) ? config.core_rbs_provider : nil)
|
|
@@ -456,7 +456,7 @@ module Docscribe
|
|
|
456
456
|
# @private
|
|
457
457
|
# @param [Hash<Symbol, Object>, Docscribe::InlineRewriter::Collector::Insertion, Docscribe::InlineRewriter::Collector::AttrInsertion] insertion the collected method insertion
|
|
458
458
|
# @raise [StandardError]
|
|
459
|
-
# @return [Integer]
|
|
459
|
+
# @return [Integer]
|
|
460
460
|
# @return [Integer] if StandardError
|
|
461
461
|
def plugin_insertion_priority(insertion)
|
|
462
462
|
return 0 unless insertion.is_a?(Hash)
|
|
@@ -471,7 +471,7 @@ module Docscribe
|
|
|
471
471
|
# @private
|
|
472
472
|
# @param [Hash<Symbol, Object>, Docscribe::InlineRewriter::Collector::Insertion, Docscribe::InlineRewriter::Collector::AttrInsertion] insertion the collected method insertion
|
|
473
473
|
# @raise [StandardError]
|
|
474
|
-
# @return [String]
|
|
474
|
+
# @return [String]
|
|
475
475
|
# @return [String] if StandardError
|
|
476
476
|
def plugin_insertion_label(insertion)
|
|
477
477
|
return 'unknown' unless insertion.is_a?(Hash)
|
|
@@ -487,7 +487,7 @@ module Docscribe
|
|
|
487
487
|
# @private
|
|
488
488
|
# @param [Hash<Symbol, Object>, Docscribe::InlineRewriter::Collector::Insertion, Docscribe::InlineRewriter::Collector::AttrInsertion] insertion the collected method insertion
|
|
489
489
|
# @raise [StandardError]
|
|
490
|
-
# @return [Integer, nil]
|
|
490
|
+
# @return [Integer, nil]
|
|
491
491
|
# @return [nil] if StandardError
|
|
492
492
|
def plugin_insertion_line(insertion)
|
|
493
493
|
return nil unless insertion.is_a?(Hash)
|
|
@@ -794,7 +794,9 @@ module Docscribe
|
|
|
794
794
|
# @return [void]
|
|
795
795
|
def merge_existing_descriptions!(params, parsed)
|
|
796
796
|
params[:param_descriptions] = parsed[:param_descriptions] if parsed[:param_descriptions].any?
|
|
797
|
-
|
|
797
|
+
if parsed[:return_description] && !parsed[:return_description].start_with?('if ')
|
|
798
|
+
params[:return_description] = parsed[:return_description]
|
|
799
|
+
end
|
|
798
800
|
params[:description] = parsed[:description] if parsed[:description].any?
|
|
799
801
|
end
|
|
800
802
|
|
|
@@ -854,15 +856,7 @@ module Docscribe
|
|
|
854
856
|
# @param [Docscribe::Config] config the active Docscribe::Config
|
|
855
857
|
# @return [Hash<String, String>, nil]
|
|
856
858
|
def resolve_param_types(insertion, external_sig, config)
|
|
857
|
-
|
|
858
|
-
DocBuilder.build_param_types_from_node(
|
|
859
|
-
insertion.node, external_sig: external_sig, config: config
|
|
860
|
-
)
|
|
861
|
-
else
|
|
862
|
-
DocBuilder.build_param_types_from_node(
|
|
863
|
-
insertion.node, external_sig: nil, config: config
|
|
864
|
-
)
|
|
865
|
-
end
|
|
859
|
+
DocBuilder.build_param_types_from_node(insertion.node, external_sig: external_sig, config: config)
|
|
866
860
|
end
|
|
867
861
|
|
|
868
862
|
# Apply method insertion aggressive
|
|
@@ -1240,7 +1234,7 @@ module Docscribe
|
|
|
1240
1234
|
# @param [Docscribe::Config] config the active Docscribe::Config
|
|
1241
1235
|
# @param [Docscribe::Types::ProviderChain, nil] signature_provider external RBS signature provider
|
|
1242
1236
|
# @raise [StandardError]
|
|
1243
|
-
# @return [String, nil]
|
|
1237
|
+
# @return [String, nil]
|
|
1244
1238
|
# @return [nil] if StandardError
|
|
1245
1239
|
def build_attr_merge_additions(ins:, existing_lines:, config:, signature_provider:)
|
|
1246
1240
|
missing = missing_attr_names(ins, existing_lines)
|
|
@@ -1326,7 +1320,7 @@ module Docscribe
|
|
|
1326
1320
|
# @param [Docscribe::Config] config the active Docscribe::Config
|
|
1327
1321
|
# @param [Docscribe::Types::ProviderChain, nil] signature_provider external RBS signature provider
|
|
1328
1322
|
# @raise [StandardError]
|
|
1329
|
-
# @return [String, nil]
|
|
1323
|
+
# @return [String, nil]
|
|
1330
1324
|
# @return [nil] if StandardError
|
|
1331
1325
|
def build_attr_doc_for_node(ins, config:, signature_provider:)
|
|
1332
1326
|
indent = SourceHelpers.line_indent(ins.node)
|
|
@@ -1447,8 +1441,8 @@ module Docscribe
|
|
|
1447
1441
|
# @param [Docscribe::Config] config the active configuration
|
|
1448
1442
|
# @param [Docscribe::Types::ProviderChain, nil] signature_provider RBS signature provider
|
|
1449
1443
|
# @raise [StandardError]
|
|
1444
|
+
# @return [String]
|
|
1450
1445
|
# @return [String] if StandardError
|
|
1451
|
-
# @return [Object] if StandardError
|
|
1452
1446
|
def attribute_type(ins, name_sym, config, signature_provider:)
|
|
1453
1447
|
ty = config.fallback_type
|
|
1454
1448
|
return ty unless signature_provider
|
|
@@ -1466,8 +1460,8 @@ module Docscribe
|
|
|
1466
1460
|
# @param [String] code the source code being processed
|
|
1467
1461
|
# @param [String] file the file name
|
|
1468
1462
|
# @raise [StandardError]
|
|
1469
|
-
# @return [Object, nil]
|
|
1470
|
-
# @return [
|
|
1463
|
+
# @return [Object, nil]
|
|
1464
|
+
# @return [Docscribe::Types::RBS::Provider, nil?] if StandardError
|
|
1471
1465
|
def build_signature_provider(config, code, file)
|
|
1472
1466
|
if config.respond_to?(:signature_provider_for)
|
|
1473
1467
|
config.signature_provider_for(source: code, file: file)
|
|
@@ -1525,7 +1519,7 @@ module Docscribe
|
|
|
1525
1519
|
# @private
|
|
1526
1520
|
# @param [Docscribe::InlineRewriter::Collector::Insertion] insertion the collected method insertion
|
|
1527
1521
|
# @raise [StandardError]
|
|
1528
|
-
# @return [Integer]
|
|
1522
|
+
# @return [Integer]
|
|
1529
1523
|
# @return [Object] if StandardError
|
|
1530
1524
|
def method_line_for(insertion)
|
|
1531
1525
|
anchor_node_for(insertion).loc.expression.line
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Docscribe
|
|
4
|
+
# Bounded LRU cache with O(1) access and eviction.
|
|
5
|
+
# Used by Server::Daemon for file rewrite caching.
|
|
6
|
+
class LRUCache
|
|
7
|
+
# @param [Integer] max_size
|
|
8
|
+
# @return [void]
|
|
9
|
+
def initialize(max_size = 1000)
|
|
10
|
+
@max_size = max_size
|
|
11
|
+
@data = {}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param [Object] key
|
|
15
|
+
# @return [Object]
|
|
16
|
+
def [](key)
|
|
17
|
+
val = @data[key]
|
|
18
|
+
return nil unless val
|
|
19
|
+
|
|
20
|
+
@data.delete(key)
|
|
21
|
+
@data[key] = val
|
|
22
|
+
val
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @param [Object] key
|
|
26
|
+
# @param [Object] val
|
|
27
|
+
# @return [Object]
|
|
28
|
+
def []=(key, val)
|
|
29
|
+
@data.delete(key) if @data.key?(key)
|
|
30
|
+
@data[key] = val
|
|
31
|
+
@data.shift if @data.size > @max_size
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [void]
|
|
35
|
+
def clear
|
|
36
|
+
@data.clear
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @return [Boolean]
|
|
40
|
+
def empty?
|
|
41
|
+
@data.empty?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @return [Integer]
|
|
45
|
+
def size
|
|
46
|
+
@data.size
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/docscribe/parsing.rb
CHANGED
|
@@ -42,7 +42,7 @@ module Docscribe
|
|
|
42
42
|
# @param [Parser::Source::Buffer] buffer prepared source buffer
|
|
43
43
|
# @param [Symbol] backend :auto, :parser, or :prism
|
|
44
44
|
# @raise [NoMethodError]
|
|
45
|
-
# @return [Parser::AST::Node, nil]
|
|
45
|
+
# @return [Parser::AST::Node, nil]
|
|
46
46
|
# @return [nil] if NoMethodError
|
|
47
47
|
def parse_buffer(buffer, backend: :auto)
|
|
48
48
|
parser = parser_for(backend: backend)
|
|
@@ -73,7 +73,7 @@ module Docscribe
|
|
|
73
73
|
# @param [Parser::Source::Buffer] buffer prepared source buffer
|
|
74
74
|
# @param [Symbol] backend :auto, :parser, or :prism
|
|
75
75
|
# @raise [NoMethodError]
|
|
76
|
-
# @return [(Parser::AST::Node?, Array<Parser::Source::Comment>), nil]
|
|
76
|
+
# @return [(Parser::AST::Node?, Array<Parser::Source::Comment>), nil]
|
|
77
77
|
# @return [nil] if NoMethodError
|
|
78
78
|
def parse_with_comments_buffer(buffer, backend: :auto)
|
|
79
79
|
parser = parser_for(backend: backend)
|
|
@@ -54,7 +54,7 @@ module Docscribe
|
|
|
54
54
|
# @param [String, Integer] priority plugin priority (higher wins for conflicts)
|
|
55
55
|
# @raise [StandardError]
|
|
56
56
|
# @raise [ArgumentError]
|
|
57
|
-
# @return [Integer]
|
|
57
|
+
# @return [Integer]
|
|
58
58
|
# @return [Object] if StandardError
|
|
59
59
|
def parse_priority(priority)
|
|
60
60
|
Integer(priority)
|
data/lib/docscribe/plugin.rb
CHANGED
|
@@ -58,7 +58,7 @@ module Docscribe
|
|
|
58
58
|
# @param [Parser::AST::Node] ast parsed AST root node
|
|
59
59
|
# @param [Parser::Source::Buffer] buffer source buffer for AST
|
|
60
60
|
# @raise [StandardError]
|
|
61
|
-
# @return [Array<Hash<Symbol, Object>>]
|
|
61
|
+
# @return [Array<Hash<Symbol, Object>>]
|
|
62
62
|
# @return [Array] if StandardError
|
|
63
63
|
def self.process_single_plugin_result(entry, ast, buffer)
|
|
64
64
|
plugin = entry.plugin
|