Class: Steep::Drivers::Annotations

Inherits:
Object
  • Object
show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/annotations.rb

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#disable_install_collection, #steepfile

Instance Method Summary collapse

Methods included from Utils::DriverHelper

#install_collection, #keep_diagnostic?, #load_config, #request_id, #shutdown_exit, #wait_for_message, #wait_for_response_id

Constructor Details

#initialize(stdout:, stderr:) ⇒ Annotations

Returns a new instance of Annotations.



10
11
12
13
14
15
# File 'lib/steep/drivers/annotations.rb', line 10

def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr

  @command_line_patterns = []
end

Instance Attribute Details

#command_line_patternsObject (readonly)

Returns the value of attribute command_line_patterns.



4
5
6
# File 'lib/steep/drivers/annotations.rb', line 4

def command_line_patterns
  @command_line_patterns
end

#stderrObject (readonly)

Returns the value of attribute stderr.



6
7
8
# File 'lib/steep/drivers/annotations.rb', line 6

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



5
6
7
# File 'lib/steep/drivers/annotations.rb', line 5

def stdout
  @stdout
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/steep/drivers/annotations.rb', line 17

def run
  project = load_config()

  loader = Services::FileLoader.new(base_dir: project.base_dir)

  project.targets.each do |target|
    Steep.logger.tagged "target=#{target.name}" do
      service = Services::SignatureService.load_from(target.new_env_loader(), implicitly_returns_nil: target.implicitly_returns_nil)

      sigs = loader.load_changes(target.signature_pattern, changes: {})
      service.update(sigs)

      factory = AST::Types::Factory.new(builder: service.latest_builder)

      srcs = loader.load_changes(target.source_pattern, command_line_patterns, changes: {})
      srcs.each do |path, changes|
        text = changes.inject("") {|text, change| change.apply_to(text) }
        source = Source.parse(text, path: path, factory: factory)

        source.each_annotation.sort_by {|node, _| [node.loc.expression.begin_pos, node.loc.expression.end_pos] }.each do |node, annotations|
          loc = node.loc
          stdout.puts "#{path}:#{loc.line}:#{loc.column}:#{node.type}:\t#{node.loc.expression.source.lines.first}"
          annotations.each do |annotation|
            annotation.location or raise
            stdout.puts "  #{annotation.location.source}"
          end
        end
      end
    end
  end

  0
end