示例#1
0
        async Task <string> IRCallbacks.ReadConsole(IReadOnlyList <IRContext> contexts, string prompt, int len, bool addToHistory, CancellationToken ct)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            if (!_initializedTcs.Task.IsCompleted)
            {
                await AfterHostStarted(_startupInfo);
            }

            var callback = _callback;

            if (!addToHistory && callback != null)
            {
                return(await callback.ReadUserInput(prompt, len, ct));
            }

            var currentRequest = Interlocked.Exchange(ref _currentRequestSource, null);

            _contexts = contexts;
            Prompt    = GetDefaultPrompt(prompt);
            MaxLength = len;

            var requestEventArgs = new RBeforeRequestEventArgs(contexts, Prompt, len, addToHistory);

            BeforeRequest?.Invoke(this, requestEventArgs);

            OnMutated();

            currentRequest?.CompleteResponse();

            string consoleInput = null;

            do
            {
                ct.ThrowIfCancellationRequested();
                try {
                    consoleInput = await ReadNextRequest(Prompt, len, ct);
                } catch (OperationCanceledException ex) when(!(ex is CancelAllException))
                {
                    // If request was canceled through means other than our token, it indicates the refusal of
                    // that requestor to respond to that particular prompt, so move on to the next requestor.
                    // If it was canceled through the token, then host itself is shutting down, and cancellation
                    // will be propagated on the entry to next iteration of this loop.
                    //
                    // If request was canceled due to CancelAllAsync, then we should not continue to process this
                    // ReadConsole call at all. Under normal conditions, ct will also be marked as canceled; but
                    // there is a potential for a race condition where we get a cancellation exception here, but
                    // ct is not marked as canceled yet. Explicitly checking for CancelAllException handles this.
                }
            } while (consoleInput == null);


            // We only want to fire 'directory changed' events when it is initiated by the user
            _processingChangeDirectoryCommand = consoleInput.StartsWithOrdinal("setwd");

            consoleInput = consoleInput.EnsureLineBreak();
            AfterRequest?.Invoke(this, new RAfterRequestEventArgs(contexts, Prompt, consoleInput, addToHistory, currentRequest?.IsVisible ?? false));

            return(consoleInput);
        }
示例#2
0
        private void SessionOnBeforeRequest(object sender, RBeforeRequestEventArgs e)
        {
            if (CurrentWindow == null || CurrentWindow.IsRunning)
            {
                return;
            }

            _coreShell.DispatchOnUIThread(() => {
                if (CurrentWindow == null || CurrentWindow.IsRunning)
                {
                    return;
                }

                var projectionBuffer = CurrentWindow.TextView.TextBuffer as IProjectionBuffer;
                if (projectionBuffer == null)
                {
                    return;
                }

                var spanCount = projectionBuffer.CurrentSnapshot.SpanCount;
                projectionBuffer.ReplaceSpans(spanCount - 2, 1, new List <object> {
                    GetPrompt()
                }, EditOptions.None, new object());
            });
        }
示例#3
0
        async Task <string> IRCallbacks.ReadConsole(IReadOnlyList <IRContext> contexts, string prompt, int len, bool addToHistory, CancellationToken ct)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            var callback = _callback;

            if (!addToHistory && callback != null)
            {
                return(await callback.ReadUserInput(prompt, len, ct));
            }

            var currentRequest = Interlocked.Exchange(ref _currentRequestSource, null);

            _contexts = contexts;
            Prompt    = prompt;
            MaxLength = len;

            var requestEventArgs = new RBeforeRequestEventArgs(contexts, prompt, len, addToHistory);

            BeforeRequest?.Invoke(this, requestEventArgs);

            var evaluationCts  = new CancellationTokenSource();
            var evaluationTask = EvaluateUntilCancelled(contexts, evaluationCts.Token, ct);

            currentRequest?.CompleteResponse();

            string consoleInput = null;

            do
            {
                ct.ThrowIfCancellationRequested();
                try {
                    consoleInput = await ReadNextRequest(prompt, len, ct);
                } catch (OperationCanceledException) {
                    // If request was canceled through means other than our token, it indicates the refusal of
                    // that requestor to respond to that particular prompt, so move on to the next requestor.
                    // If it was canceled through the token, then host itself is shutting down, and cancellation
                    // will be propagated on the entry to next iteration of this loop.
                }
            } while (consoleInput == null);

            consoleInput = consoleInput.EnsureLineBreak();

            // If evaluation was allowed, cancel evaluation processing but await evaluation that is in progress
            evaluationCts.Cancel();
            await evaluationTask;

            AfterRequest?.Invoke(this, new RAfterRequestEventArgs(contexts, prompt, consoleInput, addToHistory, _currentRequestSource.IsVisible));

            return(consoleInput);
        }
示例#4
0
 private void OnBeforeRequest(object sender, RBeforeRequestEventArgs e)
 {
     _enabled = e.Contexts.Count != 1; // Disable command only if prompt is in the top level
 }
示例#5
0
 private void RSession_BeforeRequest(object sender, RBeforeRequestEventArgs e)
 {
     _initialPromptCts.Cancel();
     ProcessBrowsePrompt(e.Contexts);
 }
示例#6
0
 private void RSession_BeforeRequest(object sender, RBeforeRequestEventArgs e)
 {
     ResetStackFrames();
 }