Class: Rbs::Merge::CommentTracker

Inherits:
Ast::Merge::Comment::HashTrackerBase
  • Object
show all
Defined in:
lib/rbs/merge/comment_tracker.rb

Overview

Tracks hash-style comments in RBS source and exposes a shared comment API.

Inherits shared lookup, query, region-building, and attachment API from Ast::Merge::Comment::HashTrackerBase. Only format-specific comment extraction and owner resolution are overridden here.

RBS has only full-line comments for the declarations this adapter models; inline hash-comment scenarios from the shared comment matrix do not exist in the language surface here. Treat those skipped matrix cases as syntax limits, not pending merge-engine work. Freeze marker lines are excluded from the tracked set.

Constant Summary collapse

DEFAULT_FREEZE_TOKEN =
'rbs-merge'

Instance Method Summary collapse

Constructor Details

#initialize(lines, freeze_token: DEFAULT_FREEZE_TOKEN) ⇒ CommentTracker

Returns a new instance of CommentTracker.



19
20
21
22
23
# File 'lib/rbs/merge/comment_tracker.rb', line 19

def initialize(lines, freeze_token: DEFAULT_FREEZE_TOKEN)
  @freeze_token = freeze_token
  @freeze_marker_pattern = Ast::Merge::FreezeNodeBase.pattern_for(:hash_comment, @freeze_token)
  super(Array(lines))
end

Instance Method Details

#augment(owners: [], **options) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/rbs/merge/comment_tracker.rb', line 47

def augment(owners: [], **options)
  Ast::Merge::Comment::Augmenter.new(
    lines: @lines,
    comments: @comments,
    owners: owners,
    style: :hash_comment,
    total_comment_count: @comments.size,
    **options
  )
end

#comment_attachment_for(owner, line_num: nil, **metadata) ⇒ Object

RBS format has no inline comment attachment here — override to always return nil. This is intentional syntax modeling, not missing feature work for the shared comment matrix.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbs/merge/comment_tracker.rb', line 28

def comment_attachment_for(owner, line_num: nil, **)
  resolved_line_num = line_num || owner_line_num(owner)
  resolved_end_line = owner_end_line(owner) || resolved_line_num
  leading_region = resolved_line_num ? leading_comment_region_before(resolved_line_num) : nil
  trailing_region = resolved_end_line ? trailing_comment_region_after(resolved_end_line) : nil

  Ast::Merge::Comment::Attachment.new(
    owner: owner,
    leading_region: leading_region,
    inline_region: nil,
    trailing_region: trailing_region,
    metadata: .merge(
      line_num: resolved_line_num,
      end_line: resolved_end_line,
      source: :comment_tracker
    )
  )
end