~ubuntu-branches/ubuntu/quantal/monodevelop/quantal

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2011-06-29 06:56:25 UTC
  • mfrom: (1.8.1 upstream) (1.3.11 experimental)
  • Revision ID: james.westby@ubuntu.com-20110629065625-7xx19c4vb95j65pl
Tags: 2.5.92+dfsg-1ubuntu1
* Merge from Debian experimental:
 - Dropped patches & changes to debian/control for Moonlight
   + debian/patches/remove_support_for_moonlight.patch,
   + debian/patches/dont_add_moonlight_to_core_addins.patch,
 - Remaining patches:
   + debian/patches/no_appmenu:

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
                        }
180
180
                }
181
181
                
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)
183
183
                {
184
184
                        SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack);
185
185
                        parser.ParseSpans (start, end - start);
186
186
                }
187
187
                
188
 
                static bool IsEqual (Span[] spans1, Span[] spans2)
189
 
                {
190
 
                        if (spans1 == null || spans1.Length == 0) 
191
 
                                return spans2 == null || spans2.Length == 0;
192
 
                        if (spans2 == null || spans1.Length != spans2.Length)
193
 
                                return false;
194
 
                        for (int i = 0; i < spans1.Length; i++) {
195
 
                                if (spans1[i] != spans2[i]) {
196
 
                                        return false;
197
 
                                }
198
 
                        }
199
 
                        return true;
200
 
                }
201
 
                
202
188
                static Queue<UpdateWorker> updateQueue = new Queue<UpdateWorker> ();
203
189
                
204
190
                class UpdateWorker
231
217
                                ManualResetEvent = new ManualResetEvent (false);
232
218
                        }
233
219
                        
234
 
                        protected void ScanSpansThreaded (Document doc, Rule rule, Stack<Span> spanStack, int start, int end)
235
 
                        {
236
 
                                SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack);
237
 
                                parser.ParseSpans (start, end - start);
238
 
                        }
239
220
                        
240
221
                        bool EndsWithContinuation (Span span, LineSegment line)
241
222
                        {
246
227
                        public void InnerRun ()
247
228
                        {
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);
 
231
                                if (startLine < 0)
251
232
                                        return;
252
 
                                Stack<Span> spanStack = iter.Current.StartSpan != null ? new Stack<Span> (iter.Current.StartSpan) : new Stack<Span> ();
253
233
                                try {
254
 
                                        LineSegment oldLine = iter.Current.Offset > 0 ? doc.GetLineByOffset (iter.Current.Offset - 1) : null;
255
 
                                        do {
256
 
                                                LineSegment line = iter.Current;
257
 
                                                if (line == null || line.Offset < 0)
258
 
                                                        break;
259
 
                                                
260
 
                                                List<Span> spanList = new List<Span> (spanStack.ToArray ());
261
 
                                                spanList.Reverse ();
262
 
                                                for (int i = 0; i < spanList.Count; i++) {
263
 
                                                        if (!EndsWithContinuation (spanList[i], oldLine)) {
264
 
                                                                spanList.RemoveAt (i);
265
 
                                                                i--;
266
 
                                                        }
267
 
                                                }
268
 
                                                Span[] newSpans = spanList.ToArray ();
 
234
                                        var lineSegment = doc.GetLine (startLine);
 
235
                                        if (lineSegment == null)
 
236
                                                return;
 
237
                                        var span = lineSegment.StartSpan;
 
238
                                        if (span == null)
 
239
                                                return;
 
240
                                        var spanStack = span.Clone ();
 
241
                                        SyntaxMode.SpanParser parser = mode.CreateSpanParser(doc, mode, null, spanStack);
 
242
                                        foreach (var line in doc.GetLinesStartingAt (startLine)) {
 
243
                                                if (line == null)
 
244
                                                        return;
269
245
                                                if (line.Offset > endOffset) {
270
 
                                                        bool equal = IsEqual (line.StartSpan, newSpans);
271
 
                                                        doUpdate |= !equal;
272
 
                                                        if (equal)
273
 
                                                                break;
274
 
                                                }
275
 
                                                line.StartSpan = newSpans.Length > 0 ? newSpans : null;
276
 
                                                oldLine = line;
277
 
                                                Rule rule = mode;
278
 
                                                if (spanStack.Count > 0 && !String.IsNullOrEmpty (spanStack.Peek ().Rule))
279
 
                                                        rule = mode.GetRule (spanStack.Peek ().Rule) ?? mode;
280
 
                                                
281
 
                                                ScanSpansThreaded (doc, rule, spanStack, line.Offset, line.EndOffset);
282
 
                                                while (spanStack.Count > 0 && !EndsWithContinuation (spanStack.Peek (), line))
283
 
                                                        spanStack.Pop ();
284
 
                                        
285
 
                                        } while (iter.MoveNext ());
 
246
                                                        span = line.StartSpan;
 
247
                                                        if (span == null)
 
248
                                                                return;
 
249
                                                        bool equal = span.Equals(spanStack);
 
250
                                                        doUpdate |= !equal;
 
251
                                                        if (equal)
 
252
                                                                break;
 
253
                                                }
 
254
                                                line.StartSpan = spanStack.Clone();
 
255
                                                parser.ParseSpans(line.Offset, line.Length);
 
256
                                                while (spanStack.Count > 0 && !EndsWithContinuation(spanStack.Peek(), line))
 
257
                                                        parser.PopSpan();
 
258
                                        }
286
259
                                } catch (Exception e) {
287
260
                                        Console.WriteLine ("Syntax highlighting exception:" + e);
288
261
                                }
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);
354
321
                                }
355
322
                        }
356
323
                }