Sha256: 2d142dd685b76926c4586dcb219cccbcb1c55c8e557bbe0d6586e0b3be8138ba

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

module Steep
  module Drivers
    class Validate
      attr_reader :stdout
      attr_reader :stderr

      include Utils::DriverHelper

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

      def run
        project = load_config()
        file_loader = Services::FileLoader.new(base_dir: project.base_dir)

        any_error = false

        project.targets.each do |target|
          controller = Services::SignatureService.load_from(target.new_env_loader(project: project))

          changes = file_loader.load_changes(target.signature_pattern, changes: {})
          controller.update(changes)

          errors =
            Steep.measure "Validation" do
              case controller.status
              when Services::SignatureService::SyntaxErrorStatus, Services::SignatureService::AncestorErrorStatus
                controller.status.diagnostics
              when Services::SignatureService::LoadedStatus
                check = Subtyping::Check.new(factory: AST::Types::Factory.new(builder: controller.latest_builder))
                Signature::Validator.new(checker: check).tap {|v| v.validate() }.each_error.to_a
              end
            end

          any_error ||= !errors.empty?

          formatter = Diagnostic::LSPFormatter.new
          diagnostics = errors.group_by {|e| e.location.buffer }.transform_values do |errors|
            errors.map {|error| formatter.format(error) }
          end

          diagnostics.each do |buffer, ds|
            printer = DiagnosticPrinter.new(stdout: stdout, buffer: buffer)
            ds.each do |d|
              printer.print(d)
              stdout.puts
            end
          end
        end

        any_error ? 1 : 0
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
steep-0.45.0 lib/steep/drivers/validate.rb
steep-0.44.1 lib/steep/drivers/validate.rb
steep-0.44.0 lib/steep/drivers/validate.rb
steep-0.43.1 lib/steep/drivers/validate.rb
steep-0.43.0 lib/steep/drivers/validate.rb