コード例 #1
0
        protected override Task ProduceTagsAsync(TaggerContext <IClassificationTag> context)
        {
            Debug.Assert(context.SpansToTag.IsSingle());

            var spanToTag = context.SpansToTag.Single();

            var document = spanToTag.Document;

            // Attempt to get a classification service which will actually produce the results.
            // If we can't (because we have no Document, or because the language doesn't support
            // this service), then bail out immediately.
            var classificationService = document?.GetLanguageService <IClassificationService>();

            if (classificationService == null)
            {
                return(Task.CompletedTask);
            }

            // The LSP client will handle producing tags when running under the LSP editor.
            // Our tagger implementation should return nothing to prevent conflicts.
            var workspaceContextService = document?.Project.Solution.Workspace.Services.GetRequiredService <IWorkspaceContextService>();

            if (workspaceContextService?.IsInLspEditorContext() == true)
            {
                return(Task.CompletedTask);
            }

            return(SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, classificationService, _typeMap));
        }
コード例 #2
0
            private static Task ProduceTagsAsync(TaggerContext <IClassificationTag> context, DocumentSnapshotSpan documentSpan, ClassificationTypeMap typeMap)
            {
                var classificationService = documentSpan.Document.GetLanguageService <IClassificationService>();

                return(classificationService != null
                    ? SemanticClassificationUtilities.ProduceTagsAsync(context, documentSpan, classificationService, typeMap)
                    : Task.CompletedTask);
            }
コード例 #3
0
            public IEnumerable <ITagSpan <IClassificationTag> > GetAllTags(NormalizedSnapshotSpanCollection spans, CancellationToken cancellationToken)
            {
                this.AssertIsForeground();
                if (spans.Count == 0)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                var firstSpan = spans.First();
                var snapshot  = firstSpan.Snapshot;

                Debug.Assert(snapshot.TextBuffer == _subjectBuffer);

                // We want to classify from the start of the first requested span to the end of the
                // last requested span.
                var spanToTag = new SnapshotSpan(snapshot,
                                                 Span.FromBounds(spans.First().Start, spans.Last().End));

                // We don't need to actually classify if what we're being asked for is a subspan
                // of the last classification we performed.
                var cachedTaggedSpan = this.CachedTaggedSpan;
                var canReuseCache    =
                    cachedTaggedSpan?.Snapshot == snapshot &&
                    cachedTaggedSpan.Value.Contains(spanToTag);

                if (!canReuseCache)
                {
                    // Our cache is not there, or is out of date.  We need to compute the up to date
                    // results.

                    var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document == null)
                    {
                        return(Array.Empty <ITagSpan <IClassificationTag> >());
                    }

                    _classificationService = _classificationService ?? document.Project.LanguageServices.GetService <IEditorClassificationService>();

                    var context = new TaggerContext <IClassificationTag>(document, snapshot, cancellationToken: cancellationToken);

                    var task = SemanticClassificationUtilities.ProduceTagsAsync(
                        context, new DocumentSnapshotSpan(document, spanToTag),
                        _classificationService, _owner._typeMap);
                    task.Wait(cancellationToken);

                    CachedTaggedSpan = spanToTag;
                    CachedTags       = new TagSpanIntervalTree <IClassificationTag>(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans);
                }

                if (this.CachedTags == null)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                return(this.CachedTags.GetIntersectingTagSpans(spans));
            }
        protected override Task ProduceTagsAsync(TaggerContext <IClassificationTag> context)
        {
            Debug.Assert(context.SpansToTag.IsSingle());

            var spanToTag = context.SpansToTag.Single();
            var document  = spanToTag.Document;

            _classificationService = _classificationService ?? document.Project.LanguageServices.GetService <IEditorClassificationService>();

            return(SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, _classificationService, _typeMap));
        }
コード例 #5
0
            private Task ProduceTagsAsync <TClassificationService>(
                TaggerContext <IClassificationTag> context,
                DocumentSnapshotSpan documentSpan,
                ClassificationTypeMap typeMap,
                IClassificationDelegationService <TClassificationService> delegationService) where TClassificationService : class, ILanguageService
            {
                var document = documentSpan.Document;

                var classificationService = document.GetLanguageService <TClassificationService>();

                if (classificationService != null)
                {
                    return(SemanticClassificationUtilities.ProduceTagsAsync(
                               context, documentSpan, delegationService, classificationService, typeMap));
                }

                return(SpecializedTasks.EmptyTask);
            }
            public IEnumerable <ITagSpan <IClassificationTag> > GetAllTags(NormalizedSnapshotSpanCollection spans, CancellationToken cancellationToken)
            {
                this.AssertIsForeground();
                if (spans.Count == 0)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                var firstSpan = spans.First();
                var snapshot  = firstSpan.Snapshot;

                Debug.Assert(snapshot.TextBuffer == _subjectBuffer);

                var cachedSnapshot = this.CachedSnapshot;

                if (snapshot != cachedSnapshot)
                {
                    // Our cache is not there, or is out of date.  We need to compute the up to date
                    // results.

                    var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document == null)
                    {
                        return(Array.Empty <ITagSpan <IClassificationTag> >());
                    }

                    _classificationService = _classificationService ?? document.Project.LanguageServices.GetService <IEditorClassificationService>();

                    var context   = new TaggerContext <IClassificationTag>(document, snapshot, cancellationToken: cancellationToken);
                    var spanToTag = new DocumentSnapshotSpan(document, snapshot.GetFullSpan());
                    var task      = SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, _classificationService, _owner._typeMap);
                    task.Wait(cancellationToken);

                    CachedSnapshot = snapshot;
                    CachedTags     = new TagSpanIntervalTree <IClassificationTag>(snapshot.TextBuffer, SpanTrackingMode.EdgeExclusive, context.tagSpans);
                }

                if (this.CachedTags == null)
                {
                    return(Array.Empty <ITagSpan <IClassificationTag> >());
                }

                return(this.CachedTags.GetIntersectingTagSpans(spans));
            }
コード例 #7
0
        protected override Task ProduceTagsAsync(TaggerContext <IClassificationTag> context)
        {
            Debug.Assert(context.SpansToTag.IsSingle());

            var spanToTag = context.SpansToTag.Single();

            // Attempt to get a classification service which will actually produce the results.
            // If we can't (because we have no Document, or because the language doesn't support
            // this service), then bail out immediately.
            var document = spanToTag.Document;
            var classificationService = document?.Project.LanguageServices.GetService <IEditorClassificationService>();

            if (classificationService == null)
            {
                return(SpecializedTasks.EmptyTask);
            }

            return(SemanticClassificationUtilities.ProduceTagsAsync(context, spanToTag, classificationService, _typeMap));
        }
コード例 #8
0
        private Task ProduceTagsAsync <TClassificationService>(
            TaggerContext <IClassificationTag> context,
            DocumentSnapshotSpan spanToTag,
            IClassificationDelegationService <TClassificationService> delegationService)
            where TClassificationService : class, ILanguageService
        {
            var document = spanToTag.Document;

            // Attempt to get a classification service which will actually produce the results.
            // If we can't (because we have no Document, or because the language doesn't support
            // this service), then bail out immediately.
            var classificationService = document?.GetLanguageService <TClassificationService>();

            if (classificationService == null)
            {
                return(SpecializedTasks.EmptyTask);
            }

            return(SemanticClassificationUtilities.ProduceTagsAsync(
                       context, spanToTag, delegationService, classificationService, _typeMap));
        }