public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                using (Logger.LogBlock(FunctionId.Tagger_SyntacticClassification_TagComputer_GetTags, CancellationToken.None))
                {
                    if (spans.Count > 0 && _workspace != null)
                    {
                        var firstSpan        = spans[0];
                        var languageServices = _workspace.Services.GetLanguageServices(firstSpan.Snapshot.ContentType);
                        if (languageServices != null)
                        {
                            var classificationService = languageServices.GetService <IEditorClassificationService>();

                            if (classificationService != null)
                            {
                                var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

                                foreach (var span in spans)
                                {
                                    AddClassifiedSpans(classificationService, span, classifiedSpans);
                                }

                                return(ClassificationUtilities.ConvertAndReturnList(_typeMap, spans[0].Snapshot, classifiedSpans));
                            }
                        }
                    }

                    return(SpecializedCollections.EmptyEnumerable <ITagSpan <IClassificationTag> >());
                }
            }
            public override async Task <IEnumerable <ITagSpan <IClassificationTag> > > ProduceTagsAsync(
                Document document,
                SnapshotSpan snapshotSpan,
                int?caretPosition,
                CancellationToken cancellationToken)
            {
                try
                {
                    var snapshot = snapshotSpan.Snapshot;
                    if (document == null)
                    {
                        return(SpecializedCollections.EmptyEnumerable <ITagSpan <IClassificationTag> >());
                    }

                    if (_classificationService == null)
                    {
                        _classificationService = document.Project.LanguageServices.GetService <IEditorClassificationService>();
                    }

                    if (_classificationService == null)
                    {
                        return(SpecializedCollections.EmptyEnumerable <ITagSpan <IClassificationTag> >());
                    }

                    // we don't directly reference the semantic model here, we just keep it alive so
                    // the classification service does not need to block to produce it.
                    using (Logger.LogBlock(FunctionId.Tagger_SemanticClassification_TagProducer_ProduceTags, cancellationToken))
                    {
                        var textSpan         = snapshotSpan.Span.ToTextSpan();
                        var extensionManager = document.Project.Solution.Workspace.Services.GetService <IExtensionManager>();

                        var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

                        await _classificationService.AddSemanticClassificationsAsync(
                            document, textSpan, classifiedSpans, cancellationToken : cancellationToken).ConfigureAwait(false);

                        return(ClassificationUtilities.ConvertAndReturnList(_typeMap, snapshotSpan.Snapshot, classifiedSpans));
                    }
                }
                catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
            private IEnumerable <ITagSpan <IClassificationTag> > GetTagsWorker(NormalizedSnapshotSpanCollection spans)
            {
                var classificationService = TryGetClassificationService(spans[0].Snapshot);

                if (classificationService == null)
                {
                    return(null);
                }

                var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

                foreach (var span in spans)
                {
                    AddClassifiedSpans(classificationService, span, classifiedSpans);
                }

                return(ClassificationUtilities.ConvertAndReturnList(
                           _typeMap, spans[0].Snapshot, classifiedSpans));
            }
Ejemplo n.º 4
0
            public IEnumerable <ITagSpan <IClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
            {
                using (Logger.LogBlock(FunctionId.Tagger_SyntacticClassification_TagComputer_GetTags, CancellationToken.None))
                {
                    if (!_cachedTaggableStatus.HasValue)
                    {
                        if (!_isClassificationOnlyWorkspace)
                        {
                            _cachedTaggableStatus = true;
                        }
                        else
                        {
                            var wpfTextViews = _associatedViewService.GetAssociatedTextViews(_subjectBuffer);
                            if (wpfTextViews.Any())
                            {
                                _cachedTaggableStatus = _viewSupportsClassificationServiceOpt?.CanClassifyViews(wpfTextViews.Cast <ITextView>()) ?? true;
                            }
                        }
                    }

                    if (_cachedTaggableStatus == false)
                    {
                        return(SpecializedCollections.EmptyEnumerable <ITagSpan <IClassificationTag> >());
                    }

                    if (spans.Count > 0)
                    {
                        var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

                        foreach (var span in spans)
                        {
                            AddClassifiedSpans(_editorClassificationService, span, classifiedSpans);
                        }

                        return(ClassificationUtilities.ConvertAndReturnList(_typeMap, spans[0].Snapshot, classifiedSpans));
                    }

                    return(SpecializedCollections.EmptyEnumerable <ITagSpan <IClassificationTag> >());
                }
            }
            private IEnumerable <ITagSpan <IClassificationTag> > GetTags <TClassificationService>(
                NormalizedSnapshotSpanCollection spans,
                HostLanguageServices languageServices,
                IClassificationDelegationService <TClassificationService> delegationService) where TClassificationService : class, ILanguageService
            {
                var classificationService = languageServices.GetService <TClassificationService>();

                if (classificationService == null)
                {
                    return(null);
                }

                var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

                foreach (var span in spans)
                {
                    AddClassifiedSpans(delegationService, classificationService, span, classifiedSpans);
                }

                return(ClassificationUtilities.ConvertAndReturnList(
                           _typeMap, spans[0].Snapshot, classifiedSpans));
            }