decode 0.24.0 → 0.24.2
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
- checksums.yaml.gz.sig +0 -0
- data/lib/decode/comment/tags.rb +1 -1
- data/lib/decode/index.rb +2 -2
- data/lib/decode/language/ruby/class.rb +1 -1
- data/lib/decode/rbs/class.rb +5 -0
- data/lib/decode/rbs/generator.rb +19 -9
- data/lib/decode/rbs/method.rb +5 -0
- data/lib/decode/rbs/module.rb +3 -0
- data/lib/decode/rbs.rb +6 -0
- data/lib/decode/trie.rb +2 -2
- data/lib/decode/version.rb +1 -1
- data/readme.md +7 -7
- data/releases.md +7 -7
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6a3ca54cbbfe55c6946466efdeef71ee9b103ceb59ab27c313a9e3a4345264b
|
4
|
+
data.tar.gz: 00fe1c5faa769e7daa607cd46a48920ad04b4926493e1b841154d9a5f193b12a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288e3c278877013c633055242d28c1f2097ca38576896f86d486ee56f1ef3e246af36dce75d30c9c364cd65b9d4928b875b0f7d384c485efde3b27cad8658b14
|
7
|
+
data.tar.gz: debf415bab150aaeb345e3013bc6d07896ccf02006e0787eef2ba73754b9c02725007df042e397bedfc02d0b7b8acc266a946535acafcc6d03bd4e069836a937
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/decode/comment/tags.rb
CHANGED
data/lib/decode/index.rb
CHANGED
@@ -57,10 +57,10 @@ module Decode
|
|
57
57
|
def inspect
|
58
58
|
"#<#{self.class} #{@definitions.size} definition(s)>"
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# Generate a string representation of the index.
|
62
62
|
alias to_s inspect
|
63
|
-
|
63
|
+
|
64
64
|
# All supported languages for this index.
|
65
65
|
# @attribute [Languages] The languages this index can parse.
|
66
66
|
attr :languages
|
data/lib/decode/rbs/class.rb
CHANGED
@@ -8,13 +8,18 @@ require_relative "wrapper"
|
|
8
8
|
require_relative "method"
|
9
9
|
module Decode
|
10
10
|
module RBS
|
11
|
+
# Represents a Ruby class definition wrapper for RBS generation.
|
11
12
|
class Class < Wrapper
|
12
13
|
|
14
|
+
# Initialize a new class wrapper.
|
15
|
+
# @parameter definition [Decode::Definition] The class definition to wrap.
|
13
16
|
def initialize(definition)
|
14
17
|
super
|
15
18
|
@generics = nil
|
16
19
|
end
|
17
20
|
|
21
|
+
# Extract generic type parameters from the class definition.
|
22
|
+
# @returns [Array] The generic type parameters for this class.
|
18
23
|
def generics
|
19
24
|
@generics ||= extract_generics
|
20
25
|
end
|
data/lib/decode/rbs/generator.rb
CHANGED
@@ -10,7 +10,10 @@ require_relative "module"
|
|
10
10
|
|
11
11
|
module Decode
|
12
12
|
module RBS
|
13
|
+
# Represents a generator for RBS type declarations.
|
13
14
|
class Generator
|
15
|
+
# Initialize a new RBS generator.
|
16
|
+
# Sets up the RBS environment for type resolution.
|
14
17
|
def initialize
|
15
18
|
# Set up RBS environment for type resolution
|
16
19
|
@loader = ::RBS::EnvironmentLoader.new()
|
@@ -23,16 +26,19 @@ module Decode
|
|
23
26
|
def generate(index, output: $stdout)
|
24
27
|
# Build nested RBS AST structure using a hash for proper ||= behavior
|
25
28
|
declarations = {}
|
29
|
+
roots = {}
|
26
30
|
|
27
31
|
# Efficiently traverse the trie to find containers and their methods
|
28
32
|
index.trie.traverse do |lexical_path, node, descend|
|
29
33
|
# Process container definitions at this node
|
30
34
|
if node.values
|
31
|
-
containers = node.values.select
|
35
|
+
containers = node.values.select{|definition| definition.container? && definition.public?}
|
32
36
|
containers.each do |definition|
|
33
37
|
case definition
|
34
38
|
when Decode::Language::Ruby::Class, Decode::Language::Ruby::Module
|
35
|
-
build_nested_declaration(definition, declarations, index)
|
39
|
+
if declaration = build_nested_declaration(definition, declarations, index)
|
40
|
+
roots[definition.qualified_name] ||= declaration
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -44,18 +50,20 @@ module Decode
|
|
44
50
|
# Write the RBS output
|
45
51
|
writer = ::RBS::Writer.new(out: output)
|
46
52
|
|
47
|
-
unless
|
48
|
-
writer.write(
|
53
|
+
unless roots.empty?
|
54
|
+
writer.write(roots.values)
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
52
58
|
private
|
53
59
|
|
54
|
-
# Build nested RBS declarations preserving the parent hierarchy
|
60
|
+
# Build nested RBS declarations preserving the parent hierarchy.
|
61
|
+
# @returns [::RBS::AST::Declarations::Class | ::RBS::AST::Declarations::Module] If the definition has no parent, returns the declaration.
|
62
|
+
# @returns [Nil] If the definition has a parent, adds to parent's members.
|
55
63
|
def build_nested_declaration(definition, declarations, index)
|
56
64
|
# Create the declaration for this definition using ||= to avoid duplicates
|
57
65
|
qualified_name = definition.qualified_name
|
58
|
-
declarations[qualified_name] ||= definition_to_rbs(definition, index)
|
66
|
+
declaration = (declarations[qualified_name] ||= definition_to_rbs(definition, index))
|
59
67
|
|
60
68
|
# Add this declaration to its parent's members if it has a parent
|
61
69
|
if definition.parent
|
@@ -63,11 +71,13 @@ module Decode
|
|
63
71
|
parent_container = declarations[parent_qualified_name]
|
64
72
|
|
65
73
|
# Only add if not already present
|
66
|
-
unless parent_container.members.any?
|
67
|
-
member.respond_to?(:name) && member.name.name == definition.name.to_sym
|
68
|
-
}
|
74
|
+
unless parent_container.members.any?{|member| member.respond_to?(:name) && member.name.name == definition.name.to_sym}
|
69
75
|
parent_container.members << declarations[qualified_name]
|
70
76
|
end
|
77
|
+
|
78
|
+
return nil
|
79
|
+
else
|
80
|
+
return declaration
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
data/lib/decode/rbs/method.rb
CHANGED
@@ -10,13 +10,18 @@ require_relative "wrapper"
|
|
10
10
|
|
11
11
|
module Decode
|
12
12
|
module RBS
|
13
|
+
# Represents a Ruby method definition wrapper for RBS generation.
|
13
14
|
class Method < Wrapper
|
14
15
|
|
16
|
+
# Initialize a new method wrapper.
|
17
|
+
# @parameter definition [Decode::Definition] The method definition to wrap.
|
15
18
|
def initialize(definition)
|
16
19
|
super
|
17
20
|
@signatures = nil
|
18
21
|
end
|
19
22
|
|
23
|
+
# Extract method signatures from the method definition.
|
24
|
+
# @returns [Array] The extracted signatures for this method.
|
20
25
|
def signatures
|
21
26
|
@signatures ||= extract_signatures
|
22
27
|
end
|
data/lib/decode/rbs/module.rb
CHANGED
@@ -8,8 +8,11 @@ require_relative "wrapper"
|
|
8
8
|
|
9
9
|
module Decode
|
10
10
|
module RBS
|
11
|
+
# Represents a Ruby module definition wrapper for RBS generation.
|
11
12
|
class Module < Wrapper
|
12
13
|
|
14
|
+
# Initialize a new module wrapper.
|
15
|
+
# @parameter definition [Decode::Definition] The module definition to wrap.
|
13
16
|
def initialize(definition)
|
14
17
|
super
|
15
18
|
end
|
data/lib/decode/rbs.rb
CHANGED
data/lib/decode/trie.rb
CHANGED
@@ -21,10 +21,10 @@ module Decode
|
|
21
21
|
def inspect
|
22
22
|
"#<#{self.class} #{@children.size} children>"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Generate a string representation of the node.
|
26
26
|
alias to_s inspect
|
27
|
-
|
27
|
+
|
28
28
|
# A mutable array of all values that terminate at this node.
|
29
29
|
# @attribute [Array | Nil] The values stored at this node, or nil if no values.
|
30
30
|
attr_accessor :values
|
data/lib/decode/version.rb
CHANGED
data/readme.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Ruby code analysis tool and documentation generator.
|
4
4
|
|
5
|
-
[](https://github.com/socketry/decode/actions?workflow=Test)
|
6
6
|
|
7
7
|
## Motivation
|
8
8
|
|
@@ -10,21 +10,21 @@ As part of my effort to build [better project documentation](https://github.com/
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
-
Please see the [project documentation](https://
|
13
|
+
Please see the [project documentation](https://socketry.github.io/decode/) for more details.
|
14
14
|
|
15
|
-
- [Getting Started](https://
|
15
|
+
- [Getting Started](https://socketry.github.io/decode/guides/getting-started/index) - This guide explains how to use `decode` for source code analysis.
|
16
16
|
|
17
|
-
- [Code Coverage](https://
|
17
|
+
- [Code Coverage](https://socketry.github.io/decode/guides/code-coverage/index) - This guide explains how to compute documentation code coverage.
|
18
18
|
|
19
|
-
- [Extract Symbols](https://
|
19
|
+
- [Extract Symbols](https://socketry.github.io/decode/guides/extract-symbols/index) - This example demonstrates how to extract symbols using the index. An instance of <code class="language-ruby">Decode::Index</code> is used for loading symbols from source code files. These symbols are available as a flat list and as a trie structure. You can look up specific symbols using a reference using <code class="language-ruby">Decode::Index\#lookup</code>.
|
20
20
|
|
21
21
|
## Releases
|
22
22
|
|
23
|
-
Please see the [project releases](https://
|
23
|
+
Please see the [project releases](https://socketry.github.io/decode/releases/index) for all releases.
|
24
24
|
|
25
25
|
### v0.24.0
|
26
26
|
|
27
|
-
- [Introduce support for RBS signature generation
|
27
|
+
- [Introduce support for RBS signature generation](https://socketry.github.io/decode/releases/index#introduce-support-for-rbs-signature-generation)
|
28
28
|
|
29
29
|
### v0.23.5
|
30
30
|
|
data/releases.md
CHANGED
@@ -2,25 +2,25 @@
|
|
2
2
|
|
3
3
|
## v0.24.0
|
4
4
|
|
5
|
-
### Introduce support for RBS signature generation
|
5
|
+
### Introduce support for RBS signature generation
|
6
6
|
|
7
7
|
Decode now supports generating RBS type signatures from Ruby source code, making it easier to add type annotations to existing Ruby projects. The RBS generator analyzes your Ruby code and documentation to produce type signatures that can be used with tools like Steep, TypeProf, and other RBS-compatible type checkers.
|
8
8
|
|
9
9
|
To generate RBS signatures for your Ruby code, use the provided bake task:
|
10
10
|
|
11
11
|
``` bash
|
12
|
-
|
13
|
-
bundle exec bake decode:rbs:generate .
|
12
|
+
-- Generate RBS signatures for the current directory
|
13
|
+
$ bundle exec bake decode:rbs:generate .
|
14
14
|
|
15
|
-
|
16
|
-
bundle exec bake decode:rbs:generate lib/
|
15
|
+
-- Generate RBS signatures for a specific directory
|
16
|
+
$ bundle exec bake decode:rbs:generate lib/
|
17
17
|
```
|
18
18
|
|
19
19
|
The generator will output RBS declarations to stdout, which you can redirect to a file:
|
20
20
|
|
21
21
|
``` bash
|
22
|
-
|
23
|
-
bundle exec bake decode:rbs:generate lib/ > sig/generated.rbs
|
22
|
+
-- Save RBS signatures to a file
|
23
|
+
$ bundle exec bake decode:rbs:generate lib/ > sig/generated.rbs
|
24
24
|
```
|
25
25
|
|
26
26
|
The RBS generator produces type signatures for:
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.24.
|
4
|
+
version: 0.24.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -145,13 +145,13 @@ files:
|
|
145
145
|
- license.md
|
146
146
|
- readme.md
|
147
147
|
- releases.md
|
148
|
-
homepage: https://github.com/
|
148
|
+
homepage: https://github.com/socketry/decode
|
149
149
|
licenses:
|
150
150
|
- MIT
|
151
151
|
metadata:
|
152
|
-
documentation_uri: https://
|
153
|
-
funding_uri: https://github.com/sponsors/
|
154
|
-
source_code_uri: https://github.com/
|
152
|
+
documentation_uri: https://socketry.github.io/decode/
|
153
|
+
funding_uri: https://github.com/sponsors/socketry/
|
154
|
+
source_code_uri: https://github.com/socketry/decode.git
|
155
155
|
rdoc_options: []
|
156
156
|
require_paths:
|
157
157
|
- lib
|
metadata.gz.sig
CHANGED
Binary file
|