コード例 #1
0
ファイル: ColorQuickInfo.cs プロジェクト: molongwudi/Codist
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <Object> qiContent, out ITrackingSpan applicableToSpan)
        {
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.Color) == false)
            {
                goto EXIT;
            }
            var buffer    = session.TextView.TextBuffer;
            var snapshot  = session.TextView.TextSnapshot;
            var navigator = _NavigatorService.GetTextStructureNavigator(buffer);
            var extent    = navigator.GetExtentOfWord(session.GetTriggerPoint(snapshot).GetValueOrDefault()).Span;
            var word      = snapshot.GetText(extent);
            var brush     = ColorQuickInfo.GetBrush(word);

            if (brush == null)
            {
                if ((extent.Length == 6 || extent.Length == 8) && extent.Span.Start > 0 && Char.IsPunctuation(snapshot.GetText(extent.Span.Start - 1, 1)[0]))
                {
                    word = "#" + word;
                }
                brush = ColorQuickInfo.GetBrush(word);
            }
            if (brush != null)
            {
                qiContent.Add(ColorQuickInfo.PreviewColor(brush));
                applicableToSpan = snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeExclusive);
                return;
            }
EXIT:
            applicableToSpan = null;
        }
コード例 #2
0
        static async Task <QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var buffer    = session.TextView.TextBuffer;
            var snapshot  = session.TextView.TextSnapshot;
            var navigator = ServicesHelper.Instance.TextStructureNavigator.GetTextStructureNavigator(buffer);
            var extent    = navigator.GetExtentOfWord(session.GetTriggerPoint(snapshot).GetValueOrDefault()).Span;
            var word      = snapshot.GetText(extent);
            var brush     = ColorHelper.GetBrush(word);

            if (brush == null)
            {
                if ((extent.Length == 6 || extent.Length == 8) && extent.Span.Start > 0 && Char.IsPunctuation(snapshot.GetText(extent.Span.Start - 1, 1)[0]))
                {
                    word = "#" + word;
                }
                brush = ColorHelper.GetBrush(word);
            }
            return(brush != null && session.Mark(nameof(ColorQuickInfo))
                                ? new QuickInfoItem(extent.ToTrackingSpan(), ColorQuickInfo.PreviewColor(brush))
                                : null);
        }