Пример #1
0
        protected override async Task ProduceTagsAsync(TaggerContext <IClassificationTag> context, DocumentSnapshotSpan spanToTag, int?caretPosition)
        {
            var document = spanToTag.Document;
            var classificationService = document?.LanguageServices.GetService <IClassificationService>();

            if (classificationService == null)
            {
                return;
            }

            Workspace.TryGetWorkspace(document.SourceText.Container, out var workspace);

            var semanticModel = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);

            if (semanticModel == null)
            {
                return;
            }

            var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

            classificationService.AddSemanticClassifications(
                semanticModel,
                spanToTag.SnapshotSpan.Span.ToTextSpan(),
                workspace,
                classifiedSpans,
                context.CancellationToken);

            ClassificationUtilities.Convert(_typeMap, spanToTag.SnapshotSpan.Snapshot, classifiedSpans, context.AddTag);
            ClassificationUtilities.ReturnClassifiedSpanList(classifiedSpans);
        }
Пример #2
0
        protected override async Task ProduceTagsAsync(TaggerContext <IClassificationTag> context, DocumentSnapshotSpan spanToTag, int?caretPosition)
        {
            var document = spanToTag.Document;
            var classificationService = document?.LanguageServices.GetService <IClassificationService>();

            if (classificationService == null)
            {
                return;
            }

            var syntaxTree = await document.GetSyntaxTreeAsync(context.CancellationToken).ConfigureAwait(false);

            var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList();

            classificationService.AddSyntacticClassifications(
                syntaxTree,
                spanToTag.SnapshotSpan.Span.ToTextSpan(),
                classifiedSpans,
                context.CancellationToken);

            ClassificationUtilities.Convert(_typeMap, spanToTag.SnapshotSpan.Snapshot, classifiedSpans, context.AddTag);
            ClassificationUtilities.ReturnClassifiedSpanList(classifiedSpans);
        }