182
public static void ScanSpans (Document doc, SyntaxMode mode, Rule rule, Stack<Span> spanStack, int start, int end)
182
public static void ScanSpans (Document doc, SyntaxMode mode, Rule rule, CloneableStack<Span> spanStack, int start, int end)
184
184
SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack);
185
185
parser.ParseSpans (start, end - start);
188
static bool IsEqual (Span[] spans1, Span[] spans2)
190
if (spans1 == null || spans1.Length == 0)
191
return spans2 == null || spans2.Length == 0;
192
if (spans2 == null || spans1.Length != spans2.Length)
194
for (int i = 0; i < spans1.Length; i++) {
195
if (spans1[i] != spans2[i]) {
202
188
static Queue<UpdateWorker> updateQueue = new Queue<UpdateWorker> ();
204
190
class UpdateWorker
231
217
ManualResetEvent = new ManualResetEvent (false);
234
protected void ScanSpansThreaded (Document doc, Rule rule, Stack<Span> spanStack, int start, int end)
236
SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack);
237
parser.ParseSpans (start, end - start);
240
221
bool EndsWithContinuation (Span span, LineSegment line)
246
227
public void InnerRun ()
248
229
bool doUpdate = false;
249
LineSegment lineSegment = doc.GetLineByOffset (startOffset);
250
if (lineSegment == null)
252
RedBlackTree<LineSegmentTree.TreeNode>.RedBlackTreeIterator iter = lineSegment.Iter;
253
if (iter == null || iter.Current == null)
255
Stack<Span> spanStack = iter.Current.StartSpan != null ? new Stack<Span> (iter.Current.StartSpan) : new Stack<Span> ();
230
int startLine = doc.OffsetToLineNumber (startOffset);
257
LineSegment oldLine = iter.Current.Offset > 0 ? doc.GetLineByOffset (iter.Current.Offset - 1) : null;
259
LineSegment line = iter.Current;
260
if (line == null || line.Offset < 0)
263
List<Span> spanList = new List<Span> (spanStack.ToArray ());
265
for (int i = 0; i < spanList.Count; i++) {
266
if (!EndsWithContinuation (spanList[i], oldLine)) {
267
spanList.RemoveAt (i);
271
Span[] newSpans = spanList.ToArray ();
234
var lineSegment = doc.GetLine (startLine);
235
if (lineSegment == null)
237
var span = lineSegment.StartSpan;
240
var spanStack = span.Clone ();
241
SyntaxMode.SpanParser parser = mode.CreateSpanParser(doc, mode, null, spanStack);
242
foreach (var line in doc.GetLinesStartingAt (startLine)) {
272
245
if (line.Offset > endOffset) {
273
bool equal = IsEqual (line.StartSpan, newSpans);
278
line.StartSpan = newSpans.Length > 0 ? newSpans : null;
281
if (spanStack.Count > 0 && !String.IsNullOrEmpty (spanStack.Peek ().Rule))
282
rule = mode.GetRule (spanStack.Peek ().Rule) ?? mode;
284
ScanSpansThreaded (doc, rule, spanStack, line.Offset, line.EndOffset);
285
while (spanStack.Count > 0 && !EndsWithContinuation (spanStack.Peek (), line))
288
} while (iter.MoveNext ());
246
span = line.StartSpan;
249
bool equal = span.Equals(spanStack);
254
line.StartSpan = spanStack.Clone();
255
parser.ParseSpans(line.Offset, line.Length);
256
while (spanStack.Count > 0 && !EndsWithContinuation(spanStack.Peek(), line))
289
259
} catch (Exception e) {
290
260
Console.WriteLine ("Syntax highlighting exception:" + e);
347
317
if (worker != null && worker.Doc == doc)
348
318
worker.ManualResetEvent.WaitOne ();
349
319
} catch (Exception e) {
350
Console.WriteLine ("Worker:" + worker);
351
Console.WriteLine ("------");
352
320
Console.WriteLine (e);
353
Console.WriteLine ("------");
354
Console.WriteLine ("worker.Doc:" + worker.Doc);
355
Console.WriteLine ("worker.IsFinished:" + worker.IsFinished);
356
Console.WriteLine ("worker.ManualResetEvent:" + worker.ManualResetEvent);