public Task <SignatureHelp> GetSignatureHelp( CodeCellId codeCellId, Position position) => GetSession().WorkspaceService.GetSignatureHelpAsync( codeCellId, position, Context.ConnectionAborted);
CodeCellState GetCodeCellStateById(CodeCellId codeCellId) { var documentId = codeCellId.ToDocumentId(); return(CodeCells.Values.FirstOrDefault( codeCell => codeCell.DocumentId == documentId)); }
public Task <CodeAnalysis.Compilation> EmitCellCompilationAsync( CodeCellId cellId, EvaluationEnvironment evaluationEnvironment, CancellationToken cancellationToken = default) => EmitSubmissionCompilationAsync( cellId.ToDocumentId(), evaluationEnvironment, cancellationToken);
public void Empty() { CodeCellId emptySubmissionId = default; DocumentId emptyDocumentId = default; DocumentId convertedSubmissionId = emptySubmissionId.ToDocumentId(); Assert.Equal(emptyDocumentId, convertedSubmissionId); }
public CodeCellId InsertCell( CodeCellBuffer buffer, CodeCellId previousCellId, CodeCellId nextCellId) => AddSubmission( buffer.CurrentText, previousCellId.ToDocumentId(), nextCellId.ToDocumentId()).ToCodeCellId();
/// <summary> /// Provides very basic workbook parsing and shunting of code cells /// into the evaluation service. Does not display non-code-cell contents /// but does evaluate a workbook from top-to-bottom. Restores nuget /// packages from the workbook's manifest. /// </summary> static async Task <int> WorkbookPlayerMain(InteractiveSession session, ClientSessionUri sessionUri) { var path = new FilePath(sessionUri.WorkbookPath); if (!path.FileExists) { Error.WriteLine($"File does not exist: {path}"); return(1); } // load the workbook file var workbook = new WorkbookPackage(path); await workbook.Open( quarantineInfo => Task.FromResult(true), path); #pragma warning disable 0618 // TODO: WorkbookDocumentManifest needs to eliminate AgentType like we've done on web // to avoid having to use the the flavor mapping in AgentIdentity. var targetPlatformIdentifier = AgentIdentity.GetFlavorId(workbook.PlatformTargets [0]); #pragma warning restore 0618 // initialize the session based on manifest metadata from the workbook file language = workbook.GetLanguageDescriptions().First(); await session.InitializeAsync(new InteractiveSessionDescription ( language, targetPlatformIdentifier, new EvaluationEnvironment(Environment.CurrentDirectory))); // restore NuGet packages await session.PackageManagerService.RestoreAsync( workbook.Pages.SelectMany(page => page.Packages)); // insert and evaluate cells in the workbook foreach (var cell in workbook.IndexPage.Contents.OfType <CodeCell> ()) { var buffer = cell.CodeAnalysisBuffer.Value; lastCodeCellId = await session.EvaluationService.InsertCodeCellAsync( buffer, lastCodeCellId); ForegroundColor = ConsoleColor.DarkYellow; Write(GetPrompt()); ResetColor(); WriteLine(buffer); await session.EvaluationService.EvaluateAsync(lastCodeCellId); if (lastCellEvaluationStatus != CodeCellEvaluationStatus.Success) { break; } } return(0); }
public void PublishEvaluation( CodeCellId codeCellid, object result, EvaluationResultHandling resultHandling = EvaluationResultHandling.Replace) => MainThread.Post(() => PublishEvaluation(new Evaluation { CodeCellId = codeCellid, ResultHandling = resultHandling, Result = RepresentationManager.Prepare(result) }));
public CodeCellUpdatedEvent( CodeCellId codeCellId, bool isSubmissionComplete, IReadOnlyList <InteractiveDiagnostic> diagnostics) { CodeCellId = codeCellId; IsSubmissionComplete = isSubmissionComplete; Diagnostics = diagnostics; }
public async Task <ImmutableList <InteractiveDiagnostic> > GetCellDiagnosticsAsync( CodeCellId cellId, CancellationToken cancellationToken = default) => (await GetSubmissionCompilationDiagnosticsAsync( cellId.ToDocumentId(), cancellationToken)) .Filter() .Select(ConversionExtensions.ToInteractiveDiagnostic) .ToImmutableList();
public CodeCellEvaluationFinishedEvent( CodeCellId codeCellId, EvaluationStatus status, bool shouldStartNewCell, IReadOnlyList <Diagnostic> diagnostics) { CodeCellId = codeCellId; Status = status; ShouldStartNewCell = shouldStartNewCell; Diagnostics = diagnostics; }
/// <summary> /// Inserts a new cell into the workspace and sets an initial buffer. /// The workspace implementation may not need both <see cref="CodeCellId"/> /// parameters, but they will always be provided, should they exist, by /// <see cref="EvaluationService"/>. /// </summary> /// <param name="initialBuffer">The initial the text content for the cell.</param> /// <param name="previousCellId">Insert the new cell immediately after this cell.</param> /// <param name="nextCellId">Insert the new cell immediately before this cell.</param> /// <returns> /// Returns the <see cref="CodeCellId"/> of the new cell. The ID must be /// unique, opaque, and persistent across the cell's lifecycle. /// </returns> public static CodeCellId InsertCell( this IWorkspaceService workspaceService, string initialBuffer, CodeCellId previousCellId, CodeCellId nextCellId) { var codeCellId = workspaceService.InsertCell(previousCellId, nextCellId); workspaceService.SetCellBuffer(codeCellId, initialBuffer); return(codeCellId); }
public Evaluation( CodeCellId codeCellId, EvaluationResultHandling resultHandling, object value) : this( codeCellId, EvaluationStatus.Success, resultHandling, value, evaluationDuration : default) // to avoid calling self { }
Document GetDocument(CodeCellId codeCellId) { var document = workspace.CurrentSolution?.GetDocument(codeCellId.ToDocumentId()); if (document == null) { throw new ArgumentException( $"documnent {codeCellId} does not exist in workspace", nameof(codeCellId)); } return(document); }
EvaluationInFlight( CodeCellId codeCellId, EvaluationPhase phase, Compilation compilation = null, object originalValue = null, Evaluation evaluation = null) { CodeCellId = codeCellId; Phase = phase; Compilation = compilation; OriginalValue = originalValue; Evaluation = evaluation; }
public async Task <Hover> GetHoverAsync( CodeCellId cellId, Position position, CancellationToken cancellationToken = default) { if (hoverController == null) { hoverController = new HoverController(this); } return(await hoverController.ProvideHoverAsync( GetDocument (cellId), position.ToRoslyn(), cancellationToken)); }
public async Task <SignatureHelp> GetSignatureHelpAsync( CodeCellId cellId, Position position, CancellationToken cancellationToken = default) { if (signatureHelpController == null) { signatureHelpController = new SignatureHelpController(this); } return(await signatureHelpController.ComputeSignatureHelpAsync( GetDocument (cellId), position.ToRoslyn(), cancellationToken)); }
public async Task <IEnumerable <Models.CompletionItem> > GetCompletionsAsync( CodeCellId cellId, Position position, CancellationToken cancellationToken = default) { if (completionController == null) { completionController = new CompletionController(this); } return(await completionController.ProvideFilteredCompletionItemsAsync( GetDocument (cellId), position.ToRoslyn(), cancellationToken)); }
public async Task <IEnumerable <CompletionItem> > GetCompletions( CodeCellId codeCellId, Position position) { var cancellationToken = Context.ConnectionAborted; try { return(await GetSession().WorkspaceService.GetCompletionsAsync( codeCellId, position, cancellationToken)); } catch (TaskCanceledException) when(!cancellationToken.IsCancellationRequested) { return(Array.Empty <CompletionItem> ()); } }
public async Task <Hover> GetHoverAsync( CodeCellId cellId, Position position, CancellationToken cancellationToken = default) { if (hoverController == null) { hoverController = new HoverController(this); } return(await hoverController.ProvideHoverAsync( await GetSourceTextAsync( cellId.ToDocumentId(), cancellationToken), position, cancellationToken)); }
public async Task <SignatureHelp> GetSignatureHelpAsync( CodeCellId cellId, Position position, CancellationToken cancellationToken = default) { if (signatureHelpController == null) { signatureHelpController = new SignatureHelpController(this); } return(await signatureHelpController.ComputeSignatureHelpAsync( await GetSourceTextAsync( cellId.ToDocumentId(), cancellationToken), position, cancellationToken)); }
public async Task <bool> IsCellOutdatedAsync( CodeCellId cellId, CancellationToken cancellationToken = default) { var documentId = cellId.ToDocumentId(); if (HaveAnyLoadDirectiveFilesChanged(documentId)) { // A trick to force Roslyn into invalidating the tree it's holding on // to representing code pulled in via any #load directives in the cell. // Unfortunately we have to go from SourceText → string → SourceText // to force SourceText.Container.TextChanged to be raised. // See https://github.com/dotnet/roslyn/issues/21964 SetCellBuffer( cellId, await GetCellBufferAsync(cellId, cancellationToken)); return(true); } return(false); }
void PopulateCompilationWorkspace() { CodeCellId previousDocumentId = null; foreach (var codeCell in WorkbookPage.Contents.OfType <CodeCell> ()) { var editor = codeCell?.View?.Editor; if (editor == null || !CodeCells.TryGetValue(editor, out var codeCellState)) { continue; } codeCellState.BindToWorkspace( ClientSession.CompilationWorkspace, ClientSession.CompilationWorkspace.InsertCell( codeCell.Buffer.Value, previousDocumentId, null)); previousDocumentId = codeCellState.CodeCellId; } }
internal Evaluation( CodeCellId codeCellId, EvaluationStatus status, EvaluationResultHandling resultHandling, object value, TimeSpan evaluationDuration = default, int cultureLCID = 0, int uiCultureLCID = 0, bool initializedIntegration = false, IReadOnlyList <AssemblyDefinition> loadedAssemblies = null) { CodeCellId = codeCellId; Status = status; ResultHandling = resultHandling; switch (value) { case null: ResultRepresentations = Array.Empty <object> (); break; case RepresentedObject representedObject: ResultType = representedObject.RepresentedType; ResultRepresentations = representedObject; break; default: ResultType = RepresentedType.Lookup(value.GetType()); ResultRepresentations = new [] { value }; break; } EvaluationDuration = evaluationDuration; CultureLCID = cultureLCID; UICultureLCID = uiCultureLCID; InitializedIntegration = initializedIntegration; LoadedAssemblies = loadedAssemblies ?? Array.Empty <AssemblyDefinition> (); }
public async Task <IReadOnlyList <InteractiveDiagnostic> > GetCellDiagnosticsAsync( CodeCellId cellId, CancellationToken cancellationToken = default) { ImmutableArray <Diagnostic> diagnostics; if (lastEmitDiagnostics != null) { diagnostics = lastEmitDiagnostics.Value; lastEmitDiagnostics = null; } else { diagnostics = await GetSubmissionCompilationDiagnosticsAsync( cellId.ToDocumentId(), cancellationToken); } return(diagnostics .Filter() .Select(ConversionExtensions.ToInteractiveDiagnostic) .ToImmutableList()); }
Evaluation( CodeCellId codeCellId, EvaluationStatus status, EvaluationResultHandling resultHandling, IRepresentedType resultType, IReadOnlyList <object> resultRepresentations, bool resultIsException, TimeSpan evaluationDuration, int cultureLCID, int uiCultureLCID, bool initializedIntegration, IReadOnlyList <AssemblyDefinition> loadedAssemblies) { CodeCellId = codeCellId; Status = status; ResultHandling = resultHandling; ResultType = resultType; ResultRepresentations = resultRepresentations; EvaluationDuration = evaluationDuration; CultureLCID = cultureLCID; UICultureLCID = uiCultureLCID; InitializedIntegration = initializedIntegration; LoadedAssemblies = loadedAssemblies; }
public CodeCellResultEvent( CodeCellId codeCellId, EvaluationResultHandling resultHandling, object value) { CodeCellId = codeCellId; ResultHandling = resultHandling; switch (value) { case null: break; case RepresentedObject representedObject: Type = representedObject.RepresentedType; ValueRepresentations = representedObject; break; default: Type = RepresentedType.Lookup(value.GetType()); ValueRepresentations = new [] { value }; break; } }
public void PublishValueForCell(CodeCellId codeCellId, object result, EvaluationResultHandling resultHandling = EvaluationResultHandling.Replace);
public Evaluation(CodeCellId codeCellId, EvaluationResultHandling resultHandling, object value);
public Compilation(CodeCellId codeCellId, int submissionNumber, EvaluationEnvironment evaluationEnvironment, bool isResultAnExpression, AssemblyDefinition executableAssembly, IReadOnlyList <AssemblyDefinition> references);
public async Task <string> GetCellBufferAsync( CodeCellId cellId, CancellationToken cancellationToken = default) => (await GetDocument(cellId).GetTextAsync(cancellationToken)).ToString();