コード例 #1
0
        public void DisplayHelp()
        {
            _window.WriteLine(InteractiveWindowResources.KeyboardShortcuts);
            _window.Write(ShortcutDescriptions);

            _window.WriteLine(InteractiveWindowResources.ReplCommands);
            foreach (var line in Help())
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }

            // Hack: Display script directives only in CS/VB interactive window
            // TODO: https://github.com/dotnet/roslyn/issues/6441
            var evaluatorTypeName = _window.Evaluator.GetType().Name;

            if (evaluatorTypeName == "CSharpInteractiveEvaluator" ||
                evaluatorTypeName == "VisualBasicInteractiveEvaluator")
            {
                _window.WriteLine(InteractiveWindowResources.CSVBScriptDirectives);
                foreach (var line in s_CSVBScriptDirectives)
                {
                    _window.Write(HelpIndent);
                    _window.WriteLine(line);
                }
            }
        }
コード例 #2
0
ファイル: InfoReplCommand.cs プロジェクト: zjherp/nodejstools
        public override Task <ExecutionResult> Execute(IInteractiveWindow window, string arguments)
        {
            if (window.Evaluator is NodejsReplEvaluator nodeEval)
            {
                try
                {
                    if (!nodeEval.EnsureNodeInstalled())
                    {
                        return(ExecutionResult.Failed);
                    }
                    var nodeExePath = nodeEval.NodeExePath;
                    var nodeVersion = FileVersionInfo.GetVersionInfo(nodeExePath);

                    window.WriteLine(string.Format(CultureInfo.CurrentUICulture, Resources.ReplNodeInfo, nodeExePath));
                    window.WriteLine(string.Format(CultureInfo.CurrentUICulture, Resources.ReplNodeVersion, nodeVersion.ProductVersion));
                }
                catch (Exception e)
                {
                    window.WriteLine(Resources.ReplNodeError);
                    window.WriteError(e.Message);
                    return(ExecutionResult.Failed);
                }
            }
            return(ExecutionResult.Succeeded);
        }
コード例 #3
0
        public override void WriteLine()
        {
            Span span = window.WriteLine(text: null);

            if (spans != null)
            {
                spans.Add(span);
            }
        }
コード例 #4
0
        public void DisplayHelp()
        {
            _window.WriteLine("Keyboard shortcuts:");
            foreach (var line in s_shortcutDescriptions)
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }

            _window.WriteLine("REPL commands:");
            foreach (var line in Help())
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }
        }
コード例 #5
0
        public void DisplayHelp()
        {
            _window.WriteLine(InteractiveWindowResources.KeyboardShortcuts);
            foreach (var line in s_shortcutDescriptions)
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }

            _window.WriteLine(InteractiveWindowResources.ReplCommands);
            foreach (var line in Help())
            {
                _window.Write(HelpIndent);
                _window.WriteLine(line);
            }
        }
コード例 #6
0
        public Task <ExecutionResult> Initialize(IInteractiveWindow window)
        {
            _window = window;
            _window.SetSmartUpDown(CurrentOptions.ReplSmartHistory);
            _window.WriteLine("Python debug interactive window.  Type $help for a list of commands.");

            _window.ReadyForInput += new Action(OnReadyForInput);
            return(ExecutionResult.Succeeded);
        }
コード例 #7
0
 internal void DisplayActiveProcess()
 {
     if (_activeEvaluator != null)
     {
         _window.WriteLine(_activeEvaluator.ProcessId.ToString());
     }
     else
     {
         _window.WriteLine("None");
     }
 }
コード例 #8
0
ファイル: SaveReplCommand.cs プロジェクト: zjherp/nodejstools
        public override Task <ExecutionResult> Execute(IInteractiveWindow window, string arguments)
        {
            if (string.IsNullOrWhiteSpace(arguments))
            {
                window.WriteError(Resources.ReplSaveNoFileName);
                return(ExecutionResult.Failed);
            }
            else if (arguments.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                window.WriteError(string.Format(CultureInfo.CurrentCulture, Resources.ReplSaveInvalidFileName, arguments));
                return(ExecutionResult.Failed);
            }

            var text = new StringBuilder();

            var positions = new List <KeyValuePair <int, ITextBuffer> >();

            foreach (var buffer in window.TextView.BufferGraph.GetTextBuffers(IsJavaScriptBuffer))
            {
                var target = window.TextView.BufferGraph.MapUpToBuffer(
                    new SnapshotPoint(buffer.CurrentSnapshot, 0),
                    PointTrackingMode.Positive,
                    PositionAffinity.Successor,
                    window.TextView.TextBuffer
                    );

                positions.Add(new KeyValuePair <int, ITextBuffer>(target.Value, buffer));
            }

            positions.Sort((x, y) => x.Key.CompareTo(y.Key));
            foreach (var buffer in positions)
            {
                var bufferText = buffer.Value.CurrentSnapshot.GetText();
                if (!bufferText.StartsWith(".", StringComparison.Ordinal))
                {
                    text.Append(bufferText);
                    text.Append(Environment.NewLine);
                }
            }

            try
            {
                File.WriteAllText(arguments, text.ToString());
                window.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.ReplSaveSucces, arguments));
            }
            catch
            {
                window.WriteError(string.Format(CultureInfo.CurrentCulture, Resources.ReplSaveFailed, arguments));
            }
            return(ExecutionResult.Succeeded);
        }
コード例 #9
0
 public Task <ExecutionResult> Execute(IInteractiveWindow window, string arguments)
 {
     System.Environment.SetEnvironmentVariable("_PTVS_DEBUG_REPL", "1");
     window.WriteLine("You will need to reset this window.");
     return(ExecutionResult.Succeeded);
 }
コード例 #10
0
        public Task<ExecutionResult> Initialize(IInteractiveWindow window) {
            _window = window;
            _window.SetSmartUpDown(CurrentOptions.ReplSmartHistory);
            _window.WriteLine("Python debug interactive window.  Type $help for a list of commands.");

            _window.TextView.BufferGraph.GraphBuffersChanged += BufferGraphGraphBuffersChanged;
            _window.ReadyForInput += new Action(OnReadyForInput);
            return ExecutionResult.Succeeded;
        }
コード例 #11
0
        public override async Task <ExecutionResult> Execute(IInteractiveWindow window, string arguments)
        {
            var projectPath  = string.Empty;
            var npmArguments = arguments.Trim(' ', '\t');

            // Parse project name/directory in square brackets
            if (npmArguments.StartsWith("[", StringComparison.Ordinal))
            {
                var match = Regex.Match(npmArguments, @"(?:[[]\s*\""?\s*)(.*?)(?:\s*\""?\s*[]]\s*)");
                projectPath  = match.Groups[1].Value;
                npmArguments = npmArguments.Substring(match.Length);
            }

            // Include spaces on either side of npm arguments so that we can more simply detect arguments
            // at beginning and end of string (e.g. '--global')
            npmArguments = string.Format(CultureInfo.InvariantCulture, " {0} ", npmArguments);

            // Prevent running `npm init` without the `-y` flag since it will freeze the repl window,
            // waiting for user input that will never come.
            if (npmArguments.Contains(" init ") && !(npmArguments.Contains(" -y ") || npmArguments.Contains(" --yes ")))
            {
                window.WriteError(Resources.ReplWindowNpmInitNoYesFlagWarning);
                return(ExecutionResult.Failure);
            }

            var solution       = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;
            var loadedProjects = solution.EnumerateLoadedProjects(onlyNodeProjects: false);

            var projectNameToDirectoryDictionary = new Dictionary <string, Tuple <string, IVsHierarchy> >(StringComparer.OrdinalIgnoreCase);

            foreach (var project in loadedProjects)
            {
                var hierarchy = (IVsHierarchy)project;

                var projectResult = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out var extObject);
                if (!ErrorHandler.Succeeded(projectResult))
                {
                    continue;
                }

                var dteProject = extObject as EnvDTE.Project;
                if (dteProject == null)
                {
                    continue;
                }

                var projectName = dteProject.Name;
                if (string.IsNullOrEmpty(projectName))
                {
                    continue;
                }

                // Try checking the `ProjectHome` property first
                var properties = dteProject.Properties;
                if (dteProject.Properties != null)
                {
                    EnvDTE.Property projectHome = null;
                    try
                    {
                        projectHome = properties.Item("ProjectHome");
                    }
                    catch (ArgumentException)
                    {
                        // noop
                    }

                    if (projectHome != null)
                    {
                        var projectHomeDirectory = projectHome.Value as string;
                        if (!string.IsNullOrEmpty(projectHomeDirectory))
                        {
                            projectNameToDirectoryDictionary.Add(projectName, Tuple.Create(projectHomeDirectory, hierarchy));
                            continue;
                        }
                    }
                }

                // Otherwise, fall back to using fullname
                var projectDirectory = string.IsNullOrEmpty(dteProject.FullName) ? null : Path.GetDirectoryName(dteProject.FullName);
                if (!string.IsNullOrEmpty(projectDirectory))
                {
                    projectNameToDirectoryDictionary.Add(projectName, Tuple.Create(projectDirectory, hierarchy));
                }
            }

            Tuple <string, IVsHierarchy> projectInfo;

            if (string.IsNullOrEmpty(projectPath) && projectNameToDirectoryDictionary.Count == 1)
            {
                projectInfo = projectNameToDirectoryDictionary.Values.First();
            }
            else
            {
                projectNameToDirectoryDictionary.TryGetValue(projectPath, out projectInfo);
            }

            NodejsProjectNode nodejsProject = null;

            if (projectInfo != null)
            {
                projectPath = projectInfo.Item1;
                if (projectInfo.Item2 != null)
                {
                    nodejsProject = projectInfo.Item2.GetProject().GetNodejsProject();
                }
            }

            var isGlobalCommand = false;

            if (string.IsNullOrWhiteSpace(npmArguments) ||
                npmArguments.Contains(" -g ") || npmArguments.Contains(" --global "))
            {
                projectPath     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                isGlobalCommand = true;
            }

            // In case someone copies filename
            var projectDirectoryPath = File.Exists(projectPath) ? Path.GetDirectoryName(projectPath) : projectPath;

            if (!isGlobalCommand && !Directory.Exists(projectDirectoryPath))
            {
                window.WriteError(Resources.NpmSpecifyValidProject);
                return(ExecutionResult.Failure);
            }

            string npmPath;

            try
            {
                npmPath = NpmHelpers.GetPathToNpm(
                    nodejsProject != null ?
                    Nodejs.GetAbsoluteNodeExePath(
                        nodejsProject.ProjectHome,
                        nodejsProject.GetProjectProperty(NodeProjectProperty.NodeExePath))
                        : null);
            }
            catch (NpmNotFoundException)
            {
                Nodejs.ShowNodejsNotInstalled();
                return(ExecutionResult.Failure);
            }

            var npmReplRedirector = new NpmReplRedirector(window);

            await ExecuteNpmCommandAsync(
                npmReplRedirector,
                npmPath,
                projectDirectoryPath,
                new[] { npmArguments },
                null);

            if (npmReplRedirector.HasErrors)
            {
                window.WriteError(string.Format(CultureInfo.CurrentCulture, Resources.NpmReplCommandCompletedWithErrors, arguments));
            }
            else
            {
                window.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.NpmSuccessfullyCompleted, arguments));
            }

            if (nodejsProject != null)
            {
                await nodejsProject.CheckForLongPaths(npmArguments);
            }

            return(ExecutionResult.Success);
        }
コード例 #12
0
ファイル: BaseJReplEvaluator.cs プロジェクト: borota/JTVS
        public Task<ExecutionResult> Initialize(IReplWindow window)
        {
            _window = window;
            _window.SetOptionValue(ReplOptions.CommandPrefix, ")");

            window.SetOptionValue(ReplOptions.UseSmartUpDown, CurrentOptions.ReplSmartHistory);
            UpdatePrompts(true);
            window.SetOptionValue(ReplOptions.DisplayPromptInMargin, !CurrentOptions.InlinePrompts);
            window.SetOptionValue(ReplOptions.SupportAnsiColors, true);
            window.SetOptionValue(ReplOptions.FormattedPrompts, true);
            window.WriteLine("J interactive window. Type )help for a list of commands.");
            _window.TextView.BufferGraph.GraphBuffersChanged += BufferGraphGraphBuffersChanged;
            return ExecutionResult.Succeeded;
        }