docscribe 1.2.1 → 1.3.0

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.
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'plugin/tag'
4
+ require_relative 'plugin/context'
5
+ require_relative 'plugin/base/tag_plugin'
6
+ require_relative 'plugin/base/collector_plugin'
7
+ require_relative 'plugin/registry'
8
+
9
+ module Docscribe
10
+ # Plugin system entry point.
11
+ #
12
+ # Provides two extension points:
13
+ #
14
+ # 1. TagPlugin — hooks into already-collected method insertions and appends
15
+ # additional YARD tags. Subclass Base::TagPlugin and override #call.
16
+ #
17
+ # 2. CollectorPlugin — receives the raw AST and walks it independently.
18
+ # Used for non-standard structures that Docscribe's Collector does not
19
+ # recognize. Subclass Base::CollectorPlugin and override #collect.
20
+ module Plugin
21
+ # Run all registered TagPlugins for one method context.
22
+ #
23
+ # Errors in individual plugins are caught so one broken plugin does not
24
+ # abort the entire run.
25
+ #
26
+ # @param [Docscribe::Plugin::Context] context
27
+ # @raise [StandardError]
28
+ # @return [Array<Docscribe::Plugin::Tag>]
29
+ def self.run_tag_plugins(context)
30
+ Registry.tag_plugins.flat_map do |plugin|
31
+ plugin.call(context)
32
+ rescue StandardError => e
33
+ warn "Docscribe: TagPlugin #{plugin.class} raised #{e.class}: #{e.message}" if debug?
34
+ []
35
+ end
36
+ end
37
+
38
+ # Run all registered CollectorPlugins for one file's AST.
39
+ #
40
+ # @param [Parser::AST::Node] ast
41
+ # @param [Parser::Source::Buffer] buffer
42
+ # @raise [StandardError]
43
+ # @return [Array<Hash>]
44
+ def self.run_collector_plugins(ast, buffer)
45
+ Registry.collector_plugins.flat_map do |plugin|
46
+ plugin.collect(ast, buffer)
47
+ rescue StandardError => e
48
+ warn "Docscribe: CollectorPlugin #{plugin.class} raised #{e.class}: #{e.message}" if debug?
49
+ []
50
+ end
51
+ end
52
+
53
+ # @return [Boolean]
54
+ def self.debug?
55
+ ENV['DOCSCRIBE_DEBUG'] == '1'
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,50 @@
1
+ # lib/docscribe/types/rbs/collection_loader.rb
2
+ # frozen_string_literal: true
3
+
4
+ require 'pathname'
5
+ require 'yaml'
6
+
7
+ module Docscribe
8
+ module Types
9
+ module RBS
10
+ # Resolve the RBS collection directory from rbs_collection.lock.yaml.
11
+ #
12
+ # After `bundle exec rbs collection install`, RBS writes a lock-file that
13
+ # records where gem signatures were installed. This loader reads that file
14
+ # so Docscribe can discover the collection directory automatically without
15
+ # requiring the user to pass --sig-dir manually.
16
+ #
17
+ # @example Typical lock-file structure
18
+ # ---
19
+ # sources: [...]
20
+ # path: ".gem_rbs_collection"
21
+ # gems: [...]
22
+ module CollectionLoader
23
+ LOCK_FILE = 'rbs_collection.lock.yaml'
24
+ DEFAULT_COLLECTION_PATH = '.gem_rbs_collection'
25
+
26
+ module_function
27
+
28
+ # Resolve the installed RBS collection directory.
29
+ #
30
+ # Returns nil when:
31
+ # - lock-file is absent (collection not initialized)
32
+ # - resolved directory does not exist on disk (collection not installed)
33
+ #
34
+ # @note module_function: when included, also defines #resolve (instance visibility: private)
35
+ # @param [String] root project root to search from
36
+ # @return [String, nil] absolute path to the collection directory, or nil
37
+ def resolve(root: Dir.pwd)
38
+ lock = Pathname(root).join(LOCK_FILE)
39
+ return nil unless lock.file?
40
+
41
+ data = YAML.safe_load(lock.read, permitted_classes: [Symbol]) || {}
42
+ rel = data['path'] || DEFAULT_COLLECTION_PATH
43
+
44
+ resolved = Pathname(root).join(rel)
45
+ resolved.directory? ? resolved.expand_path.to_s : nil
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -3,6 +3,7 @@
3
3
  require 'pathname'
4
4
  require 'docscribe/types/signature'
5
5
  require 'docscribe/types/rbs/type_formatter'
6
+ require 'docscribe/types/rbs/collection_loader'
6
7
 
7
8
  module Docscribe
8
9
  module Types
@@ -69,6 +70,8 @@ module Docscribe
69
70
  return if @env && @builder
70
71
 
71
72
  loader = ::RBS::EnvironmentLoader.new
73
+ # Load core types transitively
74
+ loader.add(library: 'rbs')
72
75
 
73
76
  @sig_dirs.each do |dir|
74
77
  path = Pathname(dir)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docscribe
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docscribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - unurgunite
@@ -135,8 +135,6 @@ dependencies:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
137
  version: 0.9.38
138
- email:
139
- - senpaiguru1488@gmail.com
140
138
  executables:
141
139
  - docscribe
142
140
  extensions: []
@@ -148,6 +146,7 @@ files:
148
146
  - lib/docscribe.rb
149
147
  - lib/docscribe/cli.rb
150
148
  - lib/docscribe/cli/config_builder.rb
149
+ - lib/docscribe/cli/generate.rb
151
150
  - lib/docscribe/cli/init.rb
152
151
  - lib/docscribe/cli/options.rb
153
152
  - lib/docscribe/cli/run.rb
@@ -156,6 +155,7 @@ files:
156
155
  - lib/docscribe/config/emit.rb
157
156
  - lib/docscribe/config/filtering.rb
158
157
  - lib/docscribe/config/loader.rb
158
+ - lib/docscribe/config/plugin.rb
159
159
  - lib/docscribe/config/rbs.rb
160
160
  - lib/docscribe/config/sorbet.rb
161
161
  - lib/docscribe/config/sorting.rb
@@ -176,7 +176,14 @@ files:
176
176
  - lib/docscribe/inline_rewriter/source_helpers.rb
177
177
  - lib/docscribe/inline_rewriter/tag_sorter.rb
178
178
  - lib/docscribe/parsing.rb
179
+ - lib/docscribe/plugin.rb
180
+ - lib/docscribe/plugin/base/collector_plugin.rb
181
+ - lib/docscribe/plugin/base/tag_plugin.rb
182
+ - lib/docscribe/plugin/context.rb
183
+ - lib/docscribe/plugin/registry.rb
184
+ - lib/docscribe/plugin/tag.rb
179
185
  - lib/docscribe/types/provider_chain.rb
186
+ - lib/docscribe/types/rbs/collection_loader.rb
180
187
  - lib/docscribe/types/rbs/provider.rb
181
188
  - lib/docscribe/types/rbs/type_formatter.rb
182
189
  - lib/docscribe/types/signature.rb
@@ -206,7 +213,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
213
  - !ruby/object:Gem::Version
207
214
  version: '0'
208
215
  requirements: []
209
- rubygems_version: 4.0.9
216
+ rubygems_version: 4.0.10
210
217
  specification_version: 4
211
- summary: Autogenerate documentation for Ruby code with YARD syntax.
218
+ summary: Auto-generate inline YARD documentation for Ruby by analyzing code AST. Supports
219
+ RBS and Sorbet type signatures.
212
220
  test_files: []