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(base_dir:) ⇒ Project

Returns a new instance of Project.



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

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

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

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



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

def base_dir
  @base_dir
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



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

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

#relative_path(path) ⇒ Object



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

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

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/steep/project.rb', line 23

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