Class: Steep::Project::SourceFile
- Inherits:
-
Object
- Object
- Steep::Project::SourceFile
- Defined in:
- lib/steep/project/file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_updated_at ⇒ Object
readonly
Returns the value of attribute content_updated_at.
-
#last_type_checked_at ⇒ Object
readonly
Returns the value of attribute last_type_checked_at.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#typing ⇒ Object
readonly
Returns the value of attribute typing.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(path:, options:) ⇒ SourceFile
constructor
A new instance of SourceFile.
- #invalidate ⇒ Object
- #parse ⇒ Object
- #requires_type_check? ⇒ Boolean
- #type_check(check) ⇒ Object
Constructor Details
#initialize(path:, options:) ⇒ SourceFile
Returns a new instance of SourceFile.
13 14 15 16 17 |
# File 'lib/steep/project/file.rb', line 13 def initialize(path:, options:) @path = path @options = self.content = "" end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/steep/project/file.rb', line 6 def content @content end |
#content_updated_at ⇒ Object (readonly)
Returns the value of attribute content_updated_at.
7 8 9 |
# File 'lib/steep/project/file.rb', line 7 def content_updated_at @content_updated_at end |
#last_type_checked_at ⇒ Object (readonly)
Returns the value of attribute last_type_checked_at.
11 12 13 |
# File 'lib/steep/project/file.rb', line 11 def last_type_checked_at @last_type_checked_at end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/steep/project/file.rb', line 4 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/steep/project/file.rb', line 5 def path @path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/steep/project/file.rb', line 9 def source @source end |
#typing ⇒ Object (readonly)
Returns the value of attribute typing.
10 11 12 |
# File 'lib/steep/project/file.rb', line 10 def typing @typing end |
Instance Method Details
#errors ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/steep/project/file.rb', line 51 def errors typing&.errors&.reject do |error| case when error.is_a?(Errors::FallbackAny) !.fallback_any_is_error when error.is_a?(Errors::MethodDefinitionMissing) .allow_missing_definitions end end end |
#invalidate ⇒ Object
32 33 34 35 36 |
# File 'lib/steep/project/file.rb', line 32 def invalidate @source = nil @typing = nil @last_type_checked_at = nil end |
#parse ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/steep/project/file.rb', line 38 def parse _ = @source = begin Source.parse(content, path: path.to_s, labeling: ASTUtils::Labeling.new) rescue ::Parser::SyntaxError => exn Steep.logger.warn { "Syntax error on #{path}: #{exn.inspect}" } exn rescue EncodingError => exn Steep.logger.warn { "Encoding error on #{path}: #{exn.inspect}" } exn end end |
#requires_type_check? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/steep/project/file.rb', line 24 def requires_type_check? if last = last_type_checked_at last < content_updated_at else true end end |
#type_check(check) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/steep/project/file.rb', line 62 def type_check(check) case source = self.source when Source @typing = Typing.new annotations = source.annotations(block: source.node, builder: check.builder, current_module: AST::Namespace.root) const_env = TypeInference::ConstantEnv.new(builder: check.builder, context: nil) type_env = TypeInference::TypeEnv.build(annotations: annotations, subtyping: check, const_env: const_env, signatures: check.builder.signatures) construction = TypeConstruction.new( checker: check, annotations: annotations, source: source, self_type: AST::Builtin::Object.instance_type, block_context: nil, module_context: TypeConstruction::ModuleContext.new( instance_type: nil, module_type: nil, implement_name: nil, current_namespace: AST::Namespace.root, const_env: const_env, class_name: nil ), method_context: nil, typing: typing, break_context: nil, type_env: type_env ) construction.synthesize(source.node) @last_type_checked_at = Time.now end end |