示例#1
0
        public Task <ExecutionResult> Execute(IReplWindow window, string arguments)
        {
            var finder = new FileFinder(arguments);

            var eval = window.Evaluator as BasePythonReplEvaluator;

            if (eval != null && eval.CurrentOptions != null)
            {
                finder.Search(eval.CurrentOptions.WorkingDirectory);
                finder.SearchAll(eval.CurrentOptions.SearchPaths, ';');
            }

            finder.ThrowIfNotFound();

            string commandPrefix = (string)window.GetOptionValue(ReplOptions.CommandPrefix);
            string lineBreak     = window.TextView.Options.GetNewLineCharacter();

            IEnumerable <string> lines = File.ReadLines(finder.Filename);
            IEnumerable <string> submissions;

            if (eval != null)
            {
                submissions = eval.JoinCode(lines).Where(CommentPrefixPredicate);
            }
            else
            {
                // v1 behavior, will probably never be hit, but if someone was developing their own IReplEvaluator
                // and using this class it would be hit.
                var submissionList    = new List <string>();
                var currentSubmission = new List <string>();

                foreach (var line in lines)
                {
                    if (line.StartsWith(_commentPrefix))
                    {
                        continue;
                    }

                    if (line.StartsWith(commandPrefix))
                    {
                        AddSubmission(submissionList, currentSubmission, lineBreak);

                        submissionList.Add(line);
                        currentSubmission.Clear();
                    }
                    else
                    {
                        currentSubmission.Add(line);
                    }
                }

                AddSubmission(submissionList, currentSubmission, lineBreak);

                submissions = submissionList;
            }

            window.Submit(submissions);
            return(ExecutionResult.Succeeded);
        }
示例#2
0
        public override void DoCommand(object sender, EventArgs args)
        {
            var activeView = CommonPackage.GetActiveTextView(_serviceProvider);
            var project    = activeView.TextBuffer.GetProject(_serviceProvider);
            var analyzer   = activeView.GetAnalyzer(_serviceProvider);

            ToolWindowPane window = (ToolWindowPane)ExecuteInReplCommand.EnsureReplWindow(_serviceProvider, analyzer, project);

            IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;

            ErrorHandler.ThrowOnFailure(windowFrame.Show());
            IReplWindow repl = (IReplWindow)window;

            PythonReplEvaluator eval = repl.Evaluator as PythonReplEvaluator;

            eval.EnsureConnected();
            repl.Submit(GetActiveInputs(activeView, eval));

            repl.Focus();
        }
示例#3
0
        public Task<ExecutionResult> Execute(IReplWindow window, string arguments) {
            var finder = new FileFinder(arguments);

            var eval = window.Evaluator as BasePythonReplEvaluator;
            if (eval != null && eval.CurrentOptions != null) {
                finder.Search(eval.CurrentOptions.WorkingDirectory);
                finder.SearchAll(eval.CurrentOptions.SearchPaths, ';');
            }

            finder.ThrowIfNotFound();
#if DEV14_OR_LATER
            string commandPrefix = "$";
#else
            string commandPrefix = (string)window.GetOptionValue(ReplOptions.CommandPrefix);
#endif
            string lineBreak = window.TextView.Options.GetNewLineCharacter();

            IEnumerable<string> lines = File.ReadLines(finder.Filename);
            IEnumerable<string> submissions;

            if (eval != null) {
                submissions = eval.JoinCode(lines).Where(CommentPrefixPredicate);
            } else {
                // v1 behavior, will probably never be hit, but if someone was developing their own IReplEvaluator
                // and using this class it would be hit.
                var submissionList = new List<string>();
                var currentSubmission = new List<string>();

                foreach (var line in lines) {
                    if (line.StartsWith(_commentPrefix)) {
                        continue;
                    }

                    if (line.StartsWith(commandPrefix)) {
                        AddSubmission(submissionList, currentSubmission, lineBreak);

                        submissionList.Add(line);
                        currentSubmission.Clear();
                    } else {
                        currentSubmission.Add(line);
                    }
                }

                AddSubmission(submissionList, currentSubmission, lineBreak);

                submissions = submissionList;
            }

            window.Submit(submissions);
            return ExecutionResult.Succeeded;
        }