Exemple #1
0
            private async Task <(ExcerptResult, SourceText)> ExcerptAsync(SourceText sourceText, DocumentSpan documentSpan)
            {
                var excerptService = documentSpan.Document.Services.GetService <IDocumentExcerptService>();

                if (excerptService != null)
                {
                    var result = await excerptService.TryExcerptAsync(documentSpan.Document, documentSpan.SourceSpan, ExcerptMode.SingleLine, CancellationToken).ConfigureAwait(false);

                    if (result != null)
                    {
                        return(result.Value, AbstractDocumentSpanEntry.GetLineContainingPosition(result.Value.Content, result.Value.MappedSpan.Start));
                    }
                }

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

                // need to fix the span issue tracking here - https://github.com/dotnet/roslyn/issues/31001
                var excerptResult = new ExcerptResult(
                    sourceText,
                    classificationResult.HighlightSpan,
                    classificationResult.ClassifiedSpans,
                    documentSpan.Document,
                    documentSpan.SourceSpan);

                return(excerptResult, AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start));
            }
Exemple #2
0
        public async Task <ExcerptResult?> TryExcerptAsync(
            Document document,
            TextSpan span,
            ExcerptMode mode,
            CancellationToken cancellationToken
            )
        {
            var razorMode = mode switch
            {
                ExcerptMode.SingleLine => RazorExcerptMode.SingleLine,
                ExcerptMode.Tooltip => RazorExcerptMode.Tooltip,
                _ => throw new InvalidEnumArgumentException($"Unsupported enum type {mode}."),
            };
            var nullableRazorExcerpt = await _razorDocumentExcerptService
                                       .TryExcerptAsync(document, span, razorMode, cancellationToken)
                                       .ConfigureAwait(false);

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

            var razorExcerpt  = nullableRazorExcerpt.Value;
            var roslynExcerpt = new ExcerptResult(
                razorExcerpt.Content,
                razorExcerpt.MappedSpan,
                razorExcerpt.ClassifiedSpans,
                razorExcerpt.Document,
                razorExcerpt.Span
                );

            return(roslynExcerpt);
        }
Exemple #3
0
            public static DocumentSpanEntry?TryCreate(
                AbstractTableDataSourceFindUsagesContext context,
                RoslynDefinitionBucket definitionBucket,
                DocumentSpan documentSpan,
                HighlightSpanKind spanKind,
                MappedSpanResult mappedSpanResult,
                ExcerptResult excerptResult,
                SourceText lineText,
                SymbolUsageInfo symbolUsageInfo,
                ImmutableDictionary <string, string> customColumnsData
                )
            {
                var document = documentSpan.Document;

                var(guid, projectName, projectFlavor) = GetGuidAndProjectInfo(document);
                var entry = new DocumentSpanEntry(
                    context,
                    definitionBucket,
                    projectName,
                    projectFlavor,
                    guid,
                    spanKind,
                    mappedSpanResult,
                    excerptResult,
                    lineText,
                    symbolUsageInfo,
                    customColumnsData
                    );

                // Because of things like linked files, we may have a reference up in multiple
                // different locations that are effectively at the exact same navigation location
                // for the user. i.e. they're the same file/span.  Showing multiple entries for these
                // is just noisy and gets worse and worse with shared projects and whatnot.  So, we
                // collapse things down to only show a single entry for each unique file/span pair.
                var winningEntry = definitionBucket.GetOrAddEntry(documentSpan, entry);

                // If we were the one that successfully added this entry to the bucket, then pass us
                // back out to be put in the ui.
                if (winningEntry == entry)
                {
                    return(entry);
                }

                // We were not the winner.  Add our flavor to the entry that already exists, but throw
                // away the item we created as we do not want to add it to the ui.
                winningEntry.AddFlavor(projectFlavor);
                return(null);
            }
 public DocumentSpanEntry(
     AbstractTableDataSourceFindUsagesContext context,
     RoslynDefinitionBucket definitionBucket,
     HighlightSpanKind spanKind,
     string documentName,
     Guid projectGuid,
     MappedSpanResult mappedSpanResult,
     ExcerptResult excerptResult,
     SourceText lineText,
     ImmutableDictionary <string, string> customColumnsData)
     : base(context,
            definitionBucket,
            documentName,
            projectGuid,
            lineText,
            mappedSpanResult)
 {
     _spanKind          = spanKind;
     _excerptResult     = excerptResult;
     _customColumnsData = customColumnsData;
 }
Exemple #5
0
            private DocumentSpanEntry(
                AbstractTableDataSourceFindUsagesContext context,
                RoslynDefinitionBucket definitionBucket,
                string rawProjectName,
                string?projectFlavor,
                Guid projectGuid,
                HighlightSpanKind spanKind,
                MappedSpanResult mappedSpanResult,
                ExcerptResult excerptResult,
                SourceText lineText,
                SymbolUsageInfo symbolUsageInfo,
                ImmutableDictionary <string, string> customColumnsData)
                : base(context, definitionBucket, projectGuid, lineText, mappedSpanResult)
            {
                _spanKind             = spanKind;
                _excerptResult        = excerptResult;
                _symbolReferenceKinds = symbolUsageInfo.ToSymbolReferenceKinds();
                _customColumnsData    = customColumnsData;

                _rawProjectName = rawProjectName;
                this.AddFlavor(projectFlavor);
            }