rbs-inline 0.2.0 → 0.3.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: '091f44026573a60f39acf39a0b8865a3cee4a4f72401cd0ab8ce37d9e397caad'
4
- data.tar.gz: 95236c91fac2461db268a7fbd81503210d0d818bad958a6b9ff03d708a28558b
3
+ metadata.gz: 44afba2006b4ffed3719716d5ac515d474dc7ba9ee18c4f9b3298c9925441284
4
+ data.tar.gz: 2c008cd99c1de1a2cb80945eed727b74fe9450af07fd3d20299775d5ee728978
5
5
  SHA512:
6
- metadata.gz: e76c5c6311109ffbac3a157625370a42f7f8b0cd2e1be58f8de4352d5e1528027acff819ecf7db6d9a6bb16bbb478adadfcb09d474816f7cc942a5a42be63729
7
- data.tar.gz: 8d7d4aba2f04cac960975add67c7d7ad30366806a540cd899a11f1250a7045145a9578732c055cf75ad50d1a68949d6aea55c7f7e3077d958aafb042f7c52149
6
+ metadata.gz: d7d02d3e07d295c00890ac95bad4c2f7f49700a0cdddb9885dcc3c194d272ef5b387c168f675a46f2b5dc3f49aaeb5230603dbe7ebcea20087952aebb7516b66
7
+ data.tar.gz: 6e476d54d6db64e42cdc7a6bfe9dfb5b1454f290e2746836cc17fe77ca41db5dac2b1a01d311877af189ee7ad2bd06207f1db2aaac86e1e494dd5855e921254d
@@ -9,18 +9,8 @@ module RBS
9
9
  # @rbs returns TypeName?
10
10
  def type_name(node)
11
11
  case node
12
- when Prism::ConstantReadNode
13
- TypeName(node.name.to_s)
14
- when Prism::ConstantPathNode
15
- if node.parent
16
- if parent = type_name(node.parent)
17
- if child = type_name(node.child)
18
- return parent + child
19
- end
20
- end
21
- else
22
- type_name(node.child)&.absolute!
23
- end
12
+ when Prism::ConstantReadNode, Prism::ConstantPathNode
13
+ TypeName(node.full_name)
24
14
  end
25
15
  end
26
16
  end
@@ -72,15 +72,28 @@ module RBS
72
72
  def run(args)
73
73
  base_paths = [Pathname("lib"), Pathname("app")]
74
74
  output_path = nil #: Pathname?
75
+ opt_in = true
75
76
 
76
77
  OptionParser.new do |opts|
77
- opts.on("--base=[BASE]", "The path to calculate relative path of files (defaults to #{base_paths.join(File::PATH_SEPARATOR)})") do |str|
78
+ opts.on("--base=BASE", "The path to calculate relative path of files (defaults to #{base_paths.join(File::PATH_SEPARATOR)})") do |str|
78
79
  # @type var str: String
79
80
  base_paths = str.split(File::PATH_SEPARATOR).map {|path| Pathname(path) }
80
81
  end
81
82
 
82
- opts.on("--output=[BASE]", "The directory where the RBS files are saved at (defaults to STDOUT if not specified)") do
83
- output_path = Pathname(_1)
83
+ opts.on("--output[=DEST]", "Save the generated RBS files under `sig/generated` or DEST if specified (defaults to output to STDOUT)") do
84
+ if _1
85
+ output_path = Pathname(_1)
86
+ else
87
+ output_path = Pathname("sig/generated")
88
+ end
89
+ end
90
+
91
+ opts.on("--opt-out", "Generates RBS files by default. Opt-out with `# rbs_inline: disabled` comment") do
92
+ opt_in = false
93
+ end
94
+
95
+ opts.on("--opt-in", "Generates RBS files only for files with `# rbs_inline: enabled` comment (default)") do
96
+ opt_in = true
84
97
  end
85
98
 
86
99
  opts.on("--verbose") do
@@ -126,7 +139,7 @@ module RBS
126
139
 
127
140
  logger.debug { "Parsing ruby file #{target}..." }
128
141
 
129
- if (uses, decls = Parser.parse(Prism.parse_file(target.to_s)))
142
+ if (uses, decls = Parser.parse(Prism.parse_file(target.to_s), opt_in: opt_in))
130
143
  writer = Writer.new()
131
144
  writer.header("Generated from #{target.relative? ? target : target.relative_path_from(Pathname.pwd)} with RBS::Inline")
132
145
  writer.write(uses, decls)
@@ -1,3 +1,5 @@
1
+ # rbs_inline: enabled
2
+
1
3
  # @rbs use Prism::*
2
4
 
3
5
  module RBS
@@ -36,22 +38,26 @@ module RBS
36
38
  @comments = {}
37
39
  end
38
40
 
39
- # @rbs result: ParseResult[ProgramNode]
41
+ # @rbs result: ParseResult
42
+ # @rbs opt_in: bool -- `true` for *opt-out* mode, `false` for *opt-in* mode.
40
43
  # @rbs returns [Array[AST::Annotations::Use], Array[AST::Declarations::t]]?
41
- def self.parse(result)
44
+ def self.parse(result, opt_in:)
42
45
  instance = Parser.new()
43
46
 
44
- # pp result
45
-
46
47
  annots = AnnotationParser.parse(result.comments)
47
48
  annots.each do |result|
48
49
  instance.comments[result.line_range.end] = result
49
50
  end
50
51
 
51
- with_magic_comment = result.comments.any? {|comment| comment.location.slice =~ /\A# rbs_inline: enabled\Z/}
52
- with_annotation = annots.any? {|result| result.annotations.any? }
52
+ with_enable_magic_comment = result.comments.any? {|comment| comment.location.slice =~ /\A# rbs_inline: enabled\Z/}
53
+ with_disable_magic_comment = result.comments.any? {|comment| comment.location.slice =~ /\A# rbs_inline: disabled\Z/}
53
54
 
54
- return unless with_magic_comment || with_annotation
55
+ return if with_disable_magic_comment # Skips if `rbs_inline: disabled`
56
+
57
+ if opt_in
58
+ # opt-in means the `rbs_inline: enable` is required.
59
+ return unless with_enable_magic_comment
60
+ end
55
61
 
56
62
  uses = [] #: Array[AST::Annotations::Use]
57
63
  annots.each do |annot|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RBS
4
4
  module Inline
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -38,7 +38,7 @@ gems:
38
38
  source:
39
39
  type: stdlib
40
40
  - name: prism
41
- version: 0.24.0
41
+ version: 0.29.0
42
42
  source:
43
43
  type: rubygems
44
44
  - name: rake
@@ -46,7 +46,7 @@ gems:
46
46
  source:
47
47
  type: git
48
48
  name: ruby/gem_rbs_collection
49
- revision: d2e93d426c927fdab90ef12e30a9875aa05d60d6
49
+ revision: 7a105f52053ce1c708b605dfa9c1ab8473424036
50
50
  remote: https://github.com/ruby/gem_rbs_collection.git
51
51
  repo_dir: gems
52
52
  - name: rbs
@@ -30,9 +30,10 @@ module RBS
30
30
 
31
31
  def initialize: () -> void
32
32
 
33
- # @rbs result: ParseResult[ProgramNode]
33
+ # @rbs result: ParseResult
34
+ # @rbs opt_in: bool -- `true` for *opt-out* mode, `false` for *opt-in* mode.
34
35
  # @rbs returns [Array[AST::Annotations::Use], Array[AST::Declarations::t]]?
35
- def self.parse: (ParseResult[ProgramNode] result) -> [ Array[AST::Annotations::Use], Array[AST::Declarations::t] ]?
36
+ def self.parse: (ParseResult result, opt_in: bool) -> [ Array[AST::Annotations::Use], Array[AST::Declarations::t] ]?
36
37
 
37
38
  # @rbs returns AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | nil
38
39
  def current_class_module_decl: () -> (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | nil)
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prism
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.29'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 0.24.0
22
+ version: '0.30'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.29'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 0.24.0
32
+ version: '0.30'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rbs
29
35
  requirement: !ruby/object:Gem::Requirement