Esempio n. 1
0
            public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, CancellationToken cancellationToken)
            {
                var options = await _context.GetOptionsAsync(document.Project.Language, cancellationToken).ConfigureAwait(false);

                var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync(
                    document, span, options.ClassificationOptions, cancellationToken).ConfigureAwait(false);

                await _context.OnReferenceFoundAsync(
                    new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false);
            }
Esempio n. 2
0
        public static async Task <ValueTrackedItem?> TryCreateAsync(Document document, TextSpan textSpan, ISymbol symbol, ValueTrackedItem?parent = null, CancellationToken cancellationToken = default)
        {
            var        excerptService = document.Services.GetService <IDocumentExcerptService>();
            SourceText?sourceText     = null;
            ImmutableArray <ClassifiedSpan> classifiedSpans = default;

            if (excerptService != null)
            {
                var result = await excerptService.TryExcerptAsync(document, textSpan, ExcerptMode.SingleLine, cancellationToken).ConfigureAwait(false);

                if (result.HasValue)
                {
                    var value = result.Value;
                    sourceText = value.Content;
                }
            }

            if (sourceText is null)
            {
                var options      = ClassificationOptions.From(document.Project);
                var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync(document, textSpan, options, cancellationToken).ConfigureAwait(false);

                var classificationResult = await ClassifiedSpansAndHighlightSpanFactory.ClassifyAsync(documentSpan, options, cancellationToken).ConfigureAwait(false);

                classifiedSpans = classificationResult.ClassifiedSpans;
                var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

                sourceText = await syntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
            }

            return(new ValueTrackedItem(
                       SymbolKey.Create(symbol, cancellationToken),
                       sourceText,
                       classifiedSpans,
                       textSpan,
                       document.Id,
                       symbol.GetGlyph(),
                       parent: parent));
        }