spoom 1.8.12 → 1.8.13
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 +6 -0
- data/lib/spoom/coverage/d3/base.rb +1 -1
- data/lib/spoom/coverage/d3/timeline.rb +1 -1
- data/lib/spoom/coverage/report.rb +2 -2
- data/lib/spoom/rbs.rb +15 -1
- data/lib/spoom/sorbet/lsp/structures.rb +1 -1
- data/lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/base_translator.rb +20 -10
- data/lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs/human_readable_translator.rb +9 -0
- data/lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb +12 -4
- data/lib/spoom/source/rewriter.rb +2 -2
- data/lib/spoom/version.rb +1 -1
- data/rbi/spoom.rbi +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f635fde4d393174f9f980312bd71fb2e2acb319e10d77ed894c62d795dde5ef9
|
|
4
|
+
data.tar.gz: fd6e3c6f2a271dd4b27e92c98373212d5aa61f5bfcd3c0519bf046d2255cccba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cf3ad6755704d567b904fdbfe1f0508682f70f09f320e97e9b5c095c9edd62cfcc426443575078d1dc97ee7aa9045e73d1433f53706ab9e08a314b004e982fc
|
|
7
|
+
data.tar.gz: ec8a52440bb314422240b686f5abffbcd0351d61e96576cf38bf77cf2678d1fa72a84e2dc33c20af34deb7a9829a68927bc4f1c4fcda8ec0b1d083559ccdbd99
|
data/README.md
CHANGED
|
@@ -256,6 +256,12 @@ Translate signatures from RBI to RBS comments:
|
|
|
256
256
|
spoom srb sigs translate
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
+
Include abstract methods:
|
|
260
|
+
|
|
261
|
+
```sh
|
|
262
|
+
spoom srb sigs translate --translate-abstract-methods
|
|
263
|
+
```
|
|
264
|
+
|
|
259
265
|
Translate signatures from RBS comments to RBI:
|
|
260
266
|
|
|
261
267
|
```sh
|
|
@@ -70,7 +70,7 @@ module Spoom
|
|
|
70
70
|
|
|
71
71
|
# @abstract
|
|
72
72
|
#: -> Array[Cards::Card]
|
|
73
|
-
def cards =
|
|
73
|
+
def cards = super
|
|
74
74
|
|
|
75
75
|
#: -> String
|
|
76
76
|
def footer_html
|
|
@@ -106,7 +106,7 @@ module Spoom
|
|
|
106
106
|
|
|
107
107
|
# @abstract
|
|
108
108
|
#: -> String
|
|
109
|
-
def erb =
|
|
109
|
+
def erb = super
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
class Snapshot < Card
|
data/lib/spoom/rbs.rb
CHANGED
|
@@ -66,6 +66,20 @@ module Spoom
|
|
|
66
66
|
@string = string
|
|
67
67
|
@location = location
|
|
68
68
|
end
|
|
69
|
+
|
|
70
|
+
# The `#` comments written inside this RBS comment (e.g.: #| String, # this is the inner comment)
|
|
71
|
+
#
|
|
72
|
+
# The RBS parser discards them, so they are found by lexing the RBS, which unlike looking for `#` doesn't
|
|
73
|
+
# mistake one written inside a string literal type (e.g. `"#"`) for a comment.
|
|
74
|
+
#
|
|
75
|
+
#: -> Array[String]
|
|
76
|
+
def inner_comments
|
|
77
|
+
return [] unless @string.include?("#")
|
|
78
|
+
|
|
79
|
+
::RBS::Parser.lex(@string).value.filter_map do |token|
|
|
80
|
+
token.location.source if token.type == :tCOMMENT || token.type == :tLINECOMMENT
|
|
81
|
+
end
|
|
82
|
+
end
|
|
69
83
|
end
|
|
70
84
|
|
|
71
85
|
class Annotation < Comment
|
|
@@ -120,7 +134,7 @@ module Spoom
|
|
|
120
134
|
continuation_locations = [] #: Array[Prism::Location]
|
|
121
135
|
|
|
122
136
|
continuation_comments.reverse_each do |continuation_comment|
|
|
123
|
-
string = "#{string}#{continuation_comment.slice.delete_prefix("#|")}"
|
|
137
|
+
string = "#{string}\n#{continuation_comment.slice.delete_prefix("#|")}"
|
|
124
138
|
location = location.join(continuation_comment.location)
|
|
125
139
|
continuation_locations << continuation_comment.location
|
|
126
140
|
end
|
|
@@ -127,7 +127,10 @@ module Spoom
|
|
|
127
127
|
@rewriter << Source::Replace.new(
|
|
128
128
|
signature.location.start_offset,
|
|
129
129
|
signature.location.end_offset,
|
|
130
|
-
pad_out_line_count(
|
|
130
|
+
pad_out_line_count(
|
|
131
|
+
of: preserve_comments(sig.string(max_line_length: @max_line_length), from: signature),
|
|
132
|
+
to_height_of: signature,
|
|
133
|
+
),
|
|
131
134
|
)
|
|
132
135
|
rescue ::RBS::ParsingError, ::RBI::Error
|
|
133
136
|
# Ignore signatures with errors
|
|
@@ -185,7 +188,10 @@ module Spoom
|
|
|
185
188
|
@rewriter << Source::Replace.new(
|
|
186
189
|
signature.location.start_offset,
|
|
187
190
|
signature.location.end_offset,
|
|
188
|
-
pad_out_line_count(
|
|
191
|
+
pad_out_line_count(
|
|
192
|
+
of: preserve_comments(sig.string(max_line_length: @max_line_length), from: signature),
|
|
193
|
+
to_height_of: signature,
|
|
194
|
+
),
|
|
189
195
|
)
|
|
190
196
|
end
|
|
191
197
|
|
|
@@ -215,7 +221,7 @@ module Spoom
|
|
|
215
221
|
# Called for every overloaded method sig that we discard because it wasn't the last one.
|
|
216
222
|
# @abstract
|
|
217
223
|
#: (Spoom::RBS::Signature) -> void
|
|
218
|
-
def rewrite_discarded_overload(signature) =
|
|
224
|
+
def rewrite_discarded_overload(signature) = super
|
|
219
225
|
|
|
220
226
|
#: (PrismTypes::anyScopeNode) -> void
|
|
221
227
|
def apply_class_annotations(node)
|
|
@@ -326,17 +332,17 @@ module Spoom
|
|
|
326
332
|
#| insert_pos: Integer,
|
|
327
333
|
#| sorbet_replacement: String?
|
|
328
334
|
#| ) -> void
|
|
329
|
-
def apply_class_annotation(annotation, parent_node:, insert_pos:, sorbet_replacement:) =
|
|
335
|
+
def apply_class_annotation(annotation, parent_node:, insert_pos:, sorbet_replacement:) = super
|
|
330
336
|
|
|
331
337
|
# Rewrites the `#: [...]` type params comment (e.g. delete it, or mark it as translated).
|
|
332
338
|
# @abstract
|
|
333
339
|
#: (Spoom::RBS::Signature, type_params: Array[::RBS::AST::TypeParam]) -> void
|
|
334
|
-
def rewrite_type_params_signature(signature, type_params:) =
|
|
340
|
+
def rewrite_type_params_signature(signature, type_params:) = super
|
|
335
341
|
|
|
336
342
|
# Inserts a single `type_member` declaration into the class/module body.
|
|
337
343
|
# @abstract
|
|
338
344
|
#: (String type_member, parent_node: PrismTypes::anyScopeNode, insert_pos: Integer) -> void
|
|
339
|
-
def insert_type_member(type_member, parent_node:, insert_pos:) =
|
|
345
|
+
def insert_type_member(type_member, parent_node:, insert_pos:) = super
|
|
340
346
|
|
|
341
347
|
#: (Array[Spoom::RBS::Annotation], RBI::Sig) -> Array[Spoom::RBS::Annotation]
|
|
342
348
|
def apply_member_annotations(annotations, sig)
|
|
@@ -389,7 +395,7 @@ module Spoom
|
|
|
389
395
|
|
|
390
396
|
# @abstract
|
|
391
397
|
#: (String mixin_name, into: PrismTypes::anyScopeNode, at: Integer) -> void
|
|
392
|
-
def extend_with(mixin_name, into:, at:) =
|
|
398
|
+
def extend_with(mixin_name, into:, at:) = super
|
|
393
399
|
|
|
394
400
|
#: (Array[Prism::Comment]) -> Array[Spoom::RBS::TypeAlias]
|
|
395
401
|
def collect_type_aliases(comments)
|
|
@@ -408,7 +414,7 @@ module Spoom
|
|
|
408
414
|
|
|
409
415
|
if string.start_with?("type ")
|
|
410
416
|
continuation_comments.reverse_each do |continuation_comment|
|
|
411
|
-
string = "#{string}#{continuation_comment.slice.delete_prefix("#|")}"
|
|
417
|
+
string = "#{string}\n#{continuation_comment.slice.delete_prefix("#|")}"
|
|
412
418
|
location = location.join(continuation_comment.location)
|
|
413
419
|
end
|
|
414
420
|
|
|
@@ -455,8 +461,8 @@ module Spoom
|
|
|
455
461
|
)
|
|
456
462
|
|
|
457
463
|
@rewriter << Source::Delete.new(from, to)
|
|
458
|
-
content = "#{
|
|
459
|
-
content = pad_out_line_count(of: content, to_height_of: type_alias)
|
|
464
|
+
content = preserve_comments("#{alias_name} = ::T.type_alias { #{sorbet_type.to_rbi} }", from: type_alias)
|
|
465
|
+
content = pad_out_line_count(of: "#{indent}#{content}\n", to_height_of: type_alias)
|
|
460
466
|
@rewriter << Source::Insert.new(insert_pos, content)
|
|
461
467
|
rescue ::RBS::ParsingError, ::RBI::Error
|
|
462
468
|
# Ignore type aliases with errors
|
|
@@ -464,6 +470,10 @@ module Spoom
|
|
|
464
470
|
end
|
|
465
471
|
end
|
|
466
472
|
|
|
473
|
+
# @overridable
|
|
474
|
+
#: (String replacement, from: Spoom::RBS::Comment) -> String
|
|
475
|
+
def preserve_comments(replacement, from:) = replacement # no-op
|
|
476
|
+
|
|
467
477
|
# @overridable
|
|
468
478
|
#: (of: String, to_height_of: Spoom::RBS::Comment) -> String
|
|
469
479
|
def pad_out_line_count(of:, to_height_of:)
|
|
@@ -56,6 +56,15 @@ module Spoom
|
|
|
56
56
|
@rewriter << Source::Insert.new(insert_pos, "\n#{indent}#{type_member}#{newline}")
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
# Keeps the comments written inside the RBS comment as lines above the replacement
|
|
60
|
+
#
|
|
61
|
+
# @override
|
|
62
|
+
#: (String replacement, from: Spoom::RBS::Comment) -> String
|
|
63
|
+
def preserve_comments(replacement, from:)
|
|
64
|
+
indent = " " * from.location.start_column
|
|
65
|
+
from.inner_comments.map { |comment| "#{comment}\n#{indent}" }.join + replacement
|
|
66
|
+
end
|
|
67
|
+
|
|
59
68
|
# @override
|
|
60
69
|
#: (String mixin_name, into: Prism::Node, at: Integer) -> void
|
|
61
70
|
def extend_with(mixin_name, into:, at:)
|
|
@@ -90,14 +90,22 @@ module Spoom
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
if last_sigs.any? { |_, sig| sig.is_abstract }
|
|
93
|
+
header = node.rparen_loc || node.parameters&.location || node.name_loc
|
|
94
|
+
comment = @comments.find do |comment|
|
|
95
|
+
comment.location.start_line == header.end_line &&
|
|
96
|
+
comment.location.start_offset >= header.end_offset &&
|
|
97
|
+
comment.location.end_offset < node.location.end_offset
|
|
98
|
+
end
|
|
99
|
+
header_comment = comment ? " #{comment.location.slice}" : ""
|
|
100
|
+
|
|
93
101
|
@rewriter << Source::Replace.new(
|
|
94
|
-
|
|
102
|
+
header.end_offset,
|
|
95
103
|
node.location.end_offset - 1,
|
|
96
|
-
if node.name.end_with?("=")
|
|
104
|
+
if node.name.end_with?("=") || (node.parameters && !node.rparen_loc)
|
|
97
105
|
indent = " " * node.location.start_column
|
|
98
|
-
"\n#{indent}
|
|
106
|
+
"#{header_comment}\n#{indent} super\n#{indent}end"
|
|
99
107
|
else
|
|
100
|
-
" =
|
|
108
|
+
" = super#{header_comment}"
|
|
101
109
|
end,
|
|
102
110
|
)
|
|
103
111
|
end
|
|
@@ -29,11 +29,11 @@ module Spoom
|
|
|
29
29
|
class Edit
|
|
30
30
|
# @abstract
|
|
31
31
|
#: (Array[Integer]) -> void
|
|
32
|
-
def apply(bytes) =
|
|
32
|
+
def apply(bytes) = super
|
|
33
33
|
|
|
34
34
|
# @abstract
|
|
35
35
|
#: -> [Integer, Integer]
|
|
36
|
-
def range =
|
|
36
|
+
def range = super
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
class Insert < Edit
|
data/lib/spoom/version.rb
CHANGED
data/rbi/spoom.rbi
CHANGED
|
@@ -2950,6 +2950,9 @@ class Spoom::RBS::Comment
|
|
|
2950
2950
|
sig { params(string: ::String, location: ::Prism::Location).void }
|
|
2951
2951
|
def initialize(string, location); end
|
|
2952
2952
|
|
|
2953
|
+
sig { returns(T::Array[::String]) }
|
|
2954
|
+
def inner_comments; end
|
|
2955
|
+
|
|
2953
2956
|
sig { returns(::Prism::Location) }
|
|
2954
2957
|
def location; end
|
|
2955
2958
|
|
|
@@ -3483,6 +3486,9 @@ class Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs::BaseTranslator < ::Spoo
|
|
|
3483
3486
|
sig { overridable.params(of: ::String, to_height_of: ::Spoom::RBS::Comment).returns(::String) }
|
|
3484
3487
|
def pad_out_line_count(of:, to_height_of:); end
|
|
3485
3488
|
|
|
3489
|
+
sig { overridable.params(replacement: ::String, from: ::Spoom::RBS::Comment).returns(::String) }
|
|
3490
|
+
def preserve_comments(replacement, from:); end
|
|
3491
|
+
|
|
3486
3492
|
sig { overridable.params(annotation: ::Spoom::RBS::Annotation, is_known: T::Boolean).void }
|
|
3487
3493
|
def rewrite_annotation(annotation, is_known:); end
|
|
3488
3494
|
|
|
@@ -3542,6 +3548,9 @@ class Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs::HumanReadableTranslator
|
|
|
3542
3548
|
end
|
|
3543
3549
|
def insert_type_member(type_member, parent_node:, insert_pos:); end
|
|
3544
3550
|
|
|
3551
|
+
sig { override.params(replacement: ::String, from: ::Spoom::RBS::Comment).returns(::String) }
|
|
3552
|
+
def preserve_comments(replacement, from:); end
|
|
3553
|
+
|
|
3545
3554
|
sig { override.params(signature: ::Spoom::RBS::Signature).void }
|
|
3546
3555
|
def rewrite_discarded_overload(signature); end
|
|
3547
3556
|
|