public async Task HandleAsync(RequestHoverText command, KernelInvocationContext context) { using var _ = new GCPressure(1024 * 1024); var document = _workspace.UpdateWorkingDocument(command.Code); var text = await document.GetTextAsync(); var cursorPosition = text.Lines.GetPosition(command.LinePosition.ToCodeAnalysisLinePosition()); var service = QuickInfoService.GetService(document); var info = await service.GetQuickInfoAsync(document, cursorPosition); if (info == null) { return; } var scriptSpanStart = LinePosition.FromCodeAnalysisLinePosition(text.Lines.GetLinePosition(0)); var linePosSpan = LinePositionSpan.FromCodeAnalysisLinePositionSpan(text.Lines.GetLinePositionSpan(info.Span)); var correctedLinePosSpan = linePosSpan.SubtractLineOffset(scriptSpanStart); context.Publish( new HoverTextProduced( command, new[] { new FormattedValue("text/markdown", info.ToMarkdownString()) }, correctedLinePosSpan)); }
public static IEnumerable <MarkedUpCodeLinePosition> PositionsInMarkedSpans( this MarkedUpCode markedUpCode) { foreach (var position in Enumerable.Range( markedUpCode.Span.Start, markedUpCode.Span.Length + 1)) { var linePosition = LinePosition.FromCodeAnalysisLinePosition(markedUpCode.SourceText.Lines.GetLinePosition(position)); yield return(new MarkedUpCodeLinePosition(markedUpCode, linePosition)); } }