Esempio n. 1
0
        //int lastVersion = -1;
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            ITextSnapshot currentSnapshot = _buffer.CurrentSnapshot;

            SQCompileError error = null;
            bool           newversion;

            _languangeService.Parse(_buffer, out newversion, ref error);
            var ts = _languangeService.GetClassificationInfo(filepath);

            // int currentVersion = _buffer.CurrentSnapshot.Version.VersionNumber;
            List <SnapshotSpan> keywordspans   = new List <SnapshotSpan>();
            List <SnapshotSpan> nokeywordspans = new List <SnapshotSpan>();
            List <TagSpan <ClassificationTag> > _currentTags = new List <TagSpan <ClassificationTag> >();
            var cachekeys = _languangeService.GetKeywordSpans(filepath);

            if (cachekeys == null || newversion)
            {
                //_currentTags.Clear();
                var      textstructnav = _textStructureNavigatorSelector.GetTextStructureNavigator(_buffer);
                FindData fd            = new FindData();
                fd.TextStructureNavigator = textstructnav;
                fd.FindOptions            = FindOptions.WholeWord | FindOptions.MatchCase;
                foreach (SnapshotSpan curSpan in spans)
                {
                    fd.TextSnapshotToSearch = curSpan.Snapshot;
                    foreach (string key in _sqTypes.Keys)
                    {
                        fd.SearchString = key;
                        var result = _textSearchService.FindAll(fd);
                        keywordspans.AddRange(result);
                    }
                }
                _languangeService.SetKeywordCache(filepath, keywordspans.ToArray());
            }
            else
            {
                keywordspans.AddRange(cachekeys);
            }



            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 = currentSnapshot.GetLineFromLineNumber(scope.iStartLine);
                    var endLine   = currentSnapshot.GetLineFromLineNumber(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)
                {
                    SnapshotSpan snap = new SnapshotSpan(start.Value, length);
                    if (newversion)
                    {
                        TagsChanged(this, new SnapshotSpanEventArgs(snap));
                    }
                    switch (t.Item4)
                    {
                    case SQDeclarationType.AttributeScope:
                        nokeywordspans.Add(snap);
                        _currentTags.Add(new TagSpan <ClassificationTag>(snap, _attribtag));
                        break;

                    case SQDeclarationType.CommentScope:
                        nokeywordspans.Add(snap);
                        _currentTags.Add(new TagSpan <ClassificationTag>(snap, _commenttag));
                        break;

                    case SQDeclarationType.LiteralScope:
                        nokeywordspans.Add(snap);
                        _currentTags.Add(new TagSpan <ClassificationTag>(snap, _stringtag));
                        break;

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

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

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

                    case SQDeclarationType.Number:
                        _currentTags.Add(new TagSpan <ClassificationTag>(snap, _numberictag));
                        break;
                    }
                }
            }

            foreach (var kwspan in keywordspans)
            {
                bool cancel = false;
                foreach (var nokwspan in nokeywordspans)
                {
                    if (nokwspan.Contains(kwspan.Start.Position))//nokwspan.IntersectsWith(kwspan))
                    {
                        cancel = true;
                        break;
                    }
                }
                if (cancel)
                {
                    continue;
                }
                if (newversion)
                {
                    TagsChanged(this, new SnapshotSpanEventArgs(kwspan));
                }

                _currentTags.Add(new TagSpan <ClassificationTag>(kwspan, _keywordtag));
            }

            foreach (var t in _currentTags)
            {
                yield return(t);
            }
        }
Esempio n. 2
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            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;
             * }*/
        }
Esempio n. 3
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            ITextSnapshot currentSnapshot = _buffer.CurrentSnapshot;

            SQCompilerError error = null;
            bool            newversion;

            _languangeService.Parse(_buffer, out newversion, ref error);
            var ts = _languangeService.GetClassificationInfo(filepath);

            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 = currentSnapshot.GetLineFromLineNumber(scope.iStartLine);
                    var endLine   = currentSnapshot.GetLineFromLineNumber(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)
                {
                    SnapshotSpan snap = new SnapshotSpan(start.Value, length);
                    if (newversion)
                    {
                        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;
                    }
                }
            }
        }