Class: Steep::Drivers::Watch::WatchListener

Inherits:
Project::NullListener show all
Defined in:
lib/steep/drivers/watch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Project::NullListener

#clear_project, #parse_signature, #parse_source, #validate_signature

Constructor Details

#initialize(stdout:, stderr:, verbose:) ⇒ WatchListener

Returns a new instance of WatchListener.



112
113
114
115
# File 'lib/steep/drivers/watch.rb', line 112

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

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



110
111
112
# File 'lib/steep/drivers/watch.rb', line 110

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



109
110
111
# File 'lib/steep/drivers/watch.rb', line 109

def stdout
  @stdout
end

Instance Method Details

#check(project:) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/steep/drivers/watch.rb', line 117

def check(project:)
  yield.tap do
    if project.success?
      if project.has_type_error?
        stdout.puts "Detected #{project.errors.size} errors... 🔥"
      else
        stdout.puts "No error detected. 🎉"
      end
    else
      stdout.puts "Type checking failed... 🔥"
    end
  end
end

#load_signature(project:) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/steep/drivers/watch.rb', line 142

def load_signature(project:)
  # @type var project: Project
  yield.tap do
    case sig = project.signature
    when Project::SignatureHasError
    when Project::SignatureHasSyntaxError
      sig.errors.each do |path, exn|
        stdout.puts "#{path} has a syntax error: #{exn.inspect}"
      end
    end
  end
end

#type_check_source(project:, file:) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/steep/drivers/watch.rb', line 131

def type_check_source(project:, file:)
  yield.tap do
    case
    when file.source.is_a?(Source) && file.errors
      file.errors.each do |error|
        error.print_to stdout
      end
    end
  end
end