ast-merge 7.1.17 → 7.1.20
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/README.md +5 -7
- data/lib/ast/merge/comment/augmenter.rb +47 -13
- data/lib/ast/merge/layout/augmenter.rb +46 -3
- data/lib/ast/merge/rust_host_provider.rb +25 -2
- data/lib/ast/merge/typed_core_provider.rb +32 -11
- data/lib/ast/merge/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +565 -514
- 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: 5843ccbe7f3d4bf1c4451abb158462a41afee71541a263c4fb56bf13ad8865b1
|
|
4
|
+
data.tar.gz: 64169e8e45b3aec72b0ccd6800d1bc19868084794105ae7a1b309b3cd0a7ad63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1680e98cb668c3885cc8e496a28cabfda991b35023cfb61536552aeb26e2d04b88a0b5fbfe2fe2eec8f298361fce30f2069f633011181101accb2f94d9b699f6
|
|
7
|
+
data.tar.gz: 6593b69de61fe214c91e1443bd2138c27243041dd21e8ca05cb890dc583f5b65585a3b9593b586d12cf25d40a27bd3e322981eeba52fc5bcf343bfd7e7d3ae95
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.md
CHANGED
|
@@ -366,11 +366,12 @@ The `Ast::Merge` module is organized into several namespaces, each with detailed
|
|
|
366
366
|
|
|
367
367
|
### Compatibility
|
|
368
368
|
|
|
369
|
-
|
|
369
|
+
The gem's declared runtime compatibility floor is MRI Ruby 4.0.0+, with concordant releases of JRuby and TruffleRuby.
|
|
370
370
|
CI workflows and Appraisals are generated for MRI Ruby 4.0.0+.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
371
|
+
The current MRI CI lane runs on Linux and macOS.
|
|
372
|
+
The test floor is configured by `ruby.test_minimum` in `.kettle-jem.yml`.
|
|
373
|
+
When it is higher than the runtime floor, older runtime-compatible Rubies are
|
|
374
|
+
not covered by the generated CI or Appraisal matrix.
|
|
374
375
|
|
|
375
376
|
<a href="https://github.com/kettle-dev"><img alt="kettle-dev Logo by Aboling0, CC BY-SA 4.0" src="https://logos.galtzo.com/assets/images/kettle-dev/avatar-128px.svg" width="14%" align="right"/></a>
|
|
376
377
|
|
|
@@ -611,9 +612,6 @@ If none of the available licenses suit your use case, please [contact us](mailto
|
|
|
611
612
|
[👨🏼🏫expsup-upwork-img]: https://img.shields.io/badge/UpWork-13544E?style=for-the-badge&logo=Upwork&logoColor=white
|
|
612
613
|
[👨🏼🏫expsup-codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github
|
|
613
614
|
[👨🏼🏫expsup-codementor-img]: https://img.shields.io/badge/CodeMentor-Get_Help-1abc9c?style=for-the-badge&logo=CodeMentor&logoColor=white
|
|
614
|
-
[🏙️entsup-tidelift]: https://tidelift.com/subscription/pkg/rubygems-ast-merge?utm_source=rubygems-ast-merge&utm_medium=referral&utm_campaign=readme
|
|
615
|
-
[🏙️entsup-tidelift-img]: https://img.shields.io/badge/Tidelift_and_Sonar-Enterprise_Support-FD3456?style=for-the-badge&logo=sonar&logoColor=white
|
|
616
|
-
[🏙️entsup-tidelift-sonar]: https://blog.tidelift.com/tidelift-joins-sonar
|
|
617
615
|
[💁🏼♂️peterboling]: http://www.peterboling.com
|
|
618
616
|
[🚂railsbling]: http://www.railsbling.com
|
|
619
617
|
[📜src-gl-img]: https://img.shields.io/badge/GitLab-FBA326?style=for-the-badge&logo=Gitlab&logoColor=orange
|
|
@@ -14,6 +14,7 @@ module Ast
|
|
|
14
14
|
:owners,
|
|
15
15
|
:tracked_comments,
|
|
16
16
|
:style,
|
|
17
|
+
:attachment_policy,
|
|
17
18
|
:capability,
|
|
18
19
|
:attachments_by_owner,
|
|
19
20
|
:preamble_region,
|
|
@@ -30,9 +31,11 @@ module Ast
|
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
def initialize(lines: nil, source: nil, comments: [], owners: [], style: nil, capability: nil,
|
|
34
|
+
def initialize(lines: nil, source: nil, comments: [], owners: [], style: nil, capability: nil,
|
|
35
|
+
attachment_policy: :preceding_owner, **options)
|
|
34
36
|
@lines = normalize_lines(lines, source)
|
|
35
37
|
@style = resolve_style(style)
|
|
38
|
+
@attachment_policy = normalize_attachment_policy(attachment_policy)
|
|
36
39
|
@owners = normalize_owners(owners)
|
|
37
40
|
@tracked_comments = normalize_comments(comments)
|
|
38
41
|
@capability = capability || Capability.source_augmented(
|
|
@@ -63,28 +66,32 @@ module Ast
|
|
|
63
66
|
|
|
64
67
|
def build!
|
|
65
68
|
claimed = Set.new
|
|
69
|
+
comments_by_owner = owners.to_h do |owner|
|
|
70
|
+
leading = infer_leading_comments(owner, claimed)
|
|
71
|
+
inline = infer_inline_comments(owner, claimed)
|
|
72
|
+
trailing = infer_trailing_comments(owner, claimed)
|
|
73
|
+
leading.each { |comment| claimed << comment.object_id }
|
|
74
|
+
inline.each { |comment| claimed << comment.object_id }
|
|
75
|
+
trailing.each { |comment| claimed << comment.object_id }
|
|
76
|
+
[owner, { leading: leading, inline: inline, trailing: trailing }]
|
|
77
|
+
end
|
|
66
78
|
layout_attachments = build_layout_attachments_by_owner
|
|
67
79
|
|
|
68
80
|
owners.each do |owner|
|
|
69
|
-
|
|
70
|
-
inline_comments = infer_inline_comments(owner, claimed)
|
|
71
|
-
trailing_comments = infer_trailing_comments(owner, claimed)
|
|
81
|
+
comments = comments_by_owner.fetch(owner)
|
|
72
82
|
layout_attachment = layout_attachments[owner]
|
|
83
|
+
leading_comments = comments.fetch(:leading)
|
|
73
84
|
|
|
74
85
|
leading_floating = leading_comments.any? && gap_before_owner?(leading_comments, owner)
|
|
75
86
|
|
|
76
87
|
attachments_by_owner[owner] = Attachment.new(
|
|
77
88
|
owner: owner,
|
|
78
89
|
leading_region: build_region(:leading, leading_comments, floating: leading_floating),
|
|
79
|
-
inline_region: build_region(:inline,
|
|
80
|
-
trailing_region: build_region(:trailing,
|
|
90
|
+
inline_region: build_region(:inline, comments.fetch(:inline), include_blank_lines: false),
|
|
91
|
+
trailing_region: build_region(:trailing, comments.fetch(:trailing)),
|
|
81
92
|
leading_gap: layout_attachment&.leading_gap,
|
|
82
93
|
trailing_gap: layout_attachment&.trailing_gap
|
|
83
94
|
)
|
|
84
|
-
|
|
85
|
-
leading_comments.each { |comment| claimed << comment.object_id }
|
|
86
|
-
inline_comments.each { |comment| claimed << comment.object_id }
|
|
87
|
-
trailing_comments.each { |comment| claimed << comment.object_id }
|
|
88
95
|
end
|
|
89
96
|
|
|
90
97
|
infer_postlude!(claimed)
|
|
@@ -96,7 +103,8 @@ module Ast
|
|
|
96
103
|
return [] unless owner.start_line
|
|
97
104
|
|
|
98
105
|
candidates = tracked_comments.select do |comment|
|
|
99
|
-
|
|
106
|
+
owner_scoped_comment?(comment) && comment[:full_line] &&
|
|
107
|
+
!claimed.include?(comment.object_id) && comment[:line] < owner.start_line
|
|
100
108
|
end
|
|
101
109
|
return [] if candidates.empty?
|
|
102
110
|
|
|
@@ -109,7 +117,11 @@ module Ast
|
|
|
109
117
|
if comment
|
|
110
118
|
selected.unshift(comment)
|
|
111
119
|
current_line -= 1
|
|
112
|
-
elsif blank_line?(current_line)
|
|
120
|
+
elsif blank_line?(current_line) && (
|
|
121
|
+
attachment_policy == :preceding_owner ||
|
|
122
|
+
selected.last&.fetch(:structural_prefix, false) ||
|
|
123
|
+
structural_prefix_comment_before_blank?(current_line, candidates)
|
|
124
|
+
)
|
|
113
125
|
current_line -= 1
|
|
114
126
|
else
|
|
115
127
|
break
|
|
@@ -119,18 +131,27 @@ module Ast
|
|
|
119
131
|
strip_preamble(selected, owner.start_line)
|
|
120
132
|
end
|
|
121
133
|
|
|
134
|
+
def structural_prefix_comment_before_blank?(current_line, candidates)
|
|
135
|
+
candidate = candidates.select { |comment| comment[:line] < current_line }.max_by { |comment| comment[:line] }
|
|
136
|
+
return false unless candidate&.fetch(:structural_prefix, false)
|
|
137
|
+
|
|
138
|
+
((candidate[:line] + 1)...current_line).all? { |line_number| blank_line?(line_number) }
|
|
139
|
+
end
|
|
140
|
+
|
|
122
141
|
def infer_inline_comments(owner, claimed)
|
|
123
142
|
return [] unless owner.respond_to?(:start_line) && owner.respond_to?(:end_line)
|
|
124
143
|
return [] unless owner.start_line && owner.end_line
|
|
125
144
|
|
|
126
145
|
tracked_comments.select do |comment|
|
|
127
146
|
!comment[:full_line] &&
|
|
147
|
+
owner_scoped_comment?(comment) &&
|
|
128
148
|
!claimed.include?(comment.object_id) &&
|
|
129
149
|
(owner.start_line..owner.end_line).cover?(comment[:line])
|
|
130
150
|
end
|
|
131
151
|
end
|
|
132
152
|
|
|
133
153
|
def infer_trailing_comments(owner, claimed)
|
|
154
|
+
return [] if attachment_policy == :following_owner
|
|
134
155
|
return [] unless owner.respond_to?(:end_line)
|
|
135
156
|
return [] unless owner.end_line
|
|
136
157
|
|
|
@@ -143,6 +164,7 @@ module Ast
|
|
|
143
164
|
while current <= max_line
|
|
144
165
|
comment = tracked_comments.find do |candidate|
|
|
145
166
|
candidate[:full_line] &&
|
|
167
|
+
owner_scoped_comment?(candidate) &&
|
|
146
168
|
!claimed.include?(candidate.object_id) &&
|
|
147
169
|
candidate[:line] == current &&
|
|
148
170
|
trailing_comment_owned_by?(candidate, owner)
|
|
@@ -162,7 +184,8 @@ module Ast
|
|
|
162
184
|
return unless last_line
|
|
163
185
|
|
|
164
186
|
comments = tracked_comments.select do |comment|
|
|
165
|
-
|
|
187
|
+
owner_scoped_comment?(comment) && comment[:full_line] &&
|
|
188
|
+
!claimed.include?(comment.object_id) && comment[:line] > last_line
|
|
166
189
|
end
|
|
167
190
|
return if comments.empty?
|
|
168
191
|
|
|
@@ -208,6 +231,10 @@ module Ast
|
|
|
208
231
|
end
|
|
209
232
|
end
|
|
210
233
|
|
|
234
|
+
def owner_scoped_comment?(comment)
|
|
235
|
+
comment.fetch(:scope, :owner).to_sym != :root
|
|
236
|
+
end
|
|
237
|
+
|
|
211
238
|
# Split a comment group that starts at line 1 into preamble and
|
|
212
239
|
# non-preamble portions at the last blank-line gap before
|
|
213
240
|
# +first_owner_start+.
|
|
@@ -317,6 +344,13 @@ module Ast
|
|
|
317
344
|
values
|
|
318
345
|
end
|
|
319
346
|
|
|
347
|
+
def normalize_attachment_policy(policy)
|
|
348
|
+
value = policy.to_sym
|
|
349
|
+
return value if %i[preceding_owner following_owner].include?(value)
|
|
350
|
+
|
|
351
|
+
raise ArgumentError, "Unknown comment attachment policy: #{policy.inspect}"
|
|
352
|
+
end
|
|
353
|
+
|
|
320
354
|
def resolve_style(style)
|
|
321
355
|
case style
|
|
322
356
|
when nil
|
|
@@ -21,11 +21,12 @@ module Ast
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def initialize(lines: nil, source: nil, owners: [], start_line_for: nil, end_line_for: nil, metadata: {},
|
|
24
|
-
**options)
|
|
24
|
+
comment_boundaries: [], **options)
|
|
25
25
|
@lines = normalize_lines(lines, source)
|
|
26
26
|
@start_line_for = start_line_for
|
|
27
27
|
@end_line_for = end_line_for
|
|
28
28
|
@owners = normalize_owners(owners)
|
|
29
|
+
@comment_boundaries = normalize_comment_boundaries(comment_boundaries)
|
|
29
30
|
@metadata = metadata.merge(options).freeze
|
|
30
31
|
@attachments_by_owner = {}
|
|
31
32
|
@preamble_gap = nil
|
|
@@ -58,8 +59,12 @@ module Ast
|
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
blank_runs.each do |run|
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
structural_before = owners.reverse_each.find { |owner| owner_end_line(owner) == run[:start_line] - 1 }
|
|
63
|
+
structural_after = owners.find { |owner| owner_start_line(owner) == run[:end_line] + 1 }
|
|
64
|
+
comment_before = comment_boundary_owner(:trailing, run[:start_line], :end_line)
|
|
65
|
+
comment_after = comment_boundary_owner(:leading, run[:end_line] + 1, :start_line)
|
|
66
|
+
before_owner = structural_before || comment_before
|
|
67
|
+
after_owner = structural_after || comment_after
|
|
63
68
|
next unless before_owner || after_owner
|
|
64
69
|
|
|
65
70
|
kind = if before_owner && after_owner
|
|
@@ -70,6 +75,14 @@ module Ast
|
|
|
70
75
|
:preamble
|
|
71
76
|
end
|
|
72
77
|
|
|
78
|
+
controller_side = if structural_before && !structural_after && comment_after
|
|
79
|
+
:before
|
|
80
|
+
elsif structural_after || after_owner
|
|
81
|
+
:after
|
|
82
|
+
else
|
|
83
|
+
:before
|
|
84
|
+
end
|
|
85
|
+
|
|
73
86
|
gap = Gap.new(
|
|
74
87
|
kind: kind,
|
|
75
88
|
start_line: run[:start_line],
|
|
@@ -77,6 +90,7 @@ module Ast
|
|
|
77
90
|
lines: run[:lines],
|
|
78
91
|
before_owner: before_owner,
|
|
79
92
|
after_owner: after_owner,
|
|
93
|
+
controller_side: controller_side,
|
|
80
94
|
metadata: { source: :layout_augmenter }
|
|
81
95
|
)
|
|
82
96
|
|
|
@@ -104,6 +118,35 @@ module Ast
|
|
|
104
118
|
end
|
|
105
119
|
end
|
|
106
120
|
|
|
121
|
+
def normalize_comment_boundaries(boundaries)
|
|
122
|
+
Array(boundaries).map do |boundary|
|
|
123
|
+
owner = boundary.fetch(:owner)
|
|
124
|
+
kind = boundary.fetch(:kind).to_sym
|
|
125
|
+
start_line = Integer(boundary.fetch(:start_line))
|
|
126
|
+
end_line = Integer(boundary.fetch(:end_line))
|
|
127
|
+
unless owners.include?(owner) && %i[leading trailing].include?(kind) &&
|
|
128
|
+
start_line.positive? && end_line >= start_line && end_line <= lines.length
|
|
129
|
+
raise ArgumentError, 'comment boundary has an invalid owner, kind, or line range'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
outside_owner = if kind == :leading
|
|
133
|
+
end_line < owner_start_line(owner)
|
|
134
|
+
else
|
|
135
|
+
start_line > owner_end_line(owner)
|
|
136
|
+
end
|
|
137
|
+
raise ArgumentError, 'comment boundary overlaps its structural owner' unless outside_owner
|
|
138
|
+
|
|
139
|
+
{ owner: owner, kind: kind, start_line: start_line, end_line: end_line }.freeze
|
|
140
|
+
end.freeze
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def comment_boundary_owner(kind, line, edge)
|
|
144
|
+
boundary = @comment_boundaries.find do |candidate|
|
|
145
|
+
candidate.fetch(:kind) == kind && candidate.fetch(edge) == line
|
|
146
|
+
end
|
|
147
|
+
boundary&.fetch(:owner)
|
|
148
|
+
end
|
|
149
|
+
|
|
107
150
|
def blank_runs
|
|
108
151
|
runs = []
|
|
109
152
|
index = 0
|
|
@@ -24,14 +24,20 @@ module Ast
|
|
|
24
24
|
@dialect = dialect
|
|
25
25
|
@package = package
|
|
26
26
|
@package_version = package_version
|
|
27
|
-
@host_methods = host_methods.
|
|
27
|
+
@host_methods = host_methods.to_h do |operation, method_name|
|
|
28
|
+
[operation.to_sym, method_name.to_sym]
|
|
29
|
+
end.freeze
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
attr_reader :provider_id, :family
|
|
31
33
|
|
|
32
34
|
def capabilities
|
|
35
|
+
operations = []
|
|
36
|
+
operations.concat(%i[analyze diff2]) if @host_methods.key?(:analyze)
|
|
37
|
+
operations << :merge2 if @host_methods.key?(:merge2)
|
|
38
|
+
operations << :merge3 if @host_methods.key?(:merge3)
|
|
33
39
|
{
|
|
34
|
-
operations:
|
|
40
|
+
operations: operations.freeze,
|
|
35
41
|
dialects: [@dialect],
|
|
36
42
|
backends: [:rust_tslp],
|
|
37
43
|
profiles: [:source_preserving],
|
|
@@ -41,6 +47,8 @@ module Ast
|
|
|
41
47
|
end
|
|
42
48
|
|
|
43
49
|
def analyze(request)
|
|
50
|
+
return unsupported_result(:analyze) unless operation_supported?(:analyze)
|
|
51
|
+
|
|
44
52
|
raw = call_host(:analyze, request.fetch(:source), request.fetch(:dialect).to_s)
|
|
45
53
|
return failure(:analyze, request, raw) unless raw.fetch('ok')
|
|
46
54
|
|
|
@@ -69,6 +77,8 @@ module Ast
|
|
|
69
77
|
end
|
|
70
78
|
|
|
71
79
|
def diff2(request)
|
|
80
|
+
return unsupported_result(:diff2) unless operation_supported?(:diff2)
|
|
81
|
+
|
|
72
82
|
before = analysis_for(request.fetch(:before_source), request.fetch(:dialect).to_s)
|
|
73
83
|
return failure(:diff2, request, before) unless before.fetch('ok')
|
|
74
84
|
|
|
@@ -116,6 +126,8 @@ module Ast
|
|
|
116
126
|
end
|
|
117
127
|
|
|
118
128
|
def merge2(request)
|
|
129
|
+
return unsupported_result(:merge2) unless operation_supported?(:merge2)
|
|
130
|
+
|
|
119
131
|
raw = call_host(
|
|
120
132
|
:merge2,
|
|
121
133
|
request.fetch(:current_source),
|
|
@@ -128,6 +140,8 @@ module Ast
|
|
|
128
140
|
end
|
|
129
141
|
|
|
130
142
|
def merge3(request)
|
|
143
|
+
return unsupported_result(:merge3) unless operation_supported?(:merge3)
|
|
144
|
+
|
|
131
145
|
raw = call_host(
|
|
132
146
|
:merge3,
|
|
133
147
|
request.fetch(:base_source),
|
|
@@ -142,6 +156,15 @@ module Ast
|
|
|
142
156
|
|
|
143
157
|
private
|
|
144
158
|
|
|
159
|
+
def operation_supported?(operation)
|
|
160
|
+
capabilities[:operations].include?(operation)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def unsupported_result(operation)
|
|
164
|
+
ProviderResult.unsupported(operation: operation,
|
|
165
|
+
message: 'Rust host does not implement this operation')
|
|
166
|
+
end
|
|
167
|
+
|
|
145
168
|
def host
|
|
146
169
|
require 'structuredmerge_core' unless defined?(::StructuredmergeCore)
|
|
147
170
|
::StructuredmergeCore
|
|
@@ -7,6 +7,8 @@ module Ast
|
|
|
7
7
|
module Merge
|
|
8
8
|
# Shared typed transport adaptation. Subclasses select explicit Rust profiles.
|
|
9
9
|
class TypedCoreProvider
|
|
10
|
+
class UnsupportedCapabilityError < StandardError; end
|
|
11
|
+
|
|
10
12
|
DIALECTS = %i[json jsonc json5].freeze
|
|
11
13
|
ROLES = { analyze: %i[source], diff2: %i[before after], merge2: %i[incoming current],
|
|
12
14
|
merge3: %i[base ours theirs] }.freeze
|
|
@@ -32,7 +34,7 @@ module Ast
|
|
|
32
34
|
def family = self.class::FAMILY
|
|
33
35
|
|
|
34
36
|
def capabilities
|
|
35
|
-
{ operations: self.class::OPERATIONS, dialects: self.class::DIALECTS, backends:
|
|
37
|
+
{ operations: self.class::OPERATIONS, dialects: self.class::DIALECTS, backends: parser_backends,
|
|
36
38
|
profiles: [:source_preserving], role: :workflow,
|
|
37
39
|
source_preservation: %i[exact_source byte_spans reparse] }.freeze
|
|
38
40
|
end
|
|
@@ -46,6 +48,8 @@ module Ast
|
|
|
46
48
|
def core = ::StructuredmergeCore
|
|
47
49
|
|
|
48
50
|
def execute(operation, request)
|
|
51
|
+
request = ProviderContract.normalize_hash(request)
|
|
52
|
+
|
|
49
53
|
unless capabilities[:operations].include?(operation)
|
|
50
54
|
return Ast::Merge::ProviderResult.unsupported(operation: operation,
|
|
51
55
|
message: 'Typed profile does not implement this operation')
|
|
@@ -55,19 +59,20 @@ module Ast
|
|
|
55
59
|
allowed = fields + %i[dialect provider_id family backend profile_id request_id] + additional_fields
|
|
56
60
|
unless (request.keys - allowed).empty? &&
|
|
57
61
|
self.class::DIALECTS.include?(request.fetch(:dialect, default_dialect).to_s.to_sym) &&
|
|
58
|
-
[nil,
|
|
62
|
+
[nil, *parser_backends.map(&:to_s)].include?(request[:backend]&.to_s) &&
|
|
59
63
|
[nil, 'source_preserving'].include?(request[:profile_id]&.to_s) &&
|
|
60
64
|
[nil, provider_id].include?(request[:provider_id]) && [nil, family].include?(request[:family]&.to_s)
|
|
61
65
|
return Ast::Merge::ProviderResult.unsupported(operation: operation,
|
|
62
66
|
message: 'Typed provider cannot honor the requested fields or selectors')
|
|
63
67
|
end
|
|
64
|
-
|
|
68
|
+
dialect = request.fetch(:dialect, default_dialect).to_s
|
|
69
|
+
backend = request[:backend]&.to_s || default_parser_backend.to_s
|
|
70
|
+
unless parser_backend_available?(backend)
|
|
65
71
|
return Ast::Merge::ProviderResult.unsupported(operation: operation,
|
|
66
|
-
message:
|
|
72
|
+
message: "Requested parser backend #{backend} is unavailable")
|
|
67
73
|
end
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
parser_id = TreeHaver::Backends::RustTslp.register_language_parser(parser_language(dialect))
|
|
75
|
+
parser_id = register_parser_backend(dialect, backend)
|
|
71
76
|
sources = ROLES.fetch(operation).zip(fields).to_h do |role, field|
|
|
72
77
|
text = request.fetch(field)
|
|
73
78
|
unless text.is_a?(String) && [Encoding::UTF_8, Encoding::US_ASCII, Encoding::ASCII_8BIT].include?(text.encoding)
|
|
@@ -90,7 +95,9 @@ module Ast
|
|
|
90
95
|
result = core.execute_operation(typed_request,
|
|
91
96
|
core::ParseLimits.new(max_batch_items: 3, max_input_bytes: 64 * 1024 * 1024, max_nodes: 1_000_000,
|
|
92
97
|
max_diagnostics: 1000))
|
|
93
|
-
project(operation, request, result)
|
|
98
|
+
project(operation, request, result, backend)
|
|
99
|
+
rescue UnsupportedCapabilityError => e
|
|
100
|
+
Ast::Merge::ProviderResult.unsupported(operation: operation, message: e.message)
|
|
94
101
|
rescue KeyError, ArgumentError, TypeError, RangeError => e
|
|
95
102
|
Ast::Merge::ProviderResult.invalid_request(operation: operation, message: e.message)
|
|
96
103
|
rescue RuntimeError => e
|
|
@@ -99,6 +106,19 @@ module Ast
|
|
|
99
106
|
end
|
|
100
107
|
|
|
101
108
|
def additional_fields = []
|
|
109
|
+
def parser_backends = [:rust_tslp]
|
|
110
|
+
def default_parser_backend = parser_backends.first
|
|
111
|
+
|
|
112
|
+
def parser_backend_available?(backend)
|
|
113
|
+
backend == 'rust_tslp' && self.class.available?
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def register_parser_backend(dialect, backend)
|
|
117
|
+
raise UnsupportedCapabilityError, "Unsupported parser backend #{backend}" unless backend == 'rust_tslp'
|
|
118
|
+
|
|
119
|
+
TreeHaver::Backends::RustTslp.register_language_parser(parser_language(dialect))
|
|
120
|
+
end
|
|
121
|
+
|
|
102
122
|
def default_dialect = self.class::DIALECTS.first
|
|
103
123
|
def parser_language(dialect) = dialect == 'json' ? 'json' : 'json5'
|
|
104
124
|
def owner_path(owner) = owner.fetch('path')
|
|
@@ -135,7 +155,7 @@ module Ast
|
|
|
135
155
|
values.to_h { |key, value| [key, JSON.parse(value)] }
|
|
136
156
|
end
|
|
137
157
|
|
|
138
|
-
def project(operation, request, result)
|
|
158
|
+
def project(operation, request, result, backend)
|
|
139
159
|
changes = result.changes.map do |change|
|
|
140
160
|
states = metadata(change.role_states)
|
|
141
161
|
{ id: change.id, path: change.path, subject_ref: change.subject_ref, change: change.classification.to_sym,
|
|
@@ -144,7 +164,8 @@ module Ast
|
|
|
144
164
|
end
|
|
145
165
|
diagnostics = result.diagnostics.map do |record|
|
|
146
166
|
diagnostic = record.canonical || record.migration
|
|
147
|
-
|
|
167
|
+
category = diagnostic.code == 'analysis.ambiguous_owner' ? :ambiguous_owner : diagnostic.category.to_sym
|
|
168
|
+
{ id: diagnostic.id, code: diagnostic.code, category: category,
|
|
148
169
|
severity: diagnostic.severity.to_sym, message: diagnostic.message, blocking: diagnostic.blocking, typed_record: record }
|
|
149
170
|
end
|
|
150
171
|
conflicts = result.conflicts.map do |record|
|
|
@@ -157,7 +178,7 @@ module Ast
|
|
|
157
178
|
payload = { output: result.output, conflicted_output: result.conflicted_output, typed_result: result }
|
|
158
179
|
if result.analysis
|
|
159
180
|
facts = metadata(result.analysis.extra)
|
|
160
|
-
payload[:analysis] = { backend:
|
|
181
|
+
payload[:analysis] = { backend: backend.to_sym, valid: true, facts: facts,
|
|
161
182
|
declarations: facts.fetch('owners').map do |owner|
|
|
162
183
|
{ path: owner_path(owner), signature: owner_path(owner), source_role: :source,
|
|
163
184
|
line_range: line_range(owner.fetch('span')), byte_range: owner.fetch('span').fetch('range') }
|
|
@@ -166,7 +187,7 @@ module Ast
|
|
|
166
187
|
payload[:diff] = { changes: changes } if result.diff
|
|
167
188
|
projected = Ast::Merge::ProviderResult.build(operation: operation, success: result.ok,
|
|
168
189
|
envelope: { provider: { provider_id: provider_id, family: family, dialect: request.fetch(:dialect, default_dialect),
|
|
169
|
-
backend:
|
|
190
|
+
backend: backend.to_sym, package: self.class::PACKAGE, package_version: package_version },
|
|
170
191
|
profile: { profile_id: :source_preserving, core_profile_id: result.profile.profile_id },
|
|
171
192
|
diagnostics: diagnostics, changes: changes, conflicts: conflicts,
|
|
172
193
|
render_report: metadata(result.render_report), verification: verification }, **payload)
|
data/lib/ast/merge/version.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Ast
|
|
|
5
5
|
# Version namespace for this gem.
|
|
6
6
|
module Version
|
|
7
7
|
# Current gem version.
|
|
8
|
-
VERSION = '7.1.
|
|
8
|
+
VERSION = '7.1.20'
|
|
9
9
|
end
|
|
10
10
|
# Current gem version exposed at the traditional constant location.
|
|
11
11
|
VERSION = Version::VERSION # Traditional Constant Location
|
data.tar.gz.sig
CHANGED
|
Binary file
|