Module: Markly::Merge

Defined in:
lib/markly/merge/provider.rb,
lib/markly/merge.rb,
lib/markly/merge/backend.rb,
lib/markly/merge/version.rb,
lib/markly/merge/freeze_node.rb,
lib/markly/merge/debug_logger.rb,
lib/markly/merge/smart_merger.rb,
lib/markly/merge/file_analysis.rb,
lib/markly/merge/comment_tracker.rb,
lib/markly/merge/partial_template_merger.rb,
sig/markly/merge.rbs

Overview

Source-preserving Markdown provider integration for Markly.

Defined Under Namespace

Modules: Backend, DebugLogger, Version Classes: FileAnalysis, PartialTemplateMerger, Provider, SmartMerger

Constant Summary collapse

PACKAGE_NAME =
'markly-merge'
BACKEND_REFERENCE =
TreeHaver::BackendReference.new(id: 'markly', family: 'native').freeze
VERSION =

Current gem version exposed at the traditional constant location.

Returns:

  • (String)
Version::VERSION
FreezeNode =
Markdown::Merge::FreezeNode
CommentTracker =
Markdown::Merge::CommentTracker

Class Method Summary collapse

Class Method Details

.available_markdown_backendsObject



28
29
30
# File 'lib/markly/merge.rb', line 28

def available_markdown_backends
  [BACKEND_REFERENCE]
end

.markdown_backend_feature_profile(backend: nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/markly/merge.rb', line 32

def markdown_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 Markdown backend #{requested}.")
  end

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

.markdown_embedded_families(analysis) ⇒ Object



491
492
493
# File 'lib/markly/merge.rb', line 491

def markdown_embedded_families(analysis)
  Markdown::Merge.markdown_embedded_families(analysis)
end

.markdown_feature_profileObject



24
25
26
# File 'lib/markly/merge.rb', line 24

def markdown_feature_profile
  Markdown::Merge.markdown_feature_profile
end

.markdown_plan_context(backend: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/markly/merge.rb', line 41

def markdown_plan_context(backend: nil)
  profile = markdown_backend_feature_profile(backend: backend)
  return profile if profile[:ok] == false

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

.markdown_structured_edit_application_projectionObject



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/markly/merge.rb', line 166

def markdown_structured_edit_application_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_application: Ast::Merge.structured_edit_application(
      request: markdown_structured_edit_request_projection[:structured_edit_request],
      result: markdown_structured_edit_result_projection[:structured_edit_result],
      metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
    )
  }
end

.markdown_structured_edit_batch_report_projectionObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
314
315
316
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
# File 'lib/markly/merge.rb', line 232

def markdown_structured_edit_batch_report_projection
  content = "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n\n## Deprecated\n\nDeprecated text.\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: 'README.md',
              target_selector: 'Synopsis@2',
              target_selector_family: 'section_branch',
              payload_text: "## Synopsis\n\nNew synopsis.\n",
              metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: 'replace',
              updated_content: "# Title\n\n## Synopsis\n\nNew synopsis.\n\n## Usage\n\nExisting text.\n\n## Deprecated\n\nDeprecated text.\n",
              changed: true,
              captured_text: "## Synopsis\n\nOld synopsis.\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: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
          ),
          provider_family: 'markdown',
          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: '/heading/usage',
              destination_selector_family: 'section_branch',
              payload_text: "### Managed Usage\n\nInserted usage text.\n",
              if_missing: 'append',
              metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: 'insert',
              updated_content: "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n### Managed Usage\n\nInserted usage text.\n\n## Deprecated\n\nDeprecated text.\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: 'append_fallback',
                resolution_source: 'none',
                anchor_boundary: 'none',
                resolution_family: 'append',
                resolution_source_family: 'implicit',
                anchor_boundary_family: 'none',
                known_resolution_kind: true,
                known_resolution_source: true,
                known_anchor_boundary: true,
                used_if_missing: true,
                metadata: { family: 'shared', source: 'legacy_crispr_reference' }
              ),
              metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
          ),
          provider_family: 'markdown',
          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: 'README.md',
              target_selector: 'Deprecated@2',
              target_selector_family: 'section_branch',
              metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: 'delete',
              updated_content: "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n",
              changed: true,
              captured_text: "## Deprecated\n\nDeprecated text.\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: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
            ),
            metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
          ),
          provider_family: 'markdown',
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: 'legacy_crispr_reference' }
        )
      ],
      diagnostics: [
        {
          severity: 'info',
          category: 'assumed_default',
          message: 'markdown batch preserved request ordering.'
        }
      ],
      metadata: { batch_label: 'markdown_markly_triad', source: 'legacy_crispr_reference' }
    )
  }
end

.markdown_structured_edit_batch_request_projectionObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/markly/merge.rb', line 192

def markdown_structured_edit_batch_request_projection
  content = "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n\n## Deprecated\n\nDeprecated text.\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: 'README.md',
          target_selector: 'Synopsis@2',
          target_selector_family: 'section_branch',
          payload_text: "## Synopsis\n\nNew synopsis.\n",
          metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
        ),
        Ast::Merge.structured_edit_request(
          operation_kind: 'insert',
          content: content,
          source_label: 'source',
          destination_selector: '/heading/usage',
          destination_selector_family: 'section_branch',
          payload_text: "### Managed Usage\n\nInserted usage text.\n",
          if_missing: 'append',
          metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
        ),
        Ast::Merge.structured_edit_request(
          operation_kind: 'delete',
          content: content,
          source_label: 'README.md',
          target_selector: 'Deprecated@2',
          target_selector_family: 'section_branch',
          metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
        )
      ],
      metadata: { batch_label: 'markdown_markly_triad', source: 'legacy_crispr_reference' }
    )
  }
end

.markdown_structured_edit_execution_report_projectionObject



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/markly/merge.rb', line 178

def markdown_structured_edit_execution_report_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_execution_report: Ast::Merge.structured_edit_execution_report(
      application: markdown_structured_edit_application_projection[:structured_edit_application],
      provider_family: 'markdown',
      provider_backend: BACKEND_REFERENCE.id,
      diagnostics: [],
      metadata: { source: 'legacy_crispr_reference' }
    )
  }
end

.markdown_structured_edit_provider_profileObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/markly/merge.rb', line 55

def markdown_structured_edit_provider_profile
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_profile: {
      family: 'markdown',
      structure_profile: Ast::Merge.structured_edit_structure_profile(
        owner_scope: 'heading_sections',
        owner_selector: 'heading_sections',
        owner_selector_family: 'section_branch',
        known_owner_selector: true,
        supported_comment_regions: [],
        metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      selection_profile: Ast::Merge.structured_edit_selection_profile(
        owner_scope: 'heading_sections',
        owner_selector: 'heading_sections',
        owner_selector_family: 'section_branch',
        selector_kind: 'heading_section',
        selection_intent: 'section_branch',
        selection_intent_family: 'section_branch',
        known_selection_intent: true,
        comment_region: nil,
        include_trailing_gap: false,
        comment_anchored: false,
        metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      match_profile: Ast::Merge.structured_edit_match_profile(
        start_boundary: 'owner_start',
        start_boundary_family: 'structural_owner',
        known_start_boundary: true,
        end_boundary: 'owner_end',
        end_boundary_family: 'structural_owner',
        known_end_boundary: true,
        payload_kind: 'section_branch',
        payload_family: 'section_branch',
        known_payload_kind: true,
        comment_anchored: false,
        trailing_gap_extended: false,
        metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      )
    }
  }
end

.markdown_structured_edit_request_projectionObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/markly/merge.rb', line 100

def markdown_structured_edit_request_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_request: Ast::Merge.structured_edit_request(
      operation_kind: 'replace',
      content: "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Install\n\nInstall text.\n",
      source_label: 'README.md',
      target_selector: 'Synopsis@2',
      target_selector_family: 'section_branch',
      target_selection: Ast::Merge.structured_edit_target_selection(
        selector_kind: 'heading_section',
        selection_intent: 'section_branch',
        selection_intent_family: 'section_branch',
        known_selection_intent: true,
        comment_region: nil,
        include_trailing_gap: false,
        comment_anchored: false,
        metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      target_match: Ast::Merge.structured_edit_target_match(
        start_boundary: 'owner_start',
        start_boundary_family: 'structural_owner',
        known_start_boundary: true,
        end_boundary: 'owner_end',
        end_boundary_family: 'structural_owner',
        known_end_boundary: true,
        payload_kind: 'section_branch',
        payload_family: 'section_branch',
        known_payload_kind: true,
        comment_anchored: false,
        trailing_gap_extended: false,
        metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
      ),
      payload_text: "## Synopsis\n\nNew synopsis.\n",
      metadata: { family: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
    )
  }
end

.markdown_structured_edit_result_projectionObject



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
# File 'lib/markly/merge.rb', line 140

def markdown_structured_edit_result_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_result: Ast::Merge.structured_edit_result(
      operation_kind: 'replace',
      updated_content: "# Title\n\n## Synopsis\n\nNew synopsis.\n\n## Install\n\nInstall text.\n",
      changed: true,
      captured_text: "## Synopsis\n\nOld synopsis.\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: 'markdown', provider: BACKEND_REFERENCE.id, source: 'legacy_crispr_reference' }
    )
  }
end

.match_markdown_owners(template, destination) ⇒ Object



402
403
404
# File 'lib/markly/merge.rb', line 402

def match_markdown_owners(template, destination)
  Markdown::Merge.match_markdown_owners(template, destination)
end

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



406
407
408
409
410
411
412
413
# File 'lib/markly/merge.rb', line 406

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

  Markdown::Merge.merge_markdown(template_source, destination_source, dialect)
end

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



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/markly/merge.rb', line 415

def merge_markdown_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 Markdown backend #{requested}.")
  end

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs(
    template_source,
    destination_source,
    dialect,
    review_state,
    applied_children
  )
end

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



431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/markly/merge.rb', line 431

def merge_markdown_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 Markdown backend #{requested}.")
  end

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_replay_bundle(
    template_source,
    destination_source,
    dialect,
    replay_bundle
  )
end

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



446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/markly/merge.rb', line 446

def merge_markdown_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 Markdown backend #{requested}.")
  end

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_replay_bundle_envelope(
    template_source,
    destination_source,
    dialect,
    envelope
  )
end

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



461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/markly/merge.rb', line 461

def merge_markdown_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 Markdown backend #{requested}.")
  end

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_review_state(
    template_source,
    destination_source,
    dialect,
    review_state
  )
end

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



476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/markly/merge.rb', line 476

def merge_markdown_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 Markdown backend #{requested}.")
  end

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_review_state_envelope(
    template_source,
    destination_source,
    dialect,
    envelope
  )
end

.merge_providerProvider

Returns:



30
31
32
# File 'lib/markly/merge/provider.rb', line 30

def merge_provider
  @merge_provider ||= Provider.new
end

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



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
# File 'lib/markly/merge.rb', line 374

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

  TreeHaver.with_backend(BACKEND_REFERENCE.id) { TreeHaver.parser_for(:markdown).parse(source) }
  normalized = Markdown::Merge.normalize_source(source)
  {
    ok: true,
    diagnostics: [],
    analysis: {
      kind: 'markdown',
      dialect: dialect,
      normalized_source: normalized,
      root_kind: 'document',
      owners: Markdown::Merge.collect_markdown_owners(normalized)
    },
    policies: []
  }
rescue StandardError => e
  {
    ok: false,
    diagnostics: [{ severity: 'error', category: 'parse_error', message: e.message }],
    policies: []
  }
end

.register_provider!(replace: false) ⇒ Object

Parameters:

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

Returns:

  • (Object)


34
35
36
37
38
# File 'lib/markly/merge/provider.rb', line 34

def register_provider!(replace: false)
  return unless Ast::Merge.respond_to?(:register_provider)

  Ast::Merge.register_provider(merge_provider, replace: replace)
end

.unsupported_feature_result(message) ⇒ Object



495
496
497
498
499
500
501
# File 'lib/markly/merge.rb', line 495

def unsupported_feature_result(message)
  {
    ok: false,
    diagnostics: [{ severity: 'error', category: 'unsupported_feature', message: message }],
    policies: []
  }
end