private ApplyChangesFromQueue ( Queue |
||
queue | Queue |
|
return | List |
internal List<TreeChangeEventRecord> ApplyChangesFromQueue(Queue<EditorTreeChange> queue) {
if (_ownerThread != Thread.CurrentThread.ManagedThreadId)
throw new ThreadStateException("Method should only be called on the main thread");
var changesToFire = new List<TreeChangeEventRecord>();
if (queue == null || queue.Count == 0)
return changesToFire;
// Since we have write lock we cannot fire events. If we fire an event,
// listener may try and access the tree while a) tree not ready and
// b) accessing AstRoot may check tree readiness and since tree is not
// ready yet (as it is still applying changes) it may try and update
// tree on its own and end up hanging trying to acquire write lock again.
// Hence we must store events in a list and fire then when update
// is done and the lock is released.
try {
AcquireWriteLock();
while (queue.Count > 0) {
var change = queue.Dequeue();
switch (change.ChangeType) {
case TreeChangeType.NewTree: {
var c = change as EditorTreeChange_NewTree;
_astRoot = c.NewTree;
changesToFire.Add(new TreeChangeEventRecord(change.ChangeType));
}
break;
default:
Debug.Fail("Unknown tree change");
break;
}
}
} finally {
ReleaseWriteLock();
}
return changesToFire;
}
List <TreeChangeEventRecord> ApplyTreeChanges(EditorTreeChangeCollection changesToApply) { // Check editor tree reference since document could have been // closed before parsing was completed if (!_disposed && _editorTree != null) { if (TextBuffer != null) { _editorTree.TextSnapshot = TextBuffer.CurrentSnapshot; } return(_editorTree.ApplyChangesFromQueue(changesToApply.ChangeQueue)); } return(new List <TreeChangeEventRecord>()); }