Class: Ibex::Runtime::SyntaxRepairResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/runtime/syntax_repair.rb

Overview

Immutable syntax-only repair attempt. There is deliberately no value.

Constant Summary collapse

STATUSES =

: Array

%i[accepted progress rejected unavailable exhausted not_found].freeze
BOUNDED_STATUSES =

: Array

%i[selected exhausted not_found].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, bounded_status:, reason:, plan:, text_edits:, syntax_root:, diagnostics:, updated_source:, validation:) ⇒ SyntaxRepairResult

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity

Raises:

  • (ArgumentError)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/ibex/runtime/syntax_repair.rb', line 142

def initialize(status:, bounded_status:, reason:, plan:, text_edits:, syntax_root:, diagnostics:,
               updated_source:, validation:)
  raise ArgumentError, "unknown syntax repair status #{status.inspect}" unless STATUSES.include?(status)
  unless BOUNDED_STATUSES.include?(bounded_status)
    raise ArgumentError, "unknown syntax repair bounded status #{bounded_status.inspect}"
  end
  unless text_edits.is_a?(Array) && text_edits.all?(CST::TextEdit)
    raise ArgumentError, "syntax repair text_edits must contain only CST::TextEdit values"
  end
  unless diagnostics.is_a?(Array) && diagnostics.all?(SyntaxSessionDiagnostic)
    raise ArgumentError, "syntax repair diagnostics must be immutable syntax-session diagnostics"
  end
  raise ArgumentError, "syntax_root must be a CST::SyntaxNode" unless syntax_root.is_a?(CST::SyntaxNode)
  raise ArgumentError, "syntax repair reason must be a Symbol or nil" unless reason.nil? || reason.is_a?(Symbol)
  unless plan.nil? || plan.is_a?(SyntaxRepairPlan)
    raise ArgumentError, "syntax repair plan must be a SyntaxRepairPlan or nil"
  end
  unless updated_source.nil? || updated_source.is_a?(CST::SourceText)
    raise ArgumentError, "updated_source must be a CST::SourceText or nil"
  end
  unless validation.nil? || validation.is_a?(SyntaxSessionResult)
    raise ArgumentError, "validation must be a SyntaxSessionResult or nil"
  end

  validate_result_shape!(status, bounded_status, reason, plan, text_edits, updated_source, validation)

  @status = status
  @bounded_status = bounded_status
  @reason = reason
  @plan = plan
  @text_edits = text_edits.dup.freeze
  @syntax_root = syntax_root
  @diagnostics = diagnostics.dup.freeze
  @updated_source = updated_source
  @validation = validation
  freeze
end

Instance Attribute Details

#bounded_statusObject (readonly)

: Symbol



128
129
130
# File 'lib/ibex/runtime/syntax_repair.rb', line 128

def bounded_status
  @bounded_status
end

#diagnosticsObject (readonly)

: Array



133
134
135
# File 'lib/ibex/runtime/syntax_repair.rb', line 133

def diagnostics
  @diagnostics
end

#planObject (readonly)

: SyntaxRepairPlan?



130
131
132
# File 'lib/ibex/runtime/syntax_repair.rb', line 130

def plan
  @plan
end

#reasonObject (readonly)

: Symbol?



129
130
131
# File 'lib/ibex/runtime/syntax_repair.rb', line 129

def reason
  @reason
end

#statusObject (readonly)

: Symbol



127
128
129
# File 'lib/ibex/runtime/syntax_repair.rb', line 127

def status
  @status
end

#syntax_rootObject (readonly)

: CST::SyntaxNode



132
133
134
# File 'lib/ibex/runtime/syntax_repair.rb', line 132

def syntax_root
  @syntax_root
end

#text_editsObject (readonly)

: Array



131
132
133
# File 'lib/ibex/runtime/syntax_repair.rb', line 131

def text_edits
  @text_edits
end

#updated_sourceObject (readonly)

: CST::SourceText?



134
135
136
# File 'lib/ibex/runtime/syntax_repair.rb', line 134

def updated_source
  @updated_source
end

#validationObject (readonly)

: SyntaxSessionResult?



135
136
137
# File 'lib/ibex/runtime/syntax_repair.rb', line 135

def validation
  @validation
end

Instance Method Details

#accepted?Boolean

Returns:

  • (Boolean)


182
# File 'lib/ibex/runtime/syntax_repair.rb', line 182

def accepted? = @status == :accepted

#progress?Boolean

Returns:

  • (Boolean)


185
# File 'lib/ibex/runtime/syntax_repair.rb', line 185

def progress? = %i[accepted progress].include?(@status)