Module: Prism::Merge

Defined in:
lib/prism/merge.rb,
lib/prism/merge/comment.rb,
lib/prism/merge/version.rb,
lib/prism/merge/provider.rb,
lib/prism/merge/nocov_node.rb,
lib/prism/merge/freeze_node.rb,
lib/prism/merge/comment/line.rb,
lib/prism/merge/debug_logger.rb,
lib/prism/merge/merge_result.rb,
lib/prism/merge/node_wrapper.rb,
lib/prism/merge/smart_merger.rb,
lib/prism/merge/block_binding.rb,
lib/prism/merge/comment/block.rb,
lib/prism/merge/file_analysis.rb,
lib/prism/merge/nocov_wrapper.rb,
lib/prism/merge/comment/parser.rb,
lib/prism/merge/node_body_layout.rb,
lib/prism/merge/block_var_renamer.rb,
lib/prism/merge/source_line_lookup.rb,
lib/prism/merge/gemspec_var_renamer.rb,
lib/prism/merge/begin_node_structure.rb,
lib/prism/merge/comment/runtime_line.rb,
lib/prism/merge/method_match_refiner.rb,
lib/prism/merge/node_type_normalizer.rb,
lib/prism/merge/magic_comment_support.rb,
lib/prism/merge/node_emission_support.rb,
lib/prism/merge/partial_template_node.rb,
lib/prism/merge/recursive_merge_policy.rb,
lib/prism/merge/scaffold_chunk_remover.rb,
lib/prism/merge/top_level_merge_runner.rb,
lib/prism/merge/begin_node_plan_emitter.rb,
lib/prism/merge/nested_statement_walker.rb,
lib/prism/merge/partial_template_merger.rb,
lib/prism/merge/wrapper_comment_support.rb,
lib/prism/merge/begin_node_merge_planner.rb,
lib/prism/merge/block_directive_detector.rb,
lib/prism/merge/comment_only_file_merger.rb,
lib/prism/merge/ruby_doc_surface_analyzer.rb,
lib/prism/merge/recursive_node_body_merger.rb,
lib/prism/merge/begin_node_rescue_semantics.rb,
lib/prism/merge/begin_node_clause_body_merger.rb,
lib/prism/merge/begin_node_clause_body_support.rb,
lib/prism/merge/begin_node_clause_header_emitter.rb,
sig/prism/merge.rbs

Overview

This public facade keeps provider protocol and backend registration entrypoints together; implementation details live in autoloaded files. rubocop:disable Metrics/ModuleLength

Defined Under Namespace

Modules: Comment, DebugLogger, MagicCommentSupport, NestedStatementWalker, NodeTypeNormalizer, SourceLineLookup, Version Classes: BeginNodeClauseBodyMerger, BeginNodeClauseBodySupport, BeginNodeClauseHeaderEmitter, BeginNodeMergePlanner, BeginNodePlanEmitter, BeginNodeRescueSemantics, BeginNodeStructure, BlockBinding, BlockDirectiveDetector, BlockVarRenamer, CommentOnlyFileMerger, CorruptionDetectedError, DestinationParseError, Error, FileAnalysis, FreezeNode, GemspecVarRenamer, MergeResult, MethodMatchRefiner, MissingAnalyzedLineError, NoCovWrapper, NocovNode, NodeBodyLayout, NodeEmissionSupport, NodeWrapper, ParseError, PartialTemplateMerger, PartialTemplateNode, Provider, RecursiveMergePolicy, RecursiveNodeBodyMerger, RubyDocSurfaceAnalyzer, ScaffoldChunkRemover, SmartMerger, TemplateParseError, TopLevelMergeRunner, WrapperCommentSupport

Constant Summary collapse

PACKAGE_NAME =
'prism-merge'
BACKEND_REFERENCE =
TreeHaver::BackendReference.new(id: 'prism', family: 'native').freeze
BACKEND_REGISTRY =
Struct.new(:registered, :mutex).new(false, Mutex.new)
VERSION =

Current gem version exposed at the traditional constant location.

Returns:

  • (String)
Version::VERSION
NodeTypingNormalizer =

Alias for the shared normalizer module from ast-merge

Ast::Merge::NodeTyping::Normalizer

Class Method Summary collapse

Class Method Details

.analyze_ruby_document(source, parse_result) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/prism/merge.rb', line 491

def analyze_ruby_document(source, parse_result)
  normalized_source = prism_ruby_normalize_source(source)
  body = parse_result.value.statements&.body || []
  {
    kind: 'ruby',
    dialect: 'ruby',
    root_kind: 'document',
    source: normalized_source,
    owners: prism_ruby_analysis_owners(body),
    discovered_surfaces: prism_ruby_discovered_surfaces(normalized_source, body),
    method_shadowing: [],
    diagnostics: []
  }
end

.apply_edit_projection(request) ⇒ Object

This adapter validates, edits, reparses, and reports one projection atomically. rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/prism/merge.rb', line 593

def apply_edit_projection(request)
  source = request.fetch(:source)
  provider_id = request.fetch(:provider_id)
  backend_id = request.fetch(:backend_ref).fetch(:id)
  language = request.fetch(:language)
  operations = request.fetch(:operations)

  unless provider_id == BACKEND_REFERENCE.id && backend_id == BACKEND_REFERENCE.id
    return edit_projection_rejection(source, 'provider_id', 'provider_edit_projection_unsupported',
                                     "provider #{provider_id} does not support Prism edit projection")
  end
  unless language == 'ruby'
    return edit_projection_rejection(source, 'language', 'edit_projection_language_unsupported',
                                     "language #{language} is not supported by Prism edit projection")
  end
  unless operations.length == 1
    return edit_projection_rejection(source, 'operations', 'edit_projection_batch_unsupported',
                                     'Prism edit projection currently supports exactly one operation')
  end

  operation = operations.first
  unless %w[replace_node insert_child delete_node].include?(operation.fetch(:operation))
    return edit_projection_rejection(source, 'operations[0].operation', 'edit_projection_operation_unsupported',
                                     "Prism edit projection does not support #{operation.fetch(:operation)}")
  end

  normalized = parse_ruby_normalized(source, 'ruby')
  unless normalized[:ok]
    return edit_projection_rejection(source, 'source', 'edit_projection_parse_failed',
                                     normalized[:diagnostics].join('; '))
  end

  target = normalized[:nodes].find do |node|
    node.dig(:metadata, :prism, :node_path) == operation.fetch(:target_node_path)
  end
  unless target
    return edit_projection_rejection(source, 'operations[0].target_node_path', 'edit_projection_target_not_found',
                                     "Prism node path #{operation.fetch(:target_node_path)} was not found")
  end

  range = target.dig(:span, :range)
  output = if operation.fetch(:operation) == 'delete_node'
             delete_range = line_deletion_range(source, range)
             source.byteslice(0...delete_range[:start_byte]) + source.byteslice(delete_range[:end_byte]..)
           elsif operation.fetch(:operation) == 'insert_child'
             insertion_byte = class_body_insertion_byte(source, range)
             "#{source.byteslice(0...insertion_byte)}#{operation.fetch(:replacement_source)}\n#{source.byteslice(insertion_byte..)}"
           else
             source.byteslice(0...range[:start_byte]) +
               operation.fetch(:replacement_source) +
               source.byteslice(range[:end_byte]..)
           end
  reparsed = parse_ruby_normalized(output, 'ruby')
  unless reparsed[:ok]
    return edit_projection_rejection(source, 'operations[0].replacement_source', 'edit_projection_reparse_failed',
                                     reparsed[:diagnostics].join('; '))
  end

  TreeHaver.build_edit_projection_execution_result(
    output,
    [
      TreeHaver::AppliedEditProjectionOperation.new(
        operation: operation.fetch(:operation),
        target_node_id: operation.fetch(:target_node_id),
        correlation_key: 'metadata.prism.node_path',
        correlation_value: operation.fetch(:target_node_path)
      )
    ],
    []
  ).to_h
end

.available_ruby_backendsObject



105
106
107
# File 'lib/prism/merge.rb', line 105

def available_ruby_backends
  [BACKEND_REFERENCE]
end

.class_body_insertion_byte(source, range) ⇒ Object



1120
1121
1122
1123
# File 'lib/prism/merge.rb', line 1120

def class_body_insertion_byte(source, range)
  end_byte = range.fetch(:end_byte)
  source.rindex("\n", end_byte - 1)&.+(1) || end_byte
end

.comment_parent_id(comment, body) ⇒ Object



1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
# File 'lib/prism/merge.rb', line 1279

def comment_parent_id(comment, body)
  body.each_with_index do |node, index|
    next unless node.is_a?(::Prism::ClassNode)
    next unless comment.location.start_offset > node.location.start_offset &&
                comment.location.end_offset < node.location.end_offset

    return "prism:class:#{index}"
  end
  'prism:program:0'
end

.coverage_directive_comment?(comment_text) ⇒ Boolean

Returns:

  • (Boolean)


1268
1269
1270
# File 'lib/prism/merge.rb', line 1268

def coverage_directive_comment?(comment_text)
  Ruby::Merge::BlockDirectiveDetector.coverage_directive_line?(comment_text)
end

.edit_projection_rejection(source, path, code, message) ⇒ Object



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'lib/prism/merge.rb', line 1094

def edit_projection_rejection(source, path, code, message)
  TreeHaver.build_edit_projection_execution_result(
    source,
    [],
    [
      TreeHaver::ProviderDiagnostic.new(
        severity: 'error',
        category: 'unsupported_feature',
        code: code,
        message: message,
        path: path,
        blocking: true
      )
    ]
  ).to_h
end

.full_source_span(source) ⇒ Object



1316
1317
1318
1319
1320
1321
1322
1323
# File 'lib/prism/merge.rb', line 1316

def full_source_span(source)
  lines = source.split("\n", -1)
  TreeHaver::SourceSpan.new(
    range: TreeHaver::ByteRange.new(start_byte: 0, end_byte: source.bytesize),
    start_point: TreeHaver::SourcePoint.new(row: 0, column: 0),
    end_point: TreeHaver::SourcePoint.new(row: lines.length - 1, column: lines.last.bytesize)
  )
end

.line_deletion_range(source, range) ⇒ Object



1111
1112
1113
1114
1115
1116
1117
1118
# File 'lib/prism/merge.rb', line 1111

def line_deletion_range(source, range)
  start_byte = range.fetch(:start_byte)
  end_byte = range.fetch(:end_byte)
  line_start = source.rindex("\n", start_byte - 1)&.+(1) || 0
  next_newline = source.index("\n", end_byte)
  line_end = next_newline ? next_newline + 1 : end_byte
  { start_byte: line_start, end_byte: line_end }
end

.magic_comment_for(comment, magic_comments) ⇒ Object



1272
1273
1274
1275
1276
1277
# File 'lib/prism/merge.rb', line 1272

def magic_comment_for(comment, magic_comments)
  magic_comments.find do |magic_comment|
    comment.location.start_offset <= magic_comment.key_loc.start_offset &&
      magic_comment.key_loc.start_offset < comment.location.end_offset
  end
end

.match_ruby_owners(template, destination) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



666
667
668
# File 'lib/prism/merge.rb', line 666

def match_ruby_owners(template, destination)
  Ruby::Merge.match_ruby_owners(template, destination)
end

.merge_providerProvider

Returns:



97
98
99
# File 'lib/prism/merge.rb', line 97

def merge_provider
  @merge_provider ||= Provider.new
end

.merge_ruby(template_source, destination_source, dialect, backend: nil, preference: :destination, add_template_only_nodes: true, signature_generator: nil, merge_template_requires: false, template_only_placement: :after_anchor, **options) ⇒ Object



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/prism/merge.rb', line 670

def merge_ruby(
  template_source,
  destination_source,
  dialect,
  backend: nil,
  preference: :destination,
  add_template_only_nodes: true,
  signature_generator: nil,
  merge_template_requires: false,
  template_only_placement: :after_anchor,
  **options
)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end
  return unsupported_feature_result("Unsupported Ruby dialect #{dialect}.") unless dialect == 'ruby'

  merger = SmartMerger.new(
    template_source,
    destination_source,
    preference: preference,
    add_template_only_nodes: add_template_only_nodes,
    signature_generator: signature_generator,
    merge_template_requires: merge_template_requires,
    template_only_placement: template_only_placement,
    **options
  )
  {
    ok: true,
    diagnostics: [],
    output: merger.merge.to_s,
    policies: Ruby::Merge.ruby_feature_profile.fetch(:supported_policies)
  }
rescue Prism::Merge::ParseError => e
  {
    ok: false,
    diagnostics: [
      {
        severity: 'error',
        category: e.is_a?(Prism::Merge::DestinationParseError) ? 'destination_parse_error' : 'parse_error',
        message: e.message
      }
    ],
    policies: []
  }
end

.merge_ruby_with_reviewed_nested_outputs(template_source, destination_source, dialect, review_state, applied_children, backend: nil) ⇒ Object

The reviewed merge boundary must retain all protocol roles for replay. rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists



797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'lib/prism/merge.rb', line 797

def merge_ruby_with_reviewed_nested_outputs(template_source, destination_source, dialect, review_state,
                                            applied_children, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  Ast::Merge.execute_reviewed_nested_merge(
    review_state,
    'ruby',
    applied_children,
    merge_parent: -> { merge_ruby(template_source, destination_source, dialect, backend: backend) },
    discover_operations: lambda { |merged_output|
      analysis = parse_ruby(merged_output, dialect, backend: backend)
      next({ ok: false, diagnostics: analysis[:diagnostics] || [] }) unless analysis[:ok]

      {
        ok: true,
        diagnostics: [],
        operations: ruby_delegated_child_operations(analysis[:analysis])
      }
    },
    apply_resolved_outputs: lambda { |merged_output, operations, apply_plan, resolved_children|
      Ruby::Merge.apply_ruby_delegated_child_outputs(
        merged_output,
        operations,
        apply_plan,
        resolved_children
      )
    }
  )
end

.merge_ruby_with_reviewed_nested_outputs_from_replay_bundle(template_source, destination_source, dialect, replay_bundle, backend: nil) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists



831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
# File 'lib/prism/merge.rb', line 831

def merge_ruby_with_reviewed_nested_outputs_from_replay_bundle(template_source, destination_source, dialect,
                                                               replay_bundle, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  execution = Array(replay_bundle[:reviewed_nested_executions]).find { |entry| entry[:family] == 'ruby' }
  unless execution
    return { ok: false,
             diagnostics: [{ severity: 'error', category: 'configuration_error', message: 'review replay bundle does not include a reviewed nested execution for ruby.' }], policies: [] }
  end

  merge_ruby_with_reviewed_nested_outputs(
    template_source,
    destination_source,
    dialect,
    execution[:review_state],
    execution[:applied_children],
    backend: backend
  )
end

.merge_ruby_with_reviewed_nested_outputs_from_replay_bundle_envelope(template_source, destination_source, dialect, envelope, backend: nil) ⇒ Object



854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'lib/prism/merge.rb', line 854

def merge_ruby_with_reviewed_nested_outputs_from_replay_bundle_envelope(template_source, destination_source,
                                                                        dialect, envelope, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  replay_bundle, import_error = Ast::Merge.import_review_replay_bundle_envelope(envelope)
  if import_error
    return { ok: false,
             diagnostics: [{ severity: 'error', category: import_error[:category], message: import_error[:message] }], policies: [] }
  end

  merge_ruby_with_reviewed_nested_outputs_from_replay_bundle(
    template_source,
    destination_source,
    dialect,
    replay_bundle,
    backend: backend
  )
end

.merge_ruby_with_reviewed_nested_outputs_from_review_state(template_source, destination_source, dialect, review_state, backend: nil) ⇒ Object



876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/prism/merge.rb', line 876

def merge_ruby_with_reviewed_nested_outputs_from_review_state(template_source, destination_source, dialect,
                                                              review_state, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  execution = Array(review_state[:reviewed_nested_executions]).find { |entry| entry[:family] == 'ruby' }
  unless execution
    return { ok: false,
             diagnostics: [{ severity: 'error', category: 'configuration_error', message: 'review state does not include a reviewed nested execution for ruby.' }], policies: [] }
  end

  merge_ruby_with_reviewed_nested_outputs(
    template_source,
    destination_source,
    dialect,
    execution[:review_state],
    execution[:applied_children],
    backend: backend
  )
end

.merge_ruby_with_reviewed_nested_outputs_from_review_state_envelope(template_source, destination_source, dialect, envelope, backend: nil) ⇒ Object



899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
# File 'lib/prism/merge.rb', line 899

def merge_ruby_with_reviewed_nested_outputs_from_review_state_envelope(template_source, destination_source,
                                                                       dialect, envelope, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  review_state, import_error = Ast::Merge.import_conformance_manifest_review_state_envelope(envelope)
  if import_error
    return { ok: false,
             diagnostics: [{ severity: 'error', category: import_error[:category], message: import_error[:message] }], policies: [] }
  end

  merge_ruby_with_reviewed_nested_outputs_from_review_state(
    template_source,
    destination_source,
    dialect,
    review_state,
    backend: backend
  )
end

.normalize_ruby_require_aliases(require_aliases) ⇒ Object

Alias normalization intentionally handles the supported input shapes inline. rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/prism/merge.rb', line 750

def normalize_ruby_require_aliases(require_aliases)
  Array(require_aliases).each_with_object({}) do |entry, aliases|
    case entry
    when Hash
      from = entry[:from] || entry['from']
      to = entry[:to] || entry['to']
    when Array
      from, to = entry
    else
      next
    end
    from = from.to_s.strip
    to = to.to_s.strip
    next if from.empty? || to.empty?

    canonical = [from, to].min
    aliases[from] = canonical
    aliases[to] = canonical
  end
end

.parse_ruby(source, dialect, backend: nil) ⇒ Object

Keep parser validation and diagnostics in one boundary method. rubocop:disable Metrics/AbcSize, Metrics/MethodLength



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/prism/merge.rb', line 462

def parse_ruby(source, dialect, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Ruby dialect #{dialect}.") unless dialect == 'ruby'
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  result = TreeHaver.with_backend(BACKEND_REFERENCE.id) do
    TreeHaver.parser_for(:ruby, backend_type: :prism).parse(source).parse_result
  end
  unless result.success?
    return {
      ok: false,
      diagnostics: result.errors.map do |error|
        { severity: 'error', category: 'parse_error', message: error.message }
      end,
      policies: []
    }
  end

  {
    ok: true,
    diagnostics: [],
    analysis: analyze_ruby_document(source, result),
    policies: []
  }
end

.parse_ruby_normalized(source, dialect = 'ruby', backend: nil) ⇒ Object

Normalization builds the complete TreeHaver contract in one pass. rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/prism/merge.rb', line 508

def parse_ruby_normalized(source, dialect = 'ruby', backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Ruby dialect #{dialect}.") unless dialect == 'ruby'
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  result = TreeHaver.with_backend(BACKEND_REFERENCE.id) do
    TreeHaver.parser_for(:ruby, backend_type: :prism).parse(source).parse_result
  end
  unless result.success?
    return TreeHaver::NormalizedParseResult.new(
      ok: false,
      backend_capability: ruby_normalized_backend_capability(dialect),
      root_id: nil,
      nodes: [],
      parse_error_tolerance: ruby_prism_parse_error_tolerance,
      source_fragments_available: false,
      diagnostics: result.errors.map(&:message),
      metadata: 
    ).to_h
  end

  root_node = result.value
  body = root_node.statements&.body || []
  method_nodes = body.each_with_index.flat_map do |node, class_index|
    next [] unless node.is_a?(::Prism::ClassNode)

    Array(node.body&.body).each_with_index.filter_map do |child, method_index|
      next unless child.is_a?(::Prism::DefNode)

      prism_method_node(source, child, class_index, method_index)
    end
  end
  comment_nodes = prism_comment_nodes(source, result.comments, result.magic_comments, body)
  class_nodes = body.each_with_index.filter_map do |node, index|
    next unless node.is_a?(::Prism::ClassNode)

    child_ids = comment_nodes.filter_map { |comment| comment.id if comment.parent_id == "prism:class:#{index}" }
    child_ids.concat(method_nodes.filter_map { |method| method.id if method.parent_id == "prism:class:#{index}" })
    prism_class_node(source, node, index, child_ids: child_ids)
  end
  top_comment_nodes = comment_nodes.filter { |comment| comment.parent_id == 'prism:program:0' }

  root = TreeHaver::NormalizedTreeNode.new(
    id: 'prism:program:0',
    kind: 'program',
    role: 'structural',
    parent_id: nil,
    child_ids: top_comment_nodes.map(&:id) + class_nodes.map(&:id),
    span: full_source_span(source),
    field_name: nil,
    named: true,
    anonymous: false,
    has_source_text: true,
    source_fragment: source,
    backend_kind: root_node.class.name,
    semantic_roles: ['compilation_unit'],
    backend_roles: ['prism.ProgramNode'],
    unsupported_features: [],
    metadata: {
      prism: {
        node_path: 'program',
        native_tree_visibility: 'provider_internal'
      }
    }
  )

  TreeHaver::NormalizedParseResult.new(
    ok: true,
    backend_capability: ruby_normalized_backend_capability(dialect),
    root_id: root.id,
    nodes: [root] + top_comment_nodes + class_nodes + comment_nodes.reject do |comment|
      comment.parent_id == 'prism:program:0'
    end + method_nodes,
    parse_error_tolerance: ruby_prism_parse_error_tolerance,
    source_fragments_available: true,
    diagnostics: [],
    metadata: 
  ).to_h
end

.prism_class_node(source, node, index, child_ids:) ⇒ Object



1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
# File 'lib/prism/merge.rb', line 1166

def prism_class_node(source, node, index, child_ids:)
  TreeHaver::NormalizedTreeNode.new(
    id: "prism:class:#{index}",
    kind: 'class_declaration',
    role: 'structural',
    parent_id: 'prism:program:0',
    child_ids: child_ids,
    span: source_span_for_location(node.location),
    field_name: 'declaration',
    named: true,
    anonymous: false,
    has_source_text: true,
    source_fragment: source.byteslice(node.location.start_offset...node.location.end_offset),
    backend_kind: node.class.name,
    semantic_roles: %w[declaration class named_symbol],
    backend_roles: ['prism.ClassNode'],
    unsupported_features: [],
    metadata: {
      prism: {
        node_path: "statements.body[#{index}]",
        raw_identifier: node.name.to_s
      }
    }
  )
end

.prism_comment_directive(comment_text, magic_comment) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/prism/merge.rb', line 1238

def prism_comment_directive(comment_text, magic_comment)
  if comment_text.strip.match?(/\A#\s*smorg:freeze\b/)
    {
      kind: 'freeze_directive',
      directive_kind: 'freeze',
      semantic_roles: %w[comment directive freeze]
    }
  elsif magic_comment
    {
      kind: 'magic_comment',
      directive_kind: 'magic_comment',
      semantic_roles: %w[comment directive magic_comment],
      magic_key: magic_comment.key,
      magic_value: magic_comment.value
    }
  elsif coverage_directive_comment?(comment_text)
    {
      kind: 'coverage_directive',
      directive_kind: 'coverage',
      semantic_roles: %w[comment directive coverage]
    }
  else
    {
      kind: 'comment',
      directive_kind: 'comment',
      semantic_roles: ['comment']
    }
  end
end

.prism_comment_node(source, comment, index, magic_comment, parent_id:) ⇒ Object

Comment nodes retain backend metadata in a single normalized schema value. rubocop:disable Metrics/AbcSize, Metrics/MethodLength



1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
# File 'lib/prism/merge.rb', line 1206

def prism_comment_node(source, comment, index, magic_comment, parent_id:)
  directive = prism_comment_directive(
    source.byteslice(comment.location.start_offset...comment.location.end_offset), magic_comment
  )
  TreeHaver::NormalizedTreeNode.new(
    id: "prism:comment:#{index}",
    kind: directive.fetch(:kind),
    role: 'comment',
    parent_id: parent_id,
    child_ids: [],
    span: source_span_for_location(comment.location),
    field_name: 'comment',
    named: false,
    anonymous: false,
    has_source_text: true,
    source_fragment: source.byteslice(comment.location.start_offset...comment.location.end_offset),
    backend_kind: comment.class.name,
    semantic_roles: directive.fetch(:semantic_roles),
    backend_roles: ['prism.Comment'],
    unsupported_features: [],
    metadata: {
      prism: {
        node_path: "comments[#{index}]",
        directive_kind: directive.fetch(:directive_kind),
        magic_key: directive[:magic_key],
        magic_value: directive[:magic_value]
      }.compact
    }
  )
end

.prism_comment_nodes(source, comments, magic_comments, body) ⇒ Object



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/prism/merge.rb', line 1192

def prism_comment_nodes(source, comments, magic_comments, body)
  comments.each_with_index.map do |comment, index|
    prism_comment_node(
      source,
      comment,
      index,
      magic_comment_for(comment, magic_comments),
      parent_id: comment_parent_id(comment, body)
    )
  end
end

.prism_method_node(source, node, class_index, method_index) ⇒ Object



1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
# File 'lib/prism/merge.rb', line 1290

def prism_method_node(source, node, class_index, method_index)
  TreeHaver::NormalizedTreeNode.new(
    id: "prism:def:#{method_index}",
    kind: 'method_declaration',
    role: 'structural',
    parent_id: "prism:class:#{class_index}",
    child_ids: [],
    span: source_span_for_location(node.location),
    field_name: 'body',
    named: true,
    anonymous: false,
    has_source_text: true,
    source_fragment: source.byteslice(node.location.start_offset...node.location.end_offset),
    backend_kind: node.class.name,
    semantic_roles: %w[declaration method named_symbol],
    backend_roles: ['prism.DefNode'],
    unsupported_features: [],
    metadata: {
      prism: {
        node_path: "statements.body[#{class_index}].body.body[#{method_index}]",
        raw_identifier: node.name.to_s
      }
    }
  )
end

.prism_normalized_metadataObject



1157
1158
1159
1160
1161
1162
1163
1164
# File 'lib/prism/merge.rb', line 1157

def 
  {
    prism: {
      native_tree_retained: 'true',
      native_tree_visibility: 'provider_internal'
    }
  }
end

.prism_ruby_analysis_owners(body) ⇒ Object



933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
# File 'lib/prism/merge.rb', line 933

def prism_ruby_analysis_owners(body)
  require_index = 0
  body.filter_map do |node|
    if (require_path = prism_ruby_require_path(node))
      owner = {
        path: "/requires/#{require_index}",
        owner_kind: 'require',
        match_key: require_path
      }
      require_index += 1
      next owner
    end

    declaration_name = prism_ruby_declaration_name(node)
    next unless declaration_name

    {
      path: "/declarations/#{declaration_name}",
      owner_kind: 'declaration',
      match_key: declaration_name
    }
  end.sort_by { |owner| owner[:path] }
end

.prism_ruby_comment_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


1090
1091
1092
# File 'lib/prism/merge.rb', line 1090

def prism_ruby_comment_line?(line)
  line.lstrip.start_with?('#')
end

.prism_ruby_comment_prefix(raw) ⇒ Object



1074
1075
1076
# File 'lib/prism/merge.rb', line 1074

def prism_ruby_comment_prefix(raw)
  Ruby::Merge::DocCommentSupport.comment_prefix_for(raw)
end

.prism_ruby_declaration_name(node) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



1047
1048
1049
1050
1051
1052
1053
1054
# File 'lib/prism/merge.rb', line 1047

def prism_ruby_declaration_name(node)
  case node
  when ::Prism::ClassNode, ::Prism::ModuleNode
    node.constant_path.slice
  when ::Prism::DefNode
    node.name.to_s
  end
end

.prism_ruby_declared_example_language(content) ⇒ Object



1082
1083
1084
# File 'lib/prism/merge.rb', line 1082

def prism_ruby_declared_example_language(content)
  Ruby::Merge::DocCommentSupport.declared_example_language_for_tag(content)
end

.prism_ruby_discovered_surfaces(source, body) ⇒ Object

Surface discovery intentionally keeps line ownership and comment state together. rubocop:disable Metrics/AbcSize, Metrics/MethodLength



959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
# File 'lib/prism/merge.rb', line 959

def prism_ruby_discovered_surfaces(source, body)
   = body.filter_map do |node|
    name = prism_ruby_declaration_name(node)
    next unless name

    [node.location.start_line, name]
  end.to_h
  surfaces = []
  pending_comments = []

  source.lines.each_with_index do |line, index|
    line_number = index + 1
    if prism_ruby_comment_line?(line)
      pending_comments << { line: line_number, raw: line.chomp }
      next
    end

    owner_name = [line_number]
    if owner_name
      owner_surfaces = prism_ruby_surfaces_for_owner(owner_name, pending_comments)
      surfaces.concat(owner_surfaces)
      pending_comments = []
      next
    end

    pending_comments = [] unless line.strip.empty?
  end

  surfaces
end

.prism_ruby_doc_comment_content?(raw) ⇒ Boolean

Returns:

  • (Boolean)


1066
1067
1068
# File 'lib/prism/merge.rb', line 1066

def prism_ruby_doc_comment_content?(raw)
  Ruby::Merge::DocCommentSupport.doc_comment_content?(raw)
end

.prism_ruby_example_surfaces(surface) ⇒ Object

Example surfaces preserve the complete delegated-child metadata contract. rubocop:disable Metrics/AbcSize, Metrics/MethodLength



1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
# File 'lib/prism/merge.rb', line 1021

def prism_ruby_example_surfaces(surface)
  entries = Array(surface.dig(:metadata, :entries))
  Ruby::Merge::DocCommentSupport.example_blocks(entries).map do |block|
    body_entries = block.fetch(:body_entries)
    declared_language = block.fetch(:declared_language) || 'ruby'
    Ast::Merge.discovered_surface(
      surface_kind: 'yard_example_block',
      declared_language: declared_language,
      effective_language: declared_language,
      address: "#{surface.fetch(:address)} > yard_example[#{block.fetch(:tag_index)}]",
      parent_address: surface.fetch(:address),
      owner: Ast::Merge.surface_owner_ref(kind: 'owned_region', address: surface.fetch(:address)),
      span: Ast::Merge.surface_span(start_line: body_entries.first.fetch(:line),
                                    end_line: body_entries.last.fetch(:line)),
      reconstruction_strategy: 'rewrite_with_prefix_preservation',
      metadata: {
        tag_kind: 'example',
        tag_index: block.fetch(:tag_index),
        tag_text: block.fetch(:tag_text),
        comment_prefix: surface.dig(:metadata, :comment_prefix)
      }
    )
  end
end

.prism_ruby_next_yard_tag_index(lines, start_index) ⇒ Object



1078
1079
1080
# File 'lib/prism/merge.rb', line 1078

def prism_ruby_next_yard_tag_index(lines, start_index)
  Ruby::Merge::DocCommentSupport.next_tag_index(lines, start_index)
end

.prism_ruby_normalize_comment_content(raw) ⇒ Object



1070
1071
1072
# File 'lib/prism/merge.rb', line 1070

def prism_ruby_normalize_comment_content(raw)
  Ruby::Merge::DocCommentSupport.normalize_comment_content(raw)
end

.prism_ruby_normalize_source(source) ⇒ Object



1086
1087
1088
# File 'lib/prism/merge.rb', line 1086

def prism_ruby_normalize_source(source)
  source.to_s.gsub("\r\n", "\n").gsub("\r", "\n")
end

.prism_ruby_require_path(node) ⇒ Object



1056
1057
1058
1059
1060
1061
1062
1063
1064
# File 'lib/prism/merge.rb', line 1056

def prism_ruby_require_path(node)
  return unless node.is_a?(::Prism::CallNode)
  return unless %i[require require_relative].include?(node.name)

  argument = node.arguments&.arguments&.first
  return unless argument.is_a?(::Prism::StringNode)

  argument.unescaped
end

.prism_ruby_surfaces_for_owner(owner_name, comment_entries) ⇒ Object

A surface record is assembled as one schema-shaped value. rubocop:disable Metrics/AbcSize, Metrics/MethodLength



993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/prism/merge.rb', line 993

def prism_ruby_surfaces_for_owner(owner_name, comment_entries)
  filtered_entries = comment_entries.filter { |entry| prism_ruby_doc_comment_content?(entry.fetch(:raw)) }
  return [] if filtered_entries.empty?

  start_line = filtered_entries.first.fetch(:line)
  end_line = filtered_entries.last.fetch(:line)
  doc_surface = Ast::Merge.discovered_surface(
    surface_kind: 'ruby_doc_comment',
    declared_language: 'yard',
    effective_language: 'yard',
    address: "document[0] > ruby_doc_comment[#{owner_name}]",
    parent_address: 'document[0]',
    owner: Ast::Merge.surface_owner_ref(kind: 'owned_region', address: "/declarations/#{owner_name}"),
    span: Ast::Merge.surface_span(start_line: start_line, end_line: end_line),
    reconstruction_strategy: 'rewrite_with_prefix_preservation',
    metadata: {
      owner_signature: owner_name,
      comment_prefix: prism_ruby_comment_prefix(filtered_entries.first.fetch(:raw)),
      entries: filtered_entries.map { |entry| { line: entry.fetch(:line), raw: entry.fetch(:raw) } }
    }
  )

  [doc_surface] + prism_ruby_example_surfaces(doc_surface)
end

.register_backend!Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/prism/merge.rb', line 78

def register_backend!
  BACKEND_REGISTRY.mutex.synchronize do
    return if BACKEND_REGISTRY.registered

    TreeHaver.register_language(
      :ruby,
      backend_module: TreeHaver::Backends::Prism,
      backend_type: :prism,
      gem_name: 'prism'
    )

    BACKEND_REGISTRY.registered = true
  end
end

.register_provider!(replace: false) ⇒ Ast::Merge::_MergeProvider

Parameters:

  • replace: (Boolean) (defaults to: false)

Returns:

  • (Ast::Merge::_MergeProvider)


101
102
103
# File 'lib/prism/merge.rb', line 101

def register_provider!(replace: false)
  Ast::Merge.register_provider(merge_provider, replace: replace)
end

.ruby_backend_feature_profile(backend: nil) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/prism/merge.rb', line 109

def ruby_backend_feature_profile(backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  unless requested == BACKEND_REFERENCE.id
    return unsupported_feature_result("Unsupported Ruby backend #{requested}.")
  end

  ruby_feature_profile.merge(backend: BACKEND_REFERENCE.id, backend_ref: BACKEND_REFERENCE.to_h)
end

.ruby_delegated_child_operations(analysis, parent_operation_id: 'ruby-document-0') ⇒ Object



925
926
927
# File 'lib/prism/merge.rb', line 925

def ruby_delegated_child_operations(analysis, parent_operation_id: 'ruby-document-0')
  Ruby::Merge.ruby_delegated_child_operations(analysis, parent_operation_id: parent_operation_id)
end

.ruby_discovered_surfaces(analysis) ⇒ Object



921
922
923
# File 'lib/prism/merge.rb', line 921

def ruby_discovered_surfaces(analysis)
  Ruby::Merge.ruby_discovered_surfaces(analysis)
end

.ruby_dsl_call_node(node) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength



772
773
774
775
776
777
778
779
780
781
# File 'lib/prism/merge.rb', line 772

def ruby_dsl_call_node(node)
  return node if node.is_a?(::Prism::CallNode)

  if node.is_a?(::Prism::IfNode) || node.is_a?(::Prism::UnlessNode)
    body = node.statements&.body
    return body.first if body&.length == 1 && body.first.is_a?(::Prism::CallNode)
  end

  nil
end

.ruby_dsl_first_argument(call) ⇒ Object



783
784
785
786
787
788
789
790
791
792
793
# File 'lib/prism/merge.rb', line 783

def ruby_dsl_first_argument(call)
  argument = call.arguments&.arguments&.first
  case argument
  when ::Prism::StringNode
    argument.unescaped
  when ::Prism::SymbolNode
    argument.unescaped.to_sym
  else
    argument&.slice
  end
end

.ruby_dsl_signature_for(node, require_aliases: nil) ⇒ Object



731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/prism/merge.rb', line 731

def ruby_dsl_signature_for(node, require_aliases: nil)
  call = ruby_dsl_call_node(node)
  return unless call

  case call.name
  when :source, :gemspec
    [:ruby_dsl_singleton, call.name]
  when :require
    first_argument = ruby_dsl_first_argument(call)
    [:call, call.name, (require_aliases || {}).fetch(first_argument, first_argument)]
  when :git_source, :gem, :eval_gemfile, :platform, :group, :task
    [:ruby_dsl_call, call.name, ruby_dsl_first_argument(call)]
  when :desc
    [:ruby_dsl_desc, call.slice]
  end
end

.ruby_dsl_signature_generator(require_aliases: nil) ⇒ Object



718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/prism/merge.rb', line 718

def ruby_dsl_signature_generator(require_aliases: nil)
  normalized_require_aliases = normalize_ruby_require_aliases(require_aliases)
  if normalized_require_aliases.empty?
    return @ruby_dsl_signature_generator ||= lambda do |node|
      ruby_dsl_signature_for(node) || node
    end
  end

  lambda do |node|
    ruby_dsl_signature_for(node, require_aliases: normalized_require_aliases) || node
  end
end

.ruby_feature_profileObject



93
94
95
# File 'lib/prism/merge.rb', line 93

def ruby_feature_profile
  Ruby::Merge.ruby_feature_profile
end

.ruby_normalized_backend_capability(dialect) ⇒ Object



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'lib/prism/merge.rb', line 1125

def ruby_normalized_backend_capability(dialect)
  TreeHaver::BackendCapability.new(
    backend_ref: BACKEND_REFERENCE,
    language: 'ruby',
    parser_identity: TreeHaver::ParserIdentity.new(
      name: 'prism',
      version: ::Prism::VERSION,
      implementation: 'ruby'
    ),
    language_version: TreeHaver::LanguageVersion.new(version: 'ruby', dialect: dialect),
    parse_error_behavior: 'diagnostic_without_tree',
    source_span_support: 'byte_range_and_points',
    source_fragment_support: 'source_slice',
    render_strategies: %w[source_fragment_reuse full_file_fallback],
    semantic_role_support: 'backend_specific_with_portable_mapping',
    normalized_tree_support: true,
    native_node_access: true,
    diagnostics: []
  )
end

.ruby_plan_context(backend: nil) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/prism/merge.rb', line 118

def ruby_plan_context(backend: nil)
  profile = ruby_backend_feature_profile(backend: backend)
  return profile if profile[:ok] == false

  {
    family_profile: ruby_feature_profile,
    feature_profile: {
      backend: profile[:backend],
      supports_dialects: true,
      supported_policies: profile[:supported_policies]
    }
  }
end

.ruby_prism_parse_error_toleranceObject



1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
# File 'lib/prism/merge.rb', line 1146

def ruby_prism_parse_error_tolerance
  TreeHaver::ParseErrorTolerance.new(
    backend_ref: BACKEND_REFERENCE,
    language: 'ruby',
    behavior: 'diagnostic_without_tree',
    tolerates_errors: false,
    error_nodes: [],
    diagnostics: []
  )
end

.ruby_structured_edit_application_projectionObject



243
244
245
246
247
248
249
250
251
252
253
# File 'lib/prism/merge.rb', line 243

def ruby_structured_edit_application_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_application: Ast::Merge.structured_edit_application(
      request: ruby_structured_edit_request_projection[:structured_edit_request],
      result: ruby_structured_edit_result_projection[:structured_edit_result],
      metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
    )
  }
end

.ruby_structured_edit_batch_report_projectionObject

This projection mirrors the nested public schema intentionally. rubocop:disable Metrics/AbcSize, Metrics/MethodLength



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/prism/merge.rb', line 317

def ruby_structured_edit_batch_report_projection
  content = "class App\n  # managed snippet\n  old_call\n\n  anchor_call\n\n  # obsolete snippet\n  obsolete_call\nend\n"
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_batch_report: Ast::Merge.structured_edit_batch_report(
      reports: [
        Ast::Merge.structured_edit_execution_report(
          application: Ast::Merge.structured_edit_application(
            request: Ast::Merge.structured_edit_request(
              operation_kind: 'replace',
              content: content,
              source_label: 'source',
              target_selector: 'managed_snippet',
              target_selector_family: 'comment_anchor',
              payload_text: "new_call\n",
              metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: 'replace',
              updated_content: "class App\n  # managed snippet\n  new_call\n\n  anchor_call\n\n  # obsolete snippet\n  obsolete_call\nend\n",
              changed: true,
              captured_text: "old_call\n",
              match_count: 1,
              operation_profile: Ast::Merge.structured_edit_operation_profile(
                operation_kind: 'replace',
                operation_family: 'rewrite',
                known_operation_kind: true,
                source_requirement: 'required',
                destination_requirement: 'none',
                replacement_source: 'explicit_text',
                captures_source_text: true,
                supports_if_missing: false,
                metadata: { source: 'legacy_crispr_reference' }
              ),
              metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
          ),
          provider_family: 'ruby',
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: 'legacy_crispr_reference' }
        ),
        Ast::Merge.structured_edit_execution_report(
          application: Ast::Merge.structured_edit_application(
            request: Ast::Merge.structured_edit_request(
              operation_kind: 'insert',
              content: content,
              source_label: 'source',
              destination_selector: 'after_anchor_call',
              destination_selector_family: 'gap_preserving_statement',
              payload_text: "inserted_call\n",
              if_missing: 'append',
              metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: 'insert',
              updated_content: "class App\n  # managed snippet\n  old_call\n\n  anchor_call\n  inserted_call\n\n  # obsolete snippet\n  obsolete_call\nend\n",
              changed: true,
              operation_profile: Ast::Merge.structured_edit_operation_profile(
                operation_kind: 'insert',
                operation_family: 'insertion',
                known_operation_kind: true,
                source_requirement: 'none',
                destination_requirement: 'optional',
                replacement_source: 'explicit_text',
                captures_source_text: false,
                supports_if_missing: true,
                metadata: { source: 'legacy_crispr_reference' }
              ),
              destination_profile: Ast::Merge.structured_edit_destination_profile(
                resolution_kind: 'selector',
                resolution_source: 'destination_selector',
                anchor_boundary: 'after',
                resolution_family: 'anchored',
                resolution_source_family: 'selector',
                anchor_boundary_family: 'gap_preserving_statement',
                known_resolution_kind: true,
                known_resolution_source: true,
                known_anchor_boundary: true,
                used_if_missing: false,
                metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
              ),
              metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
          ),
          provider_family: 'ruby',
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: 'legacy_crispr_reference' }
        ),
        Ast::Merge.structured_edit_execution_report(
          application: Ast::Merge.structured_edit_application(
            request: Ast::Merge.structured_edit_request(
              operation_kind: 'delete',
              content: content,
              source_label: 'source',
              target_selector: 'obsolete_snippet',
              target_selector_family: 'comment_anchor',
              metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: 'delete',
              updated_content: "class App\n  # managed snippet\n  old_call\n\n  anchor_call\nend\n",
              changed: true,
              captured_text: "obsolete_call\n",
              match_count: 1,
              operation_profile: Ast::Merge.structured_edit_operation_profile(
                operation_kind: 'delete',
                operation_family: 'removal',
                known_operation_kind: true,
                source_requirement: 'required',
                destination_requirement: 'none',
                replacement_source: 'none',
                captures_source_text: true,
                supports_if_missing: false,
                metadata: { source: 'legacy_crispr_reference' }
              ),
              metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
          ),
          provider_family: 'ruby',
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: 'legacy_crispr_reference' }
        )
      ],
      diagnostics: [
        {
          severity: 'info',
          category: 'assumed_default',
          message: 'ruby batch preserved request ordering.'
        }
      ],
      metadata: { batch_label: 'ruby_prism_triad', source: 'legacy_crispr_reference' }
    )
  }
end

.ruby_structured_edit_batch_request_projectionObject



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/prism/merge.rb', line 275

def ruby_structured_edit_batch_request_projection
  content = "class App\n  # managed snippet\n  old_call\n\n  anchor_call\n\n  # obsolete snippet\n  obsolete_call\nend\n"
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_batch_request: Ast::Merge.structured_edit_batch_request(
      requests: [
        Ast::Merge.structured_edit_request(
          operation_kind: 'replace',
          content: content,
          source_label: 'source',
          target_selector: 'managed_snippet',
          target_selector_family: 'comment_anchor',
          payload_text: "new_call\n",
          metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
        ),
        Ast::Merge.structured_edit_request(
          operation_kind: 'insert',
          content: content,
          source_label: 'source',
          destination_selector: 'after_anchor_call',
          destination_selector_family: 'gap_preserving_statement',
          payload_text: "inserted_call\n",
          if_missing: 'append',
          metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
        ),
        Ast::Merge.structured_edit_request(
          operation_kind: 'delete',
          content: content,
          source_label: 'source',
          target_selector: 'obsolete_snippet',
          target_selector_family: 'comment_anchor',
          metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
        )
      ],
      metadata: { batch_label: 'ruby_prism_triad', source: 'legacy_crispr_reference' }
    )
  }
end

.ruby_structured_edit_execution_report_projectionObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/prism/merge.rb', line 255

def ruby_structured_edit_execution_report_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_execution_report: Ast::Merge.structured_edit_execution_report(
      application: ruby_structured_edit_application_projection[:structured_edit_application],
      provider_family: 'ruby',
      provider_backend: BACKEND_REFERENCE.id,
      diagnostics: [
        {
          severity: 'warning',
          category: 'assumed_default',
          message: 'using managed snippet fallback selection.'
        }
      ],
      metadata: { source: 'legacy_crispr_reference' }
    )
  }
end

.ruby_structured_edit_provider_profileObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/prism/merge.rb', line 132

def ruby_structured_edit_provider_profile
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_profile: {
      family: 'ruby',
      structure_profile: Ast::Merge.structured_edit_structure_profile(
        owner_scope: 'shared_default',
        owner_selector: 'line_bound_statements',
        owner_selector_family: 'line_oriented',
        known_owner_selector: true,
        supported_comment_regions: ['leading'],
        metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      selection_profile: Ast::Merge.structured_edit_selection_profile(
        owner_scope: 'shared_default',
        owner_selector: 'line_bound_statements',
        owner_selector_family: 'line_oriented',
        selector_kind: 'comment_region_owned_owner',
        selection_intent: 'comment_anchored_owner',
        selection_intent_family: 'comment_anchor',
        known_selection_intent: true,
        comment_region: 'leading',
        include_trailing_gap: true,
        comment_anchored: true,
        metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      match_profile: Ast::Merge.structured_edit_match_profile(
        start_boundary: 'comment_region_start',
        start_boundary_family: 'comment_anchor',
        known_start_boundary: true,
        end_boundary: 'owner_end_plus_trailing_gap',
        end_boundary_family: 'gap_extension',
        known_end_boundary: true,
        payload_kind: 'comment_owned_body',
        payload_family: 'comment_owned',
        known_payload_kind: true,
        comment_anchored: true,
        trailing_gap_extended: true,
        metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      )
    }
  }
end

.ruby_structured_edit_request_projectionObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/prism/merge.rb', line 177

def ruby_structured_edit_request_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_request: Ast::Merge.structured_edit_request(
      operation_kind: 'replace',
      content: "class App\n  # managed snippet\n  old_call\nend\n",
      source_label: 'source',
      target_selector: 'managed_snippet',
      target_selector_family: 'comment_anchor',
      target_selection: Ast::Merge.structured_edit_target_selection(
        selector_kind: 'comment_region_owned_owner',
        selection_intent: 'comment_anchored_owner',
        selection_intent_family: 'comment_anchor',
        known_selection_intent: true,
        comment_region: 'leading',
        include_trailing_gap: true,
        comment_anchored: true,
        metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      target_match: Ast::Merge.structured_edit_target_match(
        start_boundary: 'comment_region_start',
        start_boundary_family: 'comment_anchor',
        known_start_boundary: true,
        end_boundary: 'owner_end_plus_trailing_gap',
        end_boundary_family: 'gap_extension',
        known_end_boundary: true,
        payload_kind: 'comment_owned_body',
        payload_family: 'comment_owned',
        known_payload_kind: true,
        comment_anchored: true,
        trailing_gap_extended: true,
        metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      payload_text: "new_call\n",
      metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
    )
  }
end

.ruby_structured_edit_result_projectionObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/prism/merge.rb', line 217

def ruby_structured_edit_result_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_result: Ast::Merge.structured_edit_result(
      operation_kind: 'replace',
      updated_content: "class App\n  # managed snippet\n  new_call\nend\n",
      changed: true,
      captured_text: "old_call\n",
      match_count: 1,
      operation_profile: Ast::Merge.structured_edit_operation_profile(
        operation_kind: 'replace',
        operation_family: 'rewrite',
        known_operation_kind: true,
        source_requirement: 'required',
        destination_requirement: 'none',
        replacement_source: 'explicit_text',
        captures_source_text: true,
        supports_if_missing: false,
        metadata: { source: 'legacy_crispr_reference' }
      ),
      metadata: { family: 'ruby', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
    )
  }
end

.source_span_for_location(location) ⇒ Object



1325
1326
1327
1328
1329
1330
1331
# File 'lib/prism/merge.rb', line 1325

def source_span_for_location(location)
  TreeHaver::SourceSpan.new(
    range: TreeHaver::ByteRange.new(start_byte: location.start_offset, end_byte: location.end_offset),
    start_point: TreeHaver::SourcePoint.new(row: location.start_line - 1, column: location.start_column),
    end_point: TreeHaver::SourcePoint.new(row: location.end_line - 1, column: location.end_column)
  )
end

.unsupported_feature_result(message) ⇒ Object



929
930
931
# File 'lib/prism/merge.rb', line 929

def unsupported_feature_result(message)
  Ruby::Merge.unsupported_feature_result(message)
end