yard-rustdoc 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4967b9c11e8b1ae8ee17256f03033e05312d501c80c0d7b064b406be63b5855d
4
- data.tar.gz: 43b2bd77f9fc7c99ec64ae6d499c55fbf9882cbe65a9d550b08cf03ea2c7bf55
3
+ metadata.gz: 78e74a92126b3580032529eaa4f17361eb6d4dd885b1dcb42ce1ccae71afa130
4
+ data.tar.gz: c978d783880150a402baf41aca076ca0a736c988b32e6283ac953ca0b86c0377
5
5
  SHA512:
6
- metadata.gz: 0433a034cdf09fe3187b4d206bc857353ee79e56177908157c9c894b5149dc9433f1676ab06dbd7b524fb7a803c4ec5e4072a9f4846e7c995600382f29253fc8
7
- data.tar.gz: 258f273a75c1ed52c12a8718641e6ae459acf0d45edba16826d7903d39072e55f4b23bf6fa27fd9f6920a19c9728a1d4f7383c013e7571b45a95d3ff59ac42b6
6
+ metadata.gz: 50e53c9f30f82fd56bfa040176b127ac72cb5015463a5d738a01a73814fba8ba984862b3ac0b81968063654d0031237a390878073edd50a1978505df911f30b8
7
+ data.tar.gz: 53743f0a93ada894d5532d7d86d57cd88a6e68446f8c065582012cae96c02431f995c4146049c36e893b4912691ce9d5635bf89ab7d5c2d46ec2f8e469028e0b
data/README.md CHANGED
@@ -58,7 +58,7 @@ The `@rename` tag renames the class to `Foo::Baz`.
58
58
 
59
59
  ```rust
60
60
  /// @yard
61
- /// @remame Foo::Baz
61
+ /// @rename Foo::Baz
62
62
  pub struct InnerName { }
63
63
  ```
64
64
 
@@ -68,7 +68,7 @@ Defines `Foo::Bar.new` -- class method because the first argument isn't `self`.
68
68
  impl Bar {
69
69
  /// @yard
70
70
  /// @return [Foo::Bar]
71
- fn build() -> Self {}
71
+ fn new() -> Self {}
72
72
  }
73
73
  ```
74
74
 
@@ -109,7 +109,7 @@ impl Bar {
109
109
 
110
110
  #### Tips
111
111
 
112
- YARD's syntax differs from what Rustdoc expects. Linters you man want to disable:
112
+ YARD's syntax differs from what Rustdoc expects. Linters you might want to disable:
113
113
 
114
114
  ```rust
115
115
  #![allow(rustdoc::broken_intra_doc_links)]
@@ -30,11 +30,17 @@ module YARD::Parser::Rustdoc
30
30
 
31
31
  @rustdoc_json.each do |id, entry|
32
32
  next unless relevant_entry?(entry)
33
- next unless TOP_LEVEL_KINDS.include?(entry["kind"])
34
33
 
35
- methods = entry
36
- .dig("inner", "impls")
37
- .flat_map { |impl_id| @rustdoc_json.dig(impl_id, "inner", "items") }
34
+ # "inner" is a Rust enum serialized with serde, resulting in a
35
+ # { "variant": { ...variant fields... } } structure.
36
+ # See https://github.com/rust-lang/rust/blob/f79a912d9edc3ad4db910c0e93672ed5c65133fa/src/rustdoc-json-types/lib.rs#L104
37
+ kind, inner = entry["inner"].first
38
+
39
+ next unless TOP_LEVEL_KINDS.include?(kind)
40
+
41
+ methods = inner
42
+ .fetch("impls")
43
+ .flat_map { |impl_id| @rustdoc_json.dig(impl_id, "inner", "impl", "items") }
38
44
  .filter_map do |method_id|
39
45
  method_entry = @rustdoc_json.fetch(method_id)
40
46
  next unless relevant_entry?(method_entry)
@@ -45,6 +51,9 @@ module YARD::Parser::Rustdoc
45
51
  @entries << Statements::Struct.new(entry, methods)
46
52
  end
47
53
 
54
+ # Ensure Foo comes before Foo::Bar
55
+ @entries.sort! { |a, b| a.name <=> b.name }
56
+
48
57
  self
49
58
  end
50
59
 
@@ -101,9 +101,15 @@ module YARD::Parser::Rustdoc
101
101
  @name || @rustdoc.fetch("name")
102
102
  end
103
103
 
104
+ # Infers the scope (instance vs class) based on the usage of "self" or
105
+ # "rb_self" as an arg name.
104
106
  def scope
105
- first_arg = @rustdoc.dig("inner", "decl", "inputs", 0, 0)
106
- if first_arg == "self" || first_arg == "rb_self"
107
+ arg_names = @rustdoc
108
+ .dig("inner", "function", "decl", "inputs")
109
+ .map(&:first)
110
+ .slice(0, 2) # Magnus may inject a Ruby handle as arg0, hence we check 2 args
111
+
112
+ if arg_names.include?("self") || arg_names.include?("rb_self")
107
113
  :instance
108
114
  else
109
115
  :class
@@ -2,6 +2,6 @@
2
2
 
3
3
  module YARD
4
4
  module Rustdoc
5
- VERSION = "0.3.2"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-rustdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Bourassa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-01 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.3.24
118
+ rubygems_version: 3.5.3
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Generate YARD documentation for Magnus-based Rust gems.