Class: Ibex::Runtime::SyntaxRepairResult
- Inherits:
-
Object
- Object
- Ibex::Runtime::SyntaxRepairResult
- 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 =
%i[accepted progress rejected unavailable exhausted not_found].freeze
- BOUNDED_STATUSES =
%i[selected exhausted not_found].freeze
Instance Attribute Summary collapse
- #bounded_status ⇒ Symbol readonly
- #diagnostics ⇒ Array[SyntaxSessionDiagnostic] readonly
- #plan ⇒ SyntaxRepairPlan? readonly
- #reason ⇒ Symbol? readonly
- #status ⇒ Symbol readonly
- #syntax_root ⇒ CST::SyntaxNode readonly
- #text_edits ⇒ Array[CST::TextEdit] readonly
- #updated_source ⇒ CST::SourceText? readonly
- #validation ⇒ SyntaxSessionResult? readonly
Instance Method Summary collapse
- #accepted? ⇒ Boolean
-
#initialize(status:, bounded_status:, reason:, plan:, text_edits:, syntax_root:, diagnostics:, updated_source:, validation:) ⇒ SyntaxRepairResult
constructor
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
- #progress? ⇒ Boolean
-
#validate_result_shape!(status, bounded_status, reason, plan, text_edits, updated_source, validation) ⇒ void
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
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
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_status ⇒ Symbol (readonly)
128 129 130 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 128 def bounded_status @bounded_status end |
#diagnostics ⇒ Array[SyntaxSessionDiagnostic] (readonly)
133 134 135 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 133 def diagnostics @diagnostics end |
#plan ⇒ SyntaxRepairPlan? (readonly)
130 131 132 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 130 def plan @plan end |
#reason ⇒ Symbol? (readonly)
129 130 131 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 129 def reason @reason end |
#status ⇒ Symbol (readonly)
127 128 129 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 127 def status @status end |
#syntax_root ⇒ CST::SyntaxNode (readonly)
132 133 134 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 132 def syntax_root @syntax_root end |
#text_edits ⇒ Array[CST::TextEdit] (readonly)
131 132 133 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 131 def text_edits @text_edits end |
#updated_source ⇒ CST::SourceText? (readonly)
134 135 136 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 134 def updated_source @updated_source end |
#validation ⇒ SyntaxSessionResult? (readonly)
135 136 137 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 135 def validation @validation end |
Instance Method Details
#accepted? ⇒ Boolean
182 |
# File 'lib/ibex/runtime/syntax_repair.rb', line 182 def accepted? = @status == :accepted |
#progress? ⇒ 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
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 |