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 (no inline comment syntax), and 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.



16
17
18
19
20
# File 'lib/rbs/merge/comment_tracker.rb', line 16

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



40
41
42
43
44
45
46
47
48
49
# File 'lib/rbs/merge/comment_tracker.rb', line 40

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 comments — override to always return nil.
This keeps comment_attachment_for from erroneously detecting inline
content on the same line.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbs/merge/comment_tracker.rb', line 25

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

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