public async Task CanQueueParallelRunspaceRequests() { // Concurrently initiate 4 requests in the session this.powerShellContext.ExecuteScriptString("$x = 100"); Task <RunspaceHandle> handleTask = this.powerShellContext.GetRunspaceHandle(); this.powerShellContext.ExecuteScriptString("$x += 200"); this.powerShellContext.ExecuteScriptString("$x = $x / 100"); PSCommand psCommand = new PSCommand(); psCommand.AddScript("$x"); Task <IEnumerable <int> > resultTask = this.powerShellContext.ExecuteCommand <int>(psCommand); // Wait for the requested runspace handle and then dispose it RunspaceHandle handle = await handleTask; handle.Dispose(); // At this point, the remaining command executions should execute and complete int result = (await resultTask).FirstOrDefault(); // 100 + 200 = 300, then divided by 100 is 3. We are ensuring that // the commands were executed in the sequence they were called. Assert.Equal(3, result); }
protected async Task HandleCompletionResolveRequest( CompletionItem completionItem, RequestContext <CompletionItem> requestContext) { if (completionItem.Kind == CompletionItemKind.Function) { RunspaceHandle runspaceHandle = await editorSession.PowerShellContext.GetRunspaceHandle(); // Get the documentation for the function CommandInfo commandInfo = CommandHelpers.GetCommandInfo( completionItem.Label, runspaceHandle.Runspace); completionItem.Documentation = CommandHelpers.GetCommandSynopsis( commandInfo, runspaceHandle.Runspace); runspaceHandle.Dispose(); } // Send back the updated CompletionItem await requestContext.SendResult(completionItem); }