ast-merge 7.1.16 → 7.1.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84b24864e7624bfe814e90f5ccc88c6abad814211071e67fbb4371d919f254c7
4
- data.tar.gz: f3768787dce27ca5ce20c1a9d1f5e86be5bc22ba7824f532707354bd01aa9bc7
3
+ metadata.gz: aa63539b7dfe068f6feabeae0336aed0cc708894a14ce7ff8ed5ea3f753d9d59
4
+ data.tar.gz: 26137ae64c03bdbfb2e4caf58ded26fc404622f6f01795aa91e4ed0af2027347
5
5
  SHA512:
6
- metadata.gz: 9a5195597db9da7216839ac505ddeb79b22ed54040d7f00645c702ecb093173cbba890faf80e85771e914db1a4baebdd02903bf468c006a1f4a5137de1028c3e
7
- data.tar.gz: d9252a87faacbdd537cc28471723f4ea3723f8ae4340337a63c7406ccc01fe903e1cab0cfe499c8415c71612185a7440ecc3ac6cdeeac98d78eaf4dfd5d8324b
6
+ metadata.gz: a886ccafc7691888e81efac752280909b62147f7bef8d18361776edff49173e6d8e9abc25532cbf774b187b5163359160a70d9caa238eeaa3a08f05f1613f67b
7
+ data.tar.gz: 08ef264ceda1d62236bf49ea7b2d6389647615fdd046f523779b745672ceb1545f6b0430ae7d12bd41883fd168f9d41b7a8fdf9817dffde71e9f998d0e76e8e6
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
- Compatible with MRI Ruby 4.0.0+, JRuby, and TruffleRuby.
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
- This test floor is configured by `ruby.test_minimum` in `.kettle-jem.yml` and
372
- may be higher than the gem's runtime compatibility floor when legacy Rubies are
373
- not practical for the current toolchain.
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, **options)
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
- leading_comments = infer_leading_comments(owner, claimed)
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, inline_comments, include_blank_lines: false),
80
- trailing_region: build_region(:trailing, trailing_comments),
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
- comment[:full_line] && !claimed.include?(comment.object_id) && comment[:line] < owner.start_line
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
- comment[:full_line] && !claimed.include?(comment.object_id) && comment[:line] > last_line
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
- before_owner = owners.reverse_each.find { |owner| owner_end_line(owner) == run[:start_line] - 1 }
62
- after_owner = owners.find { |owner| owner_start_line(owner) == run[:end_line] + 1 }
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.freeze
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: ProviderContract::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: [:rust_tslp],
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, 'rust_tslp'].include?(request[:backend]&.to_s) &&
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
- unless self.class.available?
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: 'structuredmerge-core is unavailable')
72
+ message: "Requested parser backend #{backend} is unavailable")
67
73
  end
68
74
 
69
- dialect = request.fetch(:dialect, default_dialect).to_s
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')
@@ -106,27 +126,36 @@ module Ast
106
126
  def policy(operation, _request)
107
127
  case operation
108
128
  when :analyze
109
- core::OperationPolicy.from_analyze(core::AnalyzePolicy.new(extra: {}))
129
+ core::OperationPolicyAnalyze.new(value: core::AnalyzePolicy.new(extra: {}))
110
130
  when :diff2
111
- core::OperationPolicy.from_diff2(core::DiffPolicy.new(comparison_profile: 'exact-source-owners',
112
- equivalence: ['exact-source'], extra: {}))
131
+ core::OperationPolicyDiff2.new(value: diff2_policy)
113
132
  when :merge2
114
- core::OperationPolicy.from_merge2(core::DirectionalMergePolicy.new(
115
- directional_merge: 'template-into-current', render_policy: 'source-preserving', extra: {}
116
- ))
133
+ core::OperationPolicyMerge2.new(value: merge2_policy)
117
134
  when :merge3
118
- core::OperationPolicy.from_merge3(core::ThreeWayMergePolicy.new(render_policy: 'source-preserving',
119
- fallback_policy: 'none', extra: {}))
135
+ core::OperationPolicyMerge3.new(value: merge3_policy)
120
136
  end
121
137
  end
122
138
 
139
+ def diff2_policy
140
+ core::DiffPolicy.new(comparison_profile: 'exact-source-owners', equivalence: ['exact-source'], extra: {})
141
+ end
142
+
143
+ def merge2_policy
144
+ core::DirectionalMergePolicy.new(directional_merge: 'template-into-current', render_policy: 'source-preserving',
145
+ extra: {})
146
+ end
147
+
148
+ def merge3_policy
149
+ core::ThreeWayMergePolicy.new(render_policy: 'source-preserving', fallback_policy: 'none', extra: {})
150
+ end
151
+
123
152
  # Only open metadata values are encoded by the generated binding; never
124
153
  # send or decode a whole-operation JSON string.
125
154
  def metadata(values)
126
155
  values.to_h { |key, value| [key, JSON.parse(value)] }
127
156
  end
128
157
 
129
- def project(operation, request, result)
158
+ def project(operation, request, result, backend)
130
159
  changes = result.changes.map do |change|
131
160
  states = metadata(change.role_states)
132
161
  { id: change.id, path: change.path, subject_ref: change.subject_ref, change: change.classification.to_sym,
@@ -135,7 +164,8 @@ module Ast
135
164
  end
136
165
  diagnostics = result.diagnostics.map do |record|
137
166
  diagnostic = record.canonical || record.migration
138
- { id: diagnostic.id, code: diagnostic.code, category: diagnostic.category.to_sym,
167
+ category = diagnostic.code == 'analysis.ambiguous_owner' ? :ambiguous_owner : diagnostic.category.to_sym
168
+ { id: diagnostic.id, code: diagnostic.code, category: category,
139
169
  severity: diagnostic.severity.to_sym, message: diagnostic.message, blocking: diagnostic.blocking, typed_record: record }
140
170
  end
141
171
  conflicts = result.conflicts.map do |record|
@@ -148,7 +178,7 @@ module Ast
148
178
  payload = { output: result.output, conflicted_output: result.conflicted_output, typed_result: result }
149
179
  if result.analysis
150
180
  facts = metadata(result.analysis.extra)
151
- payload[:analysis] = { backend: :rust_tslp, valid: true, facts: facts,
181
+ payload[:analysis] = { backend: backend.to_sym, valid: true, facts: facts,
152
182
  declarations: facts.fetch('owners').map do |owner|
153
183
  { path: owner_path(owner), signature: owner_path(owner), source_role: :source,
154
184
  line_range: line_range(owner.fetch('span')), byte_range: owner.fetch('span').fetch('range') }
@@ -157,7 +187,7 @@ module Ast
157
187
  payload[:diff] = { changes: changes } if result.diff
158
188
  projected = Ast::Merge::ProviderResult.build(operation: operation, success: result.ok,
159
189
  envelope: { provider: { provider_id: provider_id, family: family, dialect: request.fetch(:dialect, default_dialect),
160
- backend: :rust_tslp, package: self.class::PACKAGE, package_version: package_version },
190
+ backend: backend.to_sym, package: self.class::PACKAGE, package_version: package_version },
161
191
  profile: { profile_id: :source_preserving, core_profile_id: result.profile.profile_id },
162
192
  diagnostics: diagnostics, changes: changes, conflicts: conflicts,
163
193
  render_report: metadata(result.render_report), verification: verification }, **payload)
@@ -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.16'
8
+ VERSION = '7.1.19'
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