示例#1
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            if (firsttime)
            {
                bool newversion;
                _languangeService.Parse(_buffer, out newversion);
                firsttime = false;
            }

            ITextSnapshot currentSnapshot = _buffer.CurrentSnapshot;

            var ts = _languangeService.GetClassificationInfo(filepath);

            var lines = currentSnapshot.Lines.ToArray();

            foreach (var t in ts)
            {
                TextSpan scope = t.Item2;
                if (t.Item4 == SQDeclarationType.Class ||
                    t.Item4 == SQDeclarationType.Enum)
                {
                    scope = t.Item1;
                }
                if (scope.iEndLine == -1 || scope.iStartLine == -1 ||
                    scope.iEndLine >= currentSnapshot.LineCount || scope.iStartLine >= currentSnapshot.LineCount)
                {
                    continue;
                }

                int           length         = 0;
                string        collpasedlabel = t.Item3;
                SnapshotPoint?start          = null;
                try
                {
                    var startLine = lines[scope.iStartLine];
                    var endLine   = lines[scope.iEndLine];
                    start  = startLine.Start + scope.iStartIndex;
                    length = (endLine.Start - startLine.Start) + scope.iEndIndex - scope.iStartIndex;
                    if (start.Value.Position + length >= currentSnapshot.Length)
                    {
                        length = currentSnapshot.Length - start.Value.Position;
                    }
                }
                catch (Exception)
                {
                    length = 0;
                }
                if (length > 0 && start != null)
                {
                    bool         update = false;
                    SnapshotSpan snap   = new SnapshotSpan(start.Value, length);
                    foreach (var nspan in spans)
                    {
                        var line = currentSnapshot.GetLineFromPosition(nspan.Start);
                        if (line.Extent.IntersectsWith(snap))
                        {
                            update = true;
                            break;
                        }
                    }
                    if (!update)
                    {
                        continue;
                    }

                    if (ForceNewVersion)
                    {
                        TagsChanged(this, new SnapshotSpanEventArgs(snap));
                    }
                    switch (t.Item4)
                    {
                    case SQDeclarationType.AttributeScope:
                        yield return(new TagSpan <ClassificationTag>(snap, _attribtag)); break;

                    case SQDeclarationType.CommentScope:
                        yield return(new TagSpan <ClassificationTag>(snap, _commenttag)); break;

                    case SQDeclarationType.LiteralScope:
                        yield return(new TagSpan <ClassificationTag>(snap, _stringtag)); break;

                    case SQDeclarationType.Extend:
                    case SQDeclarationType.Class:
                        yield return(new TagSpan <ClassificationTag>(snap, _classtag)); break;

                    case SQDeclarationType.Enum:
                        yield return(new TagSpan <ClassificationTag>(snap, _enumtag)); break;

                    case SQDeclarationType.SubName:
                        yield return(new TagSpan <ClassificationTag>(snap, _subnametag)); break;

                    case SQDeclarationType.Number:
                        yield return(new TagSpan <ClassificationTag>(snap, _numberictag)); break;

                    case SQDeclarationType.KeyWord:
                        yield return(new TagSpan <ClassificationTag>(snap, _keywordtag)); break;
                    }
                }
            }
            ForceNewVersion = false;

            /* if (cachekeys != null)
             * {
             *   foreach (var kwspan in cachekeys)
             *   {
             *       bool cancel = false;
             *       foreach (var nokwspan in nokeywordspans)
             *       {
             *           if (nokwspan.Contains(kwspan.Position))//nokwspan.IntersectsWith(kwspan))
             *           {
             *               cancel = true;
             *               break;
             *           }
             *       }
             *       if (cancel)
             *           yield break;
             *
             *       SnapshotSpan keysnap = new SnapshotSpan(currentSnapshot, kwspan.Position, kwspan.Length);
             *         if (ForceNewVersion)
             *       //   TagsChanged(this, new SnapshotSpanEventArgs(keysnap));
             *
             *       yield return new TagSpan<ClassificationTag>(keysnap, _keywordtag);
             *   }
             * }*/
            /*foreach (var t in _currentTags)
             * {
             *  yield return t;
             * }*/
        }
        public IEnumerable <ITagSpan <IOutliningRegionTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            ITextSnapshot currentSnapshot = _buffer.CurrentSnapshot;

            /*_CompilerError errors = null;
             * SQDeclaration sqdec = _languangeService.Parse(currentSnapshot.TextBuffer, ref errors);
             * if (sqdec == null)
             *  yield return null;
             * _textspans.Clear();
             * GetSpans(_textspans, sqdec);*/
            var ts = _languangeService.GetClassificationInfo(filepath);

            foreach (var t in ts)
            {
                SQDeclarationType type = t.Item4;
                if (type == SQDeclarationType.Class ||
                    type == SQDeclarationType.Function ||
                    type == SQDeclarationType.Scope ||
                    type == SQDeclarationType.AttributeScope ||
                    type == SQDeclarationType.Enum ||
                    type == SQDeclarationType.Constructor ||
                    type == SQDeclarationType.CommentScope)
                {
                    var scope = t.Item2;

                    if (scope.iStartLine == scope.iEndLine || scope.iEndLine == -1 || scope.iStartLine == -1 ||
                        scope.iEndLine >= currentSnapshot.LineCount || scope.iStartLine >= currentSnapshot.LineCount)
                    {
                        continue;
                    }

                    SnapshotSpan?snap           = null;
                    string       collpasedlabel = "...";
                    bool         collapsed      = type == SQDeclarationType.AttributeScope;
                    try
                    {
                        collpasedlabel = t.Item3;
                        var startLine = currentSnapshot.GetLineFromLineNumber(scope.iStartLine);
                        var endLine   = currentSnapshot.GetLineFromLineNumber(scope.iEndLine);
                        var start     = startLine.Start + scope.iStartIndex;
                        int length    = (endLine.Start - startLine.Start) + scope.iEndIndex - scope.iStartIndex;
                        if (start.Position + length >= currentSnapshot.Length)
                        {
                            length = currentSnapshot.Length - start.Position;
                        }
                        if (length > 0)
                        {
                            snap = new SnapshotSpan(start, length);
                        }
                    }
                    catch (Exception)
                    {
                        //this is a safe assumption as the currentsnapshot may have changed at this time
                    }

                    if (snap != null)
                    {
                        yield return(new TagSpan <IOutliningRegionTag>(snap.Value, new OutliningRegionTag(collapsed, collapsed, collpasedlabel, snap.Value.GetText())));
                    }
                }
            }
        }