コード例 #1
0
            public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                var firstSpan = spans.FirstOrDefault();

                if (firstSpan.Snapshot != null)
                {
                    var window = firstSpan.Snapshot.TextBuffer.GetInteractiveWindow();
                    if (window == null || !((IContentType)window.Properties[typeof(IContentType)]).TypeName.EqualsOrdinal(RContentTypeDefinition.ContentType))
                    {
                        yield break;
                    }
                }

                foreach (var span in spans)
                {
                    // prompts are inserted directly into the input buffer as inert text
                    var matches = _view.BufferGraph.MapDownToFirstMatch(span, SpanTrackingMode.EdgeInclusive, x => x.TextBuffer.ContentType.IsOfType("inert"));
                    foreach (var match in matches)
                    {
                        var trimmedLength = match.GetText().TrimEnd(_trimChars).Length;
                        var targetSpan    = new SnapshotSpan(match.Snapshot, match.Start, trimmedLength);

                        foreach (var upperMatch in _view.BufferGraph.MapUpToBuffer(targetSpan, SpanTrackingMode.EdgeInclusive, span.Snapshot.TextBuffer))
                        {
                            yield return(new TagSpan <ClassificationTag>(
                                             upperMatch,
                                             _tag
                                             ));
                        }
                    }
                }
            }
コード例 #2
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            var globalSpan = spans.FirstOrDefault();

            foreach (var tagSpan in this._aggregator.GetTags(spans))
            {
                IClassificationType classification = null;
                switch (tagSpan.Tag.Type)
                {
                case TokenType.Literal:
                    classification = _standardClassifications.Literal;
                    break;

                case TokenType.Operator:
                    classification = _standardClassifications.Operator;
                    break;

                case TokenType.BooleanLiteral:
                case TokenType.Keyword:
                    classification = _standardClassifications.Keyword;
                    break;

                case TokenType.Comment:
                    classification = _standardClassifications.Comment;
                    break;

                case TokenType.Identifier:
                    classification = _standardClassifications.Identifier;
                    break;

                case TokenType.StringLiteral:
                    classification = _standardClassifications.StringLiteral;
                    break;

                case TokenType.NumberLiteral:
                    classification = _standardClassifications.NumberLiteral;
                    break;

                case TokenType.Method:
                    classification = _standardClassifications.SymbolDefinition;
                    break;

                case TokenType.FormalReferenceEnd:
                case TokenType.FormalReferenceStart:
                case TokenType.Punctuator:
                    continue;

                default:
                    continue;
#if DEBUG
                    throw new InvalidOperationException();
#endif
                }
                var span = tagSpan.Span.GetSpans(globalSpan.Snapshot)[0];
                yield return(new TagSpan <ClassificationTag>(span, new ClassificationTag(classification)));
            }
            yield break;
        }
コード例 #3
0
            private void UpdateAtCaretPosition(CaretPosition caretPosition)
            {
                SnapshotPoint?point = caretPosition.Point.GetPoint(SourceBuffer, caretPosition.Affinity);

                if (point == null)
                {
                    return;
                }

                if (_highlightedSpans?.FirstOrDefault().Snapshot == SourceBuffer.CurrentSnapshot &&
                    (_highlightedSpans?.Any(s => s.Contains(point.Value)) ?? false))
                {
                    return;
                }

                NormalizedSnapshotSpanCollection newHighlightedSpans = null;

                this.HtmlDocument.HtmlEditorTree.GetPositionElement(point.Value.Position, out _, out AttributeNode attribute);

                if ((attribute?.ValueRangeUnquoted.Contains(point.Value.Position) ?? false) ||
                    (attribute?.ValueRangeUnquoted.End == point.Value.Position))
                {
                    if (attribute.Name?.Equals("class", StringComparison.InvariantCultureIgnoreCase) ?? false)
                    {
                        int relativeIndex = point.Value.Position - attribute.ValueRangeUnquoted.Start;

                        // find definitions
                        string @class = ClassRegex.Matches(attribute.Value)
                                        .Cast <Match>()
                                        .FirstOrDefault(m => m.Index <= relativeIndex && relativeIndex <= m.Index + m.Length)?
                                        .Value;

                        // find references
                        if (@class != null)
                        {
                            newHighlightedSpans = new NormalizedSnapshotSpanCollection(FindReferences(@class, point.Value.Snapshot));
                        }
                    }
                }

                _highlightedSpans = newHighlightedSpans;

                TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(SourceBuffer.CurrentSnapshot, 0, SourceBuffer.CurrentSnapshot.Length)));
            }
コード例 #4
0
            private void UpdateAtCaretPosition(CaretPosition caretPosition)
            {
                SnapshotPoint?point = caretPosition.Point.GetPoint(SourceBuffer, caretPosition.Affinity);

                if (point == null)
                {
                    return;
                }

                if (_highlightedSpans?.FirstOrDefault().Snapshot == SourceBuffer.CurrentSnapshot &&
                    (_highlightedSpans?.Any(s => s.Contains(point.Value)) ?? false))
                {
                    return;
                }

                NormalizedSnapshotSpanCollection newHighlightedSpans = null;

                this.HtmlDocument.HtmlEditorTree.GetPositionElement(point.Value.Position, out ElementNode element, out AttributeNode attribute);

                if ((attribute?.ValueRangeUnquoted.Contains(point.Value.Position) ?? false) ||
                    (attribute?.ValueRangeUnquoted.End == point.Value.Position))
                {
                    if (attribute.Name?.Equals("name", StringComparison.InvariantCultureIgnoreCase) ?? false)
                    {
                        if ((element?.Name.Equals("input", StringComparison.InvariantCultureIgnoreCase) ?? false) &&
                            (element?.GetAttribute("type")?.Value?.Equals("radio", StringComparison.InvariantCultureIgnoreCase) ?? false))
                        {
                            string name = attribute.Value;

                            // find references
                            newHighlightedSpans = new NormalizedSnapshotSpanCollection(FindReferences(name, point.Value.Snapshot));
                        }
                    }
                }

                _highlightedSpans = newHighlightedSpans;

                TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(SourceBuffer.CurrentSnapshot, 0, SourceBuffer.CurrentSnapshot.Length)));
            }
コード例 #5
0
        IEnumerable <ITagSpan <ClippyTag> > ITagger <ClippyTag> .GetTags(NormalizedSnapshotSpanCollection spans)
        {
            try
            {
                if (spans == null || spans.FirstOrDefault() == null)
                {
                    return(null);
                }

                if (spans.FirstOrDefault().Snapshot.ContentType.TypeName != "SQL Server Tools")
                {
                    return(null);
                }

                var items = new List <ITagSpan <ClippyTag> >();

                if (_lastCallTime.AddMilliseconds(_lastCallDelay) >= DateTime.Now)
                {
                    return(_lastSpans);
                }

                _lastCallTime = DateTime.Now;

                if (!Monitor.TryEnter(_lock))
                {
                    return(_lastSpans);
                }

                var dte = VsServiceProvider.Get(typeof(DTE));


                if (null == dte || !ClippySettings.Enabled)
                {
                    Monitor.Exit(_lock);
                    return(_lastSpans);
                }

                //if (_store == null)
                //{
                //    _store = new TagStore();
                //    Monitor.Exit(_lock);
                //    return _lastSpans;
                //}

                if (_store.Stopped)
                {
                    _store.Stopped = false;
                    Monitor.Exit(_lock);
                    return(_lastSpans);
                }


                var text = spans.FirstOrDefault().Snapshot.GetText();

                var glyphs = new OperationsBuilder(spans.FirstOrDefault().Snapshot, _store).GetStatementOptions(text);

                foreach (var g in glyphs)
                {
                    if (g.Menu.Count == 0)
                    {
                        continue;
                    }

                    var tag = new ClippyTag(g);

                    var tagSpan = new TagSpan <ClippyTag>(new SnapshotSpan(spans.FirstOrDefault().Snapshot, g.StatementOffset, g.StatementLength), tag);
                    tag.Tagger            = this;
                    tagSpan.Tag.ParentTag = tagSpan;
                    g.Tag = tagSpan.Tag;
                    items.Add(tagSpan);
                }

                Monitor.Exit(_lock);
                _lastSpans = items;
                return(items);
            }
            catch (Exception)
            {
                Monitor.Exit(_lock);
                return(null);
            }
        }
コード例 #6
0
ファイル: ErrorTaskProvider.cs プロジェクト: cmrazek/DkTools
        public IEnumerable <ITagSpan <ErrorTag> > GetErrorTagsForFile(string fileName, NormalizedSnapshotSpanCollection docSpans)
        {
            var tags = new List <TagSpan <ErrorTag> >();

            var firstSpan = docSpans.FirstOrDefault();

            if (firstSpan == null)
            {
                return(tags);
            }
            var snapshot = firstSpan.Snapshot;

            ErrorTask[] tasks;
            lock (_tasksLock)
            {
                tasks = Tasks.Cast <ErrorTask>().ToArray();
            }

            foreach (var task in (from t in tasks where string.Equals(t.Document, fileName, StringComparison.OrdinalIgnoreCase) select t))
            {
                var span = task.Span;
                if (span.HasValue)
                {
                    foreach (var docSpan in docSpans)
                    {
                        var spanT = new SnapshotSpan(task.GetSnapshot(snapshot), span.Value.Start, span.Value.Length).TranslateTo(docSpan.Snapshot, SpanTrackingMode.EdgeExclusive);
                        if (docSpan.Contains(spanT.Start))
                        {
                            string tagType;
                            switch (task.Type)
                            {
                            case ErrorType.Warning:
                                tagType = VSTheme.CurrentTheme == VSThemeMode.Light ? ErrorTagger.CodeWarningLight : ErrorTagger.CodeWarningDark;
                                break;

                            case ErrorType.CodeAnalysisError:
                                tagType = VSTheme.CurrentTheme == VSThemeMode.Light ? ErrorTagger.CodeAnalysisErrorLight : ErrorTagger.CodeAnalysisErrorDark;
                                break;

                            default:
                                tagType = VSTheme.CurrentTheme == VSThemeMode.Light ? ErrorTagger.CodeErrorLight : ErrorTagger.CodeErrorDark;
                                break;
                            }
                            tags.Add(new TagSpan <ErrorTag>(task.GetSnapshotSpan(snapshot), new ErrorTag(tagType, task.Text)));
                            break;
                        }
                    }
                }
                else
                {
                    var line = task.GetSnapshot(snapshot).GetLineFromLineNumber(task.Line);
                    foreach (var docSpan in docSpans)
                    {
                        var spanLineStart = line.Start.TranslateTo(docSpan.Snapshot, PointTrackingMode.Negative);
                        if (docSpan.Contains(spanLineStart.Position))
                        {
                            var errorCode = task.Type == ErrorType.Warning ? ErrorCode.Fec_Warning : ErrorCode.Fec_Error;

                            var spanLine = docSpan.Snapshot.GetLineFromPosition(spanLineStart);
                            var startPos = spanLine.Start.Position;
                            var endPos   = spanLine.End.Position;
                            if (startPos < endPos)
                            {
                                var newStartPos = spanLine.Start.Position + spanLine.GetText().GetIndentOffset();
                                if (newStartPos < endPos)
                                {
                                    startPos = newStartPos;
                                }
                            }

                            string tagType;
                            switch (task.Type)
                            {
                            case ErrorType.Warning:
                                tagType = VSTheme.CurrentTheme == VSThemeMode.Light ? ErrorTagger.CodeWarningLight : ErrorTagger.CodeWarningDark;
                                break;

                            case ErrorType.CodeAnalysisError:
                                tagType = VSTheme.CurrentTheme == VSThemeMode.Light ? ErrorTagger.CodeAnalysisErrorLight : ErrorTagger.CodeAnalysisErrorDark;
                                break;

                            default:
                                tagType = VSTheme.CurrentTheme == VSThemeMode.Light ? ErrorTagger.CodeErrorLight : ErrorTagger.CodeErrorDark;
                                break;
                            }

                            tags.Add(new TagSpan <ErrorTag>(new SnapshotSpan(docSpan.Snapshot, startPos, endPos - startPos),
                                                            new ErrorTag(tagType, task.Text)));
                            break;
                        }
                    }
                }
            }

            return(tags);
        }