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
RedBlackTree<LineSegmentTree.TreeNode>.RedBlackTreeIterator iter = doc.GetLineByOffset (startOffset).Iter;
250
if (iter == null || iter.Current == null)
230
int startLine = doc.OffsetToLineNumber (startOffset);
252
Stack<Span> spanStack = iter.Current.StartSpan != null ? new Stack<Span> (iter.Current.StartSpan) : new Stack<Span> ();
254
LineSegment oldLine = iter.Current.Offset > 0 ? doc.GetLineByOffset (iter.Current.Offset - 1) : null;
256
LineSegment line = iter.Current;
257
if (line == null || line.Offset < 0)
260
List<Span> spanList = new List<Span> (spanStack.ToArray ());
262
for (int i = 0; i < spanList.Count; i++) {
263
if (!EndsWithContinuation (spanList[i], oldLine)) {
264
spanList.RemoveAt (i);
268
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)) {
269
245
if (line.Offset > endOffset) {
270
bool equal = IsEqual (line.StartSpan, newSpans);
275
line.StartSpan = newSpans.Length > 0 ? newSpans : null;
278
if (spanStack.Count > 0 && !String.IsNullOrEmpty (spanStack.Peek ().Rule))
279
rule = mode.GetRule (spanStack.Peek ().Rule) ?? mode;
281
ScanSpansThreaded (doc, rule, spanStack, line.Offset, line.EndOffset);
282
while (spanStack.Count > 0 && !EndsWithContinuation (spanStack.Peek (), line))
285
} 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))
286
259
} catch (Exception e) {
287
260
Console.WriteLine ("Syntax highlighting exception:" + e);
344
317
if (worker != null && worker.Doc == doc)
345
318
worker.ManualResetEvent.WaitOne ();
346
319
} catch (Exception e) {
347
Console.WriteLine ("Worker:" + worker);
348
Console.WriteLine ("------");
349
320
Console.WriteLine (e);
350
Console.WriteLine ("------");
351
Console.WriteLine ("worker.Doc:" + worker.Doc);
352
Console.WriteLine ("worker.IsFinished:" + worker.IsFinished);
353
Console.WriteLine ("worker.ManualResetEvent:" + worker.ManualResetEvent);