コード例 #1
0
 private void ParseAndCache()
 {
     if (!Invalidated)
     {
         lock (Timer)
             Timer.Change(-1, -1);
         return;
     }
     try
     {
         Invalidated = false;
         var  snapshot = Buffer.CurrentSnapshot;
         bool validDsl;
         var  tokens            = SyntaxParser.GetTokens(snapshot, out validDsl);
         var  arr               = new ITagSpan <DddTokenTag> [tokens.Length];
         int  previousLine      = -1;
         ITextSnapshotLine line = null;
         for (int i = 0; i < tokens.Length; i++)
         {
             var d = tokens[i];
             var t = d.Concept;
             if (t.Line != previousLine)
             {
                 line         = snapshot.GetLineFromLineNumber(t.Line - 1);
                 previousLine = t.Line;
             }
             var span = new SnapshotSpan(snapshot, new Span(line.Start.Position + t.Column, t.Value.Length));
             arr[i] = new TagSpan <DddTokenTag>(span, d);
         }
         if (!validDsl)
         {
             if (TagsEqual(Tags, arr))
             {
                 return;
             }
         }
         if (Invalidated)
         {
             return;
         }
         Tags = arr;
         TagsChanged(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, Span.FromBounds(0, snapshot.Length))));
         lock (Timer)
             Timer.Change(1000, -1);
     }
     catch
     {
         lock (Timer)
             Timer.Change(5000, -1);
     }
 }
コード例 #2
0
        private static List <Completion> GetCompletitions(string rule)
        {
            if (Completitions.Count == 0)
            {
                lock (Completitions)
                {
                    foreach (var r in SyntaxParser.AllRules)
                    {
                        if (r.Children.Length > 0)
                        {
                            var list = new List <Completion>();
                            foreach (var c in r.Children)
                            {
                                var nr = SyntaxParser.Find(c);
                                if (nr != null)
                                {
                                    list.Add(new Completion(
                                                 PrettyRuleName(nr.Rule),
                                                 PrepareStaticGrammar(nr.Grammar),
                                                 nr.DescriptionAndGrammar,
                                                 null,
                                                 null));
                                }
                            }
                            if (list.Count > 0)
                            {
                                Completitions[r.Rule] = list;
                            }
                        }
                    }
                }
            }
            List <Completion> result;

            if (Completitions.TryGetValue(rule, out result))
            {
                return(result);
            }
            return(null);
        }
コード例 #3
0
        public void AugmentQuickInfoSession(
            IQuickInfoSession session,
            IList <object> quickInfoContent,
            out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (IsDisposed)
            {
                return;
            }

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(Buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            foreach (IMappingTagSpan <DddTokenTag> curTag in Aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                var t = curTag.Tag;
                if (t.Type != DddTokenTypes.Keyword && t.Type != DddTokenTypes.Identifier && t.Type != DddTokenTypes.StringQuote)
                {
                    continue;
                }
                var tagSpan = curTag.Span.GetSpans(Buffer).First();
                applicableToSpan = Buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                if (t.Parent != null)
                {
                    var rule  = t.Parent.Concept.Value;
                    var found = SyntaxParser.Find(rule);
                    if (found != null)
                    {
                        quickInfoContent.Add(found.DescriptionAndGrammar);
                    }
                }
            }
        }
コード例 #4
0
        private void ParseAndCache()
        {
            if (!Invalidated)
            {
                lock (Timer)
                    Timer.Change(-1, -1);
                return;
            }
            try
            {
                Invalidated = false;
                var newSnapshot = Buffer.CurrentSnapshot;
                var newRegions  = new List <Region>();

                PartialRegion currentRegion = null;
                bool          validDsl;
                var           tokens = SyntaxParser.GetExtensions(newSnapshot, out validDsl);
                if (Invalidated)
                {
                    return;
                }
                int       currentLevel = 0;
                var       levelInfo    = new List <LevelInfo>(tokens.Length / 16 + 2);
                LevelInfo lastInfo     = null;
                for (int i = 0; i < tokens.Length; i++)
                {
                    var t = tokens[i];
                    if (t.Type == SyntaxType.RuleExtension)
                    {
                        lastInfo = new LevelInfo();
                        if (currentLevel < levelInfo.Count)
                        {
                            levelInfo[currentLevel] = lastInfo;
                        }
                        else
                        {
                            levelInfo.Add(lastInfo);
                        }
                        currentLevel++;
                        currentRegion = new PartialRegion
                        {
                            Rule          = t.Value,
                            Level         = currentLevel,
                            StartLine     = t.Line - 1,
                            StartOffset   = t.Column,
                            PartialParent = currentRegion
                        };
                    }
                    else if (t.Type == SyntaxType.RuleEnd)
                    {
                        if (currentRegion == null)
                        {
                            continue;
                        }
                        lastInfo.Level--;
                        if (lastInfo.Level >= 0)
                        {
                            continue;
                        }
                        currentLevel--;
                        newRegions.Add(new Region
                        {
                            Rule        = t.Value,
                            IsNested    = lastInfo.IsNested,
                            Level       = currentLevel,
                            StartLine   = currentRegion.StartLine,
                            StartOffset = currentRegion.StartOffset,
                            EndLine     = t.Line - 1,
                            EndOffset   = t.Column - 1
                        });
                        lastInfo = currentLevel > 0 ? levelInfo[currentLevel - 1] : null;
                        if (lastInfo != null)
                        {
                            lastInfo.Level--;
                        }
                        currentRegion = currentRegion.PartialParent;
                    }
                    else if (lastInfo != null)
                    {
                        lastInfo.Level++;
                        lastInfo.IsNested = true;
                    }
                }
                if (Invalidated)
                {
                    return;
                }

                int changeStart = 0;
                int changeEnd   = newSnapshot.Length;

                if (!validDsl)
                {
                    var oldSpans = new Span[Regions.Length];
                    for (int i = 0; i < Regions.Length; i++)
                    {
                        oldSpans[i] = AsSnapshotSpan(Regions[i], Snapshot).TranslateTo(newSnapshot, SpanTrackingMode.EdgeExclusive).Span;
                    }
                    var newSpans = new Span[newRegions.Count];
                    for (int i = 0; i < newRegions.Count; i++)
                    {
                        newSpans[i] = AsSnapshotSpan(newRegions[i], newSnapshot).Span;
                    }

                    var oldSpanCollection = new NormalizedSpanCollection(oldSpans);
                    var newSpanCollection = new NormalizedSpanCollection(newSpans);

                    //the changed regions are regions that appear in one set or the other, but not both.
                    var removed = NormalizedSpanCollection.Difference(oldSpanCollection, newSpanCollection);

                    if (removed.Count > 0)
                    {
                        changeStart = removed[0].Start;
                        changeEnd   = removed[removed.Count - 1].End;
                    }

                    if (newSpans.Length > 0)
                    {
                        changeStart = Math.Min(changeStart, newSpans[0].Start);
                        changeEnd   = Math.Max(changeEnd, newSpans[newSpans.Length - 1].End);
                    }
                }
                if (Invalidated)
                {
                    return;
                }
                Snapshot = newSnapshot;
                Regions  = newRegions.ToArray();

                if (changeStart <= changeEnd)
                {
                    TagsChanged(this, new SnapshotSpanEventArgs(new SnapshotSpan(newSnapshot, Span.FromBounds(changeStart, changeEnd))));
                }
                lock (Timer)
                    Timer.Change(1000, -1);
            }
            catch
            {
                lock (Timer)
                    Timer.Change(5000, -1);
            }
        }