131 } |
131 } |
132 def phase = _phase |
132 def phase = _phase |
133 def is_ready: Boolean = phase == Session.Ready |
133 def is_ready: Boolean = phase == Session.Ready |
134 |
134 |
135 private val global_state = new Volatile(Document.State.init) |
135 private val global_state = new Volatile(Document.State.init) |
136 def current_state(): Document.State = global_state.peek() |
136 def current_state(): Document.State = global_state() |
137 |
137 |
138 def snapshot(name: String, pending_edits: List[Text.Edit]): Document.Snapshot = |
138 def snapshot(name: String, pending_edits: List[Text.Edit]): Document.Snapshot = |
139 current_state().snapshot(name, pending_edits) |
139 global_state().snapshot(name, pending_edits) |
140 |
140 |
141 |
141 |
142 /* theory files */ |
142 /* theory files */ |
143 |
143 |
144 val thy_load = new Thy_Load |
144 val thy_load = new Thy_Load |
178 def handle_edits(name: String, |
178 def handle_edits(name: String, |
179 header: Document.Node.Header, edits: List[Option[List[Text.Edit]]]) |
179 header: Document.Node.Header, edits: List[Option[List[Text.Edit]]]) |
180 //{{{ |
180 //{{{ |
181 { |
181 { |
182 val syntax = current_syntax() |
182 val syntax = current_syntax() |
183 val previous = current_state().history.tip.version |
183 val previous = global_state().history.tip.version |
184 val doc_edits = edits.map(edit => (name, edit)) |
184 val doc_edits = edits.map(edit => (name, edit)) |
185 val result = Future.fork { Thy_Syntax.text_edits(syntax, previous.join, doc_edits) } |
185 val result = Future.fork { Thy_Syntax.text_edits(syntax, previous.join, doc_edits) } |
186 val change = global_state.change_yield(_.extend_history(previous, doc_edits, result)) |
186 val change = global_state.change_yield(_.extend_history(previous, doc_edits, result)) |
187 |
187 |
188 change.version.map(_ => { |
188 change.version.map(_ => { |
189 assignments.await { current_state().is_assigned(previous.get_finished) } |
189 assignments.await { global_state().is_assigned(previous.get_finished) } |
190 this_actor ! Change_Node(name, header, change) }) |
190 this_actor ! Change_Node(name, header, change) }) |
191 } |
191 } |
192 //}}} |
192 //}}} |
193 |
193 |
194 |
194 |
198 //{{{ |
198 //{{{ |
199 { |
199 { |
200 val previous = change.previous.get_finished |
200 val previous = change.previous.get_finished |
201 val (node_edits, version) = change.result.get_finished |
201 val (node_edits, version) = change.result.get_finished |
202 |
202 |
203 var former_assignment = current_state().the_assignment(previous).get_finished |
203 var former_assignment = global_state().the_assignment(previous).get_finished |
204 for { |
204 for { |
205 (name, Some(cmd_edits)) <- node_edits |
205 (name, Some(cmd_edits)) <- node_edits |
206 (prev, None) <- cmd_edits |
206 (prev, None) <- cmd_edits |
207 removed <- previous.nodes(name).commands.get_after(prev) |
207 removed <- previous.nodes(name).commands.get_after(prev) |
208 } former_assignment -= removed |
208 } former_assignment -= removed |
217 val id1 = c1.map(_.id) |
217 val id1 = c1.map(_.id) |
218 val id2 = |
218 val id2 = |
219 c2 match { |
219 c2 match { |
220 case None => None |
220 case None => None |
221 case Some(command) => |
221 case Some(command) => |
222 if (current_state().lookup_command(command.id).isEmpty) { |
222 if (global_state().lookup_command(command.id).isEmpty) { |
223 global_state.change(_.define_command(command)) |
223 global_state.change(_.define_command(command)) |
224 prover.get.define_command(command.id, Symbol.encode(command.source)) |
224 prover.get.define_command(command.id, Symbol.encode(command.source)) |
225 } |
225 } |
226 Some(command.id) |
226 Some(command.id) |
227 } |
227 } |