コード例 #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);
            }
        }
コード例 #2
0
ファイル: 34.cs プロジェクト: qnsoftware/visualsquirrel
        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;
                    }
                }
            }
        }