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); var service = QuickInfoService.GetService(document); var info = await service.GetQuickInfoAsync(document, cursorPosition); if (info == null) { return; } var scriptSpanStart = text.Lines.GetLinePosition(0); var linePosSpan = text.Lines.GetLinePositionSpan(info.Span); var correctedLinePosSpan = linePosSpan.SubtractLineOffset(scriptSpanStart); context.Publish( new HoverTextProduced( command, new[] { new FormattedValue("text/markdown", info.ToMarkdownString()) }, correctedLinePosSpan)); }
private async Task <IEnumerable <CompletionItem> > GetCompletionList( string code, int cursorPosition) { using var _ = new GCPressure(1024 * 1024); var document = _workspace.ForkDocument(code); var service = CompletionService.GetService(document); var completionList = await service.GetCompletionsAsync(document, cursorPosition); if (completionList is null) { return(Enumerable.Empty <CompletionItem>()); } var items = completionList.Items.Select(item => item.ToModel()).ToArray(); return(items); }