Exemple #1
0
            /// <summary>
            /// Pends the next input line to the current input buffer, optionally executing it
            /// if it forms a complete statement.
            /// </summary>
            private async Task ProcessQueuedInputAsync()
            {
                var textView = _window.TextView;
                var eval     = _window.GetPythonEvaluator();

                bool supportsMultipleStatements = false;

                if (eval != null)
                {
                    supportsMultipleStatements = await eval.GetSupportsMultipleStatementsAsync();
                }

                // Process all of our pending inputs until we get a complete statement
                while (_pendingInputs.First != null)
                {
                    string current = _pendingInputs.First.Value;
                    _pendingInputs.RemoveFirst();

                    MoveCaretToEndOfCurrentInput();

                    var statements = RecombineInput(
                        current,
                        _window.CurrentLanguageBuffer?.CurrentSnapshot.GetText(),
                        supportsMultipleStatements,
                        await textView.GetLanguageVersionAsync(_serviceProvider),
                        textView.Options.GetNewLineCharacter()
                        );

                    if (statements.Count > 0)
                    {
                        // If there was more than one statement then save those for execution later...
                        var input = statements[0];
                        for (int i = statements.Count - 1; i > 0; i--)
                        {
                            _pendingInputs.AddFirst(statements[i]);
                        }

                        _window.InsertCode(input);

                        string fullCode = _window.CurrentLanguageBuffer.CurrentSnapshot.GetText();
                        if (_window.Evaluator.CanExecuteCode(fullCode))
                        {
                            // the code is complete, execute it now
                            _window.Operations.ExecuteInput();
                            return;
                        }

                        _window.InsertCode(textView.Options.GetNewLineCharacter());

                        if (_submitAtEnd && _pendingInputs.First == null)
                        {
                            _window.Operations.ExecuteInput();
                        }
                    }
                }
            }
Exemple #2
0
        internal void SetCurrentScope(string newItem)
        {
            string activeCode = _interactive.CurrentLanguageBuffer.CurrentSnapshot.GetText();

            (_interactive.Evaluator as IMultipleScopeEvaluator)?.SetScope(newItem);
            _interactive.InsertCode(activeCode);
        }
Exemple #3
0
            /// <summary>
            /// Pends the next input line to the current input buffer, optionally executing it
            /// if it forms a complete statement.
            /// </summary>
            private void ProcessQueuedInput()
            {
                var textView = _window.TextView;

                // Process all of our pending inputs until we get a complete statement
                while (_pendingInputs.First != null)
                {
                    string current = _pendingInputs.First.Value;
                    _pendingInputs.RemoveFirst();

                    MoveCaretToEndOfCurrentInput();

                    var statements = RecombineInput(current);

                    if (statements.Count > 0)
                    {
                        // If there was more than one statement then save those for execution later...
                        var input = statements[0];
                        for (int i = statements.Count - 1; i > 0; i--)
                        {
                            _pendingInputs.AddFirst(statements[i]);
                        }

                        _window.InsertCode(input);

                        string fullCode = _window.CurrentLanguageBuffer.CurrentSnapshot.GetText();
                        if (_window.Evaluator.CanExecuteCode(fullCode))
                        {
                            // the code is complete, execute it now
                            _window.Operations.ExecuteInput();
                            return;
                        }

                        _window.InsertCode(textView.Options.GetNewLineCharacter());
                    }
                }
            }
Exemple #4
0
 public void InsertCode(string text)
 {
     _interactiveWindow.InsertCode(text);
 }
Exemple #5
0
 public void InsertCode(string text) =>
 InvokeOnUIThread(cancellationToken => _interactiveWindow.InsertCode(text));
 private void InsertAndExecuteInput(string input)
 {
     _window.InsertCode(input);
     AssertCurrentSubmission(input);
     ExecuteInput();
 }
Exemple #7
0
        private static async Task PasteReplCode(
            IInteractiveWindow window,
            string pasting,
            PythonLanguageVersion version
            )
        {
            // there's some text in the buffer...
            var view  = window.TextView;
            var caret = view.Caret;

            if (view.Selection.IsActive && !view.Selection.IsEmpty)
            {
                foreach (var span in view.Selection.SelectedSpans)
                {
                    foreach (var normalizedSpan in view.BufferGraph.MapDownToBuffer(span, SpanTrackingMode.EdgeInclusive, window.CurrentLanguageBuffer))
                    {
                        normalizedSpan.Snapshot.TextBuffer.Delete(normalizedSpan);
                    }
                }
            }

            var curBuffer = window.CurrentLanguageBuffer;

            if (curBuffer.CurrentSnapshot.Length > 0)
            {
                // There is existing content in the buffer, so let's just insert and
                // return. We do submit any statements.
                window.InsertCode(pasting);
                return;
            }

            var inputPoint = view.BufferGraph.MapDownToBuffer(
                caret.Position.BufferPosition,
                PointTrackingMode.Positive,
                curBuffer,
                PositionAffinity.Successor
                );


            // if we didn't find a location then see if we're in a prompt, and if so, then we want
            // to insert after the prompt.
            if (caret.Position.BufferPosition != window.TextView.TextBuffer.CurrentSnapshot.Length)
            {
                for (int i = caret.Position.BufferPosition + 1;
                     inputPoint == null && i <= window.TextView.TextBuffer.CurrentSnapshot.Length;
                     i++)
                {
                    inputPoint = view.BufferGraph.MapDownToBuffer(
                        new SnapshotPoint(window.TextView.TextBuffer.CurrentSnapshot, i),
                        PointTrackingMode.Positive,
                        curBuffer,
                        PositionAffinity.Successor
                        );
                }
            }

            bool submitLast = pasting.EndsWithOrdinal("\n");

            if (inputPoint == null)
            {
                // we didn't find a point to insert, insert at the beginning.
                inputPoint = new SnapshotPoint(curBuffer.CurrentSnapshot, 0);
            }

            // we want to insert the pasted code at the caret, but we also want to
            // respect the stepping.  So first grab the code before and after the caret.
            var splitCode = JoinToCompleteStatements(SplitAndDedent(pasting), version).ToList();

            curBuffer.Delete(new Span(0, curBuffer.CurrentSnapshot.Length));

            bool supportMultiple = await window.GetSupportsMultipleStatements();

            if (supportMultiple)
            {
                window.InsertCode(string.Join(Environment.NewLine, splitCode));
            }
            else if (splitCode.Count == 1)
            {
                curBuffer.Insert(0, splitCode[0]);
                var viewPoint = view.BufferGraph.MapUpToBuffer(
                    new SnapshotPoint(curBuffer.CurrentSnapshot, Math.Min(inputPoint.Value.Position + pasting.Length, curBuffer.CurrentSnapshot.Length)),
                    PointTrackingMode.Positive,
                    PositionAffinity.Successor,
                    view.TextBuffer
                    );

                if (viewPoint != null)
                {
                    view.Caret.MoveTo(viewPoint.Value);
                }
            }
            else if (splitCode.Count != 0)
            {
                var lastCode = splitCode[splitCode.Count - 1];
                splitCode.RemoveAt(splitCode.Count - 1);

                while (splitCode.Any())
                {
                    var code = splitCode[0];
                    splitCode.RemoveAt(0);
                    await window.SubmitAsync(new[] { code });

                    supportMultiple = await window.GetSupportsMultipleStatements();

                    if (supportMultiple)
                    {
                        // Might have changed while we were executing
                        break;
                    }
                }

                if (supportMultiple)
                {
                    // Insert all remaning lines of code
                    lastCode = string.Join(Environment.NewLine, splitCode);
                }

                window.InsertCode(lastCode);
            }
            else
            {
                window.InsertCode(pasting);
            }

            if (submitLast)
            {
                if (window.Evaluator.CanExecuteCode(window.CurrentLanguageBuffer.CurrentSnapshot.GetText()))
                {
                    window.Operations.ExecuteInput();
                }
                else
                {
                    window.InsertCode("\n");
                }
            }
        }
Exemple #8
0
 private async Task InsertAndExecuteInput(string input)
 {
     _window.InsertCode(input);
     AssertCurrentSubmission(input);
     await ExecuteInput().ConfigureAwait(true);
 }