Class: Prism::Merge::RubyDocSurfaceAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/merge/ruby_doc_surface_analyzer.rb

Overview

Discovers doc-comment and @example child surfaces while leaving raw span ownership and reconstruction anchored to Prism-owned source lines.

Constant Summary collapse

DEFAULT_DOC_LANGUAGE =
:yard
DEFAULT_EXAMPLE_LANGUAGE =
:ruby

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(analysis, doc_language: DEFAULT_DOC_LANGUAGE, default_example_language: DEFAULT_EXAMPLE_LANGUAGE) ⇒ RubyDocSurfaceAnalyzer

Returns a new instance of RubyDocSurfaceAnalyzer.



13
14
15
16
17
# File 'lib/prism/merge/ruby_doc_surface_analyzer.rb', line 13

def initialize(analysis, doc_language: DEFAULT_DOC_LANGUAGE, default_example_language: DEFAULT_EXAMPLE_LANGUAGE)
  @analysis = analysis
  @doc_language = normalize_language(doc_language).to_sym
  @default_example_language = normalize_language(default_example_language).to_sym
end

Instance Attribute Details

#analysisObject (readonly)

Returns the value of attribute analysis.



11
12
13
# File 'lib/prism/merge/ruby_doc_surface_analyzer.rb', line 11

def analysis
  @analysis
end

Instance Method Details

#discover_child_surfaces(surface) ⇒ Object



42
43
44
45
46
# File 'lib/prism/merge/ruby_doc_surface_analyzer.rb', line 42

def discover_child_surfaces(surface)
  return [] unless surface.surface_kind == :ruby_doc_comment

  discover_example_surfaces(surface)
end

#discover_doc_comment_surfaces(owners: analysis.statements) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/prism/merge/ruby_doc_surface_analyzer.rb', line 19

def discover_doc_comment_surfaces(owners: analysis.statements)
  Array(owners).filter_map do |owner|
    attachment = analysis.comment_attachment_for(owner)
    region = attachment.leading_region
    next unless doc_comment_region?(region)

    build_doc_comment_surface(owner, region)
  end
end

#discover_surfaces(owners: analysis.statements) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/prism/merge/ruby_doc_surface_analyzer.rb', line 29

def discover_surfaces(owners: analysis.statements)
  discovered = []
  queue = discover_doc_comment_surfaces(owners: owners)

  until queue.empty?
    surface = queue.shift
    discovered << surface
    queue.concat(discover_child_surfaces(surface))
  end

  discovered
end