Class: Steep::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/project.rb,
lib/steep/project/dsl.rb,
lib/steep/project/file.rb,
lib/steep/project/target.rb,
lib/steep/project/options.rb,
lib/steep/project/file_loader.rb,
lib/steep/project/hover_content.rb,
lib/steep/project/completion_provider.rb

Defined Under Namespace

Classes: CompletionProvider, DSL, FileLoader, HoverContent, Options, SignatureFile, SourceFile, Target

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steepfile_path:) ⇒ Project

Returns a new instance of Project.



6
7
8
9
10
11
12
13
# File 'lib/steep/project.rb', line 6

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

Instance Attribute Details

#steepfile_pathObject (readonly)

Returns the value of attribute steepfile_path.



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

def steepfile_path
  @steepfile_path
end

#targetsObject (readonly)

Returns the value of attribute targets.



3
4
5
# File 'lib/steep/project.rb', line 3

def targets
  @targets
end

Instance Method Details

#absolute_path(path) ⇒ Object



23
24
25
# File 'lib/steep/project.rb', line 23

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

#base_dirObject



15
16
17
# File 'lib/steep/project.rb', line 15

def base_dir
  steepfile_path.parent
end

#relative_path(path) ⇒ Object



19
20
21
# File 'lib/steep/project.rb', line 19

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

#type_of_node(path:, line:, column:) ⇒ Object



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/project.rb', line 27

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