protected override async Task AssertContentIsAsync( TestWorkspace workspace, Document document, ITextSnapshot snapshot, int position, string expectedContent, string expectedDocumentationComment = null) { var provider = CreateProvider(workspace); var info = await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, CancellationToken.None)); Assert.NotNull(info); Assert.NotEqual(0, info.RelatedSpans.Length); var trackingSpan = new Mock <ITrackingSpan>(MockBehavior.Strict); var streamingPresenter = workspace.ExportProvider.GetExport <IStreamingFindUsagesPresenter>(); var quickInfoItem = await IntellisenseQuickInfoBuilder.BuildItemAsync(trackingSpan.Object, info, snapshot, document, streamingPresenter, CancellationToken.None); var containerElement = quickInfoItem.Item as ContainerElement; var textElements = containerElement.Elements.OfType <ClassifiedTextElement>(); Assert.NotEmpty(textElements); var textElement = textElements.First(); var actualText = string.Concat(textElement.Runs.Select(r => r.Text)); Assert.Equal(expectedContent, actualText); }
static async Task <Hover> GetHoverAsync(QuickInfoItem info, Document document, ClientCapabilities clientCapabilities, CancellationToken cancellationToken) { var supportsVSExtensions = clientCapabilities.HasVisualStudioLspCapability(); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); if (supportsVSExtensions) { return(new VSHover { Range = ProtocolConversions.TextSpanToRange(info.Span, text), Contents = new SumType <SumType <string, MarkedString>, SumType <string, MarkedString>[], MarkupContent>(string.Empty), // Build the classified text without navigation actions - they are not serializable. // TODO - Switch to markup content once it supports classifications. // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/918138 RawContent = await IntellisenseQuickInfoBuilder.BuildContentWithoutNavigationActionsAsync(info, document, cancellationToken).ConfigureAwait(false) }); } else { return(new Hover { Range = ProtocolConversions.TextSpanToRange(info.Span, text), Contents = GetContents(info, document, clientCapabilities), }); } }
protected override async Task AssertContentIsAsync( TestWorkspace workspace, Document document, int position, string expectedContent, string expectedDocumentationComment = null) { var provider = CreateProvider(); var info = await provider.GetQuickInfoAsync(new QuickInfoContext(document, position, SymbolDescriptionOptions.Default, CancellationToken.None)); Assert.NotNull(info); Assert.NotEqual(0, info.RelatedSpans.Length); var trackingSpan = new Mock <ITrackingSpan>(MockBehavior.Strict); var threadingContext = workspace.ExportProvider.GetExportedValue <IThreadingContext>(); var operationExecutor = workspace.ExportProvider.GetExportedValue <IUIThreadOperationExecutor>(); var streamingPresenter = workspace.ExportProvider.GetExport <IStreamingFindUsagesPresenter>(); var quickInfoItem = await IntellisenseQuickInfoBuilder.BuildItemAsync( trackingSpan.Object, info, document, ClassificationOptions.Default, threadingContext, operationExecutor, AsynchronousOperationListenerProvider.NullListener, streamingPresenter, CancellationToken.None); var containerElement = quickInfoItem.Item as ContainerElement; var textElements = containerElement.Elements.OfType <ClassifiedTextElement>(); Assert.NotEmpty(textElements); var textElement = textElements.First(); var actualText = string.Concat(textElement.Runs.Select(r => r.Text)); Assert.Equal(expectedContent, actualText); }
public override async Task <Hover?> HandleRequestAsync(TextDocumentPositionParams request, RequestContext context, CancellationToken cancellationToken) { var document = context.Document; if (document == null) { return(null); } var position = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(request.Position), cancellationToken).ConfigureAwait(false); var quickInfoService = document.Project.LanguageServices.GetRequiredService <QuickInfoService>(); var info = await quickInfoService.GetQuickInfoAsync(document, position, cancellationToken).ConfigureAwait(false); if (info == null) { return(null); } var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); // TODO - Switch to markup content once it supports classifications. // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/918138 return(new VSHover { Range = ProtocolConversions.TextSpanToRange(info.Span, text), Contents = new SumType <SumType <string, MarkedString>, SumType <string, MarkedString>[], MarkupContent>(string.Empty), // Build the classified text without navigation actions - they are not serializable. RawContent = await IntellisenseQuickInfoBuilder.BuildContentWithoutNavigationActionsAsync(info, document, cancellationToken).ConfigureAwait(false) }); }
private static async Task <Hover> GetHoverAsync( QuickInfoItem info, SourceText text, string language, Document?document, ClassificationOptions?classificationOptions, ClientCapabilities?clientCapabilities, CancellationToken cancellationToken) { Contract.ThrowIfFalse(document is null == (classificationOptions == null)); var supportsVSExtensions = clientCapabilities.HasVisualStudioLspCapability(); if (supportsVSExtensions) { var context = document == null ? null : new IntellisenseQuickInfoBuilderContext( document, classificationOptions !.Value, threadingContext: null, operationExecutor: null, asynchronousOperationListener: null, streamingPresenter: null); return(new VSInternalHover { Range = ProtocolConversions.TextSpanToRange(info.Span, text), Contents = new SumType <SumType <string, MarkedString>, SumType <string, MarkedString>[], MarkupContent>(string.Empty), // Build the classified text without navigation actions - they are not serializable. // TODO - Switch to markup content once it supports classifications. // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/918138 RawContent = await IntellisenseQuickInfoBuilder.BuildContentWithoutNavigationActionsAsync(info, context, cancellationToken).ConfigureAwait(false) }); } else { return(new Hover { Range = ProtocolConversions.TextSpanToRange(info.Span, text), Contents = GetContents(info, language, clientCapabilities), }); }