Class: Ibex::Runtime::SyntaxRepairResult

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

Overview

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

Constant Summary collapse

STATUSES =

Signature:

  • Array[Symbol]

Returns:

  • (Array[Symbol])
%i[accepted progress rejected unavailable exhausted not_found].freeze
BOUNDED_STATUSES =

Signature:

  • Array[Symbol]

Returns:

  • (Array[Symbol])
%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

RBS:

  • (status: Symbol, bounded_status: Symbol, reason: Symbol?, plan: SyntaxRepairPlan?, text_edits: Array[CST::TextEdit], syntax_root: CST::SyntaxNode, diagnostics: Array[SyntaxSessionDiagnostic], updated_source: CST::SourceText?, validation: SyntaxSessionResult?) -> void

Parameters:



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_statusSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


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

def bounded_status
  @bounded_status
end

#diagnosticsArray[SyntaxSessionDiagnostic] (readonly)

Signature:

  • Array[SyntaxSessionDiagnostic]

Returns:



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

def diagnostics
  @diagnostics
end

#planSyntaxRepairPlan? (readonly)

Signature:

  • SyntaxRepairPlan?

Returns:



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

def plan
  @plan
end

#reasonSymbol? (readonly)

Signature:

  • Symbol?

Returns:

  • (Symbol, nil)


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

def reason
  @reason
end

#statusSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


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

def status
  @status
end

#syntax_rootCST::SyntaxNode (readonly)

Signature:

  • CST::SyntaxNode

Returns:



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

def syntax_root
  @syntax_root
end

#text_editsArray[CST::TextEdit] (readonly)

Signature:

  • Array[CST::TextEdit]

Returns:



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

def text_edits
  @text_edits
end

#updated_sourceCST::SourceText? (readonly)

Signature:

  • CST::SourceText?

Returns:



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

def updated_source
  @updated_source
end

#validationSyntaxSessionResult? (readonly)

Signature:

  • SyntaxSessionResult?

Returns:



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

def validation
  @validation
end

Instance Method Details

#accepted?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


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

def accepted? = @status == :accepted

#progress?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


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

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

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

This method returns an undefined value.

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

RBS:

  • (Symbol, Symbol, Symbol?, SyntaxRepairPlan?, Array[CST::TextEdit], CST::SourceText?, SyntaxSessionResult?) -> void

Parameters:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ibex/runtime/syntax_repair.rb', line 192

def validate_result_shape!(status, bounded_status, reason, plan, text_edits, updated_source, validation)
  if %i[accepted progress rejected].include?(status)
    raise ArgumentError, "a completed syntax repair must be selected" unless bounded_status == :selected
    raise ArgumentError, "a completed syntax repair requires a plan" unless plan
    raise ArgumentError, "a completed syntax repair requires text edits" if text_edits.empty?
    raise ArgumentError, "a completed syntax repair requires updated source and validation" unless
      updated_source && validation
    raise ArgumentError, "a completed syntax repair cannot have a reason" unless reason.nil?
    raise ArgumentError, "accepted validation must succeed" if status == :accepted && !validation.success?
    if %i[progress rejected].include?(status) && validation.success?
      raise ArgumentError, "non-accepted validation must report an error"
    end

    return
  end

  if status == :unavailable
    raise ArgumentError, "unavailable syntax repair must be selected" unless bounded_status == :selected
    raise ArgumentError, "unavailable syntax repair requires a reason" unless reason
  elsif status != bounded_status || !%i[exhausted not_found].include?(status)
    raise ArgumentError, "bounded status does not match syntax repair status"
  end
  raise ArgumentError, "unavailable or bounded syntax repair cannot expose text edits" unless text_edits.empty?
  return unless updated_source || validation

  raise ArgumentError,
        "unavailable or bounded syntax repair cannot expose validation"
end