Sha256: 83ca781c91be66052647390cc9bca6b4a1a58a0f6b69c2810d49e013894924f5

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 KB

Contents

module Steep
  class Project
    attr_reader :targets
    attr_reader :steepfile_path

    def initialize(steepfile_path:)
      @targets = []
      @steepfile_path = steepfile_path

      unless steepfile_path.absolute?
        raise "Project#initialize(steepfile_path:): steepfile_path should be absolute path"
      end
    end

    def base_dir
      steepfile_path.parent
    end

    def relative_path(path)
      path.relative_path_from(base_dir)
    end

    def absolute_path(path)
      (base_dir + path).cleanpath
    end

    def type_of_node(path:, line:, column:)
      source_file = targets.map {|target| target.source_files[path] }.compact[0]

      if source_file

        case (status = source_file.status)
        when SourceFile::TypeCheckStatus
          node = status.source.find_node(line: line, column: column)

          type = begin
            status.typing.type_of(node: node)
          rescue RuntimeError
            AST::Builtin.any_type
          end

          if block_given?
            yield type, node
          else
            type
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
steep-0.29.0 lib/steep/project.rb
steep-0.28.0 lib/steep/project.rb
steep-0.27.0 lib/steep/project.rb
steep-0.25.0 lib/steep/project.rb
steep-0.24.0 lib/steep/project.rb
steep-0.23.0 lib/steep/project.rb
steep-0.22.0 lib/steep/project.rb
steep-0.21.0 lib/steep/project.rb
steep-0.20.0 lib/steep/project.rb
steep-0.19.0 lib/steep/project.rb
steep-0.18.0 lib/steep/project.rb
steep-0.17.1 lib/steep/project.rb
steep-0.17.0 lib/steep/project.rb
steep-0.16.3 lib/steep/project.rb
steep-0.16.2 lib/steep/project.rb
steep-0.16.1 lib/steep/project.rb
steep-0.16.0 lib/steep/project.rb