public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { if (string.IsNullOrWhiteSpace(arguments)) { var curValue = (bool)window.GetOptionValue(ReplOptions.ShowOutput); window.WriteLine("ECHO is " + (curValue ? "ON" : "OFF")); return(ExecutionResult.Succeeded); } if (arguments.Equals("on", System.StringComparison.InvariantCultureIgnoreCase)) { window.SetOptionValue(ReplOptions.ShowOutput, true); return(ExecutionResult.Succeeded); } else if (arguments.Equals("off", System.StringComparison.InvariantCultureIgnoreCase)) { window.SetOptionValue(ReplOptions.ShowOutput, false); return(ExecutionResult.Succeeded); } //Any other value passed to .echo we treat as a message window.WriteLine(arguments); return(ExecutionResult.Succeeded); }
public Task <ExecutionResult> Execute(IReplWindow 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); return(ExecutionResult.Failed); } } return(ExecutionResult.Succeeded); }
public override void WriteLine(string decodedString) { var substring = string.Empty; string outputString = string.Empty; if (decodedString.StartsWith(ErrorText, StringComparison.Ordinal)) { outputString += ErrorAnsiColor + decodedString.Substring(0, ErrorText.Length); substring = decodedString.Length > ErrorText.Length ? decodedString.Substring(ErrorText.Length) : string.Empty; this.HasErrors = true; } else if (decodedString.StartsWith(WarningText, StringComparison.Ordinal)) { outputString += WarnAnsiColor + decodedString.Substring(0, WarningText.Length); substring = decodedString.Length > WarningText.Length ? decodedString.Substring(WarningText.Length) : string.Empty; } else { substring = decodedString; } outputString += NormalAnsiColor + substring; _window.WriteLine(outputString); Debug.WriteLine(decodedString, "REPL npm"); }
internal void DisplayActiveProcess() { if (_activeEvaluator != null) { _window.WriteLine(_activeEvaluator.ProcessId.ToString()); } else { _window.WriteLine("None"); } }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { if (string.IsNullOrWhiteSpace(arguments)) { var curValue = (bool)window.GetOptionValue(ReplOptions.ShowOutput); window.WriteLine("ECHO is " + (curValue ? "ON" : "OFF")); return ExecutionResult.Succeeded; } if (arguments.Equals("on", System.StringComparison.InvariantCultureIgnoreCase)) { window.SetOptionValue(ReplOptions.ShowOutput, true); return ExecutionResult.Succeeded; } else if(arguments.Equals("off",System.StringComparison.InvariantCultureIgnoreCase)) { window.SetOptionValue(ReplOptions.ShowOutput, false); return ExecutionResult.Succeeded; } //Any other value passed to .echo we treat as a message window.WriteLine(arguments); return ExecutionResult.Succeeded; }
public Task<ExecutionResult> Initialize(IReplWindow window) { _window = window; _window.SetOptionValue(ReplOptions.CommandPrefix, "."); _window.SetOptionValue(ReplOptions.PrimaryPrompt, "> "); _window.SetOptionValue(ReplOptions.SecondaryPrompt, ". "); _window.SetOptionValue(ReplOptions.DisplayPromptInMargin, false); _window.SetOptionValue(ReplOptions.SupportAnsiColors, true); _window.SetOptionValue(ReplOptions.UseSmartUpDown, true); _window.WriteLine(Resources.ReplInitializationMessage); return ExecutionResult.Succeeded; }
public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { if (string.IsNullOrWhiteSpace(arguments)) { window.WriteError("save requires a filename"); return(ExecutionResult.Failed); } else if (arguments.IndexOfAny(Path.GetInvalidPathChars()) != -1) { window.WriteError(string.Format(CultureInfo.CurrentCulture, "Invalid filename: {0}", 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, "Session saved to: {0}", arguments)); } catch { window.WriteError(string.Format(CultureInfo.CurrentCulture, "Failed to save: {0}", arguments)); } return(ExecutionResult.Succeeded); }
public Task <ExecutionResult> Initialize(IReplWindow window) { _window = window; _window.SetOptionValue(ReplOptions.CommandPrefix, "."); _window.SetOptionValue(ReplOptions.PrimaryPrompt, "> "); _window.SetOptionValue(ReplOptions.SecondaryPrompt, ". "); _window.SetOptionValue(ReplOptions.DisplayPromptInMargin, false); _window.SetOptionValue(ReplOptions.SupportAnsiColors, true); _window.SetOptionValue(ReplOptions.UseSmartUpDown, true); _window.WriteLine(SR.GetString(SR.ReplInitializationMessage)); return(ExecutionResult.Succeeded); }
public Task <ExecutionResult> Initialize(IReplWindow window) { _window = window; _window.SetOptionValue(ReplOptions.CommandPrefix, "$"); _window.SetOptionValue(ReplOptions.UseSmartUpDown, CurrentOptions.ReplSmartHistory); _window.SetOptionValue(ReplOptions.PrimaryPrompt, CurrentOptions.PrimaryPrompt); _window.SetOptionValue(ReplOptions.SecondaryPrompt, CurrentOptions.SecondaryPrompt); _window.SetOptionValue(ReplOptions.DisplayPromptInMargin, !CurrentOptions.InlinePrompts); _window.SetOptionValue(ReplOptions.SupportAnsiColors, true); _window.SetOptionValue(ReplOptions.FormattedPrompts, true); _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); }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { if(String.IsNullOrWhiteSpace(arguments)) { window.WriteError("save requires a filename"); return ExecutionResult.Failed; }else if(arguments.IndexOfAny(Path.GetInvalidPathChars()) != -1) { window.WriteError(String.Format("Invalid filename: {0}", arguments)); return ExecutionResult.Failed; } StringBuilder text = new StringBuilder(); List<KeyValuePair<int, ITextBuffer>> 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(".")) { text.Append(bufferText); text.Append(Environment.NewLine); } } try { File.WriteAllText(arguments, text.ToString()); window.WriteLine(String.Format("Session saved to: {0}", arguments)); } catch { window.WriteError(String.Format("Failed to save: {0}", arguments)); } return ExecutionResult.Succeeded; }
public async Task <ExecutionResult> Execute(IReplWindow window, string arguments) { string projectPath = string.Empty; string 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(SR.GetString(SR.ReplWindowNpmInitNoYesFlagWarning)); return(ExecutionResult.Failure); } var solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution; IEnumerable <IVsProject> loadedProjects = solution.EnumerateLoadedProjects(onlyNodeProjects: false); var projectNameToDirectoryDictionary = new Dictionary <string, Tuple <string, IVsHierarchy> >(StringComparer.OrdinalIgnoreCase); foreach (IVsProject project in loadedProjects) { var hierarchy = (IVsHierarchy)project; object extObject; var projectResult = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject); if (!ErrorHandler.Succeeded(projectResult)) { continue; } EnvDTE.Project dteProject = extObject as EnvDTE.Project; if (dteProject == null) { continue; } string projectName = dteProject.Name; if (string.IsNullOrEmpty(projectName)) { continue; } // Try checking the `ProjectHome` property first EnvDTE.Properties 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 string 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(); } } bool 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 string projectDirectoryPath = File.Exists(projectPath) ? Path.GetDirectoryName(projectPath) : projectPath; if (!isGlobalCommand && !Directory.Exists(projectDirectoryPath)) { window.WriteError("Please specify a valid Node.js project or project directory. If your solution contains multiple projects, specify a target project using .npm [ProjectName or ProjectDir] <npm arguments> For example: .npm [MyApp] list"); 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(SR.GetString(SR.NpmReplCommandCompletedWithErrors, arguments)); } else { window.WriteLine(SR.GetString(SR.NpmSuccessfullyCompleted, arguments)); } if (nodejsProject != null) { await nodejsProject.CheckForLongPaths(npmArguments); } return(ExecutionResult.Success); }
public async Task<ExecutionResult> Execute(IReplWindow window, string arguments) { string projectPath = string.Empty; string npmArguments = arguments.Trim(' ', '\t'); // Parse project name/directory in square brackets if (npmArguments.StartsWith("[")) { 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(" {0} ", npmArguments); var solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution; IEnumerable<IVsProject> loadedProjects = solution.EnumerateLoadedProjects(onlyNodeProjects: true); var projectNameToDirectoryDictionary = new Dictionary<string, Tuple<string, IVsHierarchy>>(StringComparer.OrdinalIgnoreCase); foreach (IVsProject project in loadedProjects) { var hierarchy = (IVsHierarchy)project; object extObject; var projectResult = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject); if (!ErrorHandler.Succeeded(projectResult)) { continue; } EnvDTE.Project dteProject = extObject as EnvDTE.Project; if (dteProject == null) { continue; } EnvDTE.Properties properties = dteProject.Properties; if (dteProject.Properties == null) { continue; } string projectName = dteProject.Name; EnvDTE.Property projectHome = properties.Item("ProjectHome"); if (projectHome == null || projectName == null) { continue; } var projectDirectory = projectHome.Value as string; if (projectDirectory != null) { 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(); } } bool 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 string projectDirectoryPath = File.Exists(projectPath) ? Path.GetDirectoryName(projectPath) : projectPath; if (!isGlobalCommand && !(Directory.Exists(projectDirectoryPath) && File.Exists(Path.Combine(projectDirectoryPath, "package.json")))) { window.WriteError("Please specify a valid Node.js project or project directory in solution. If solution contains multiple projects, specify target project using .npm [ProjectName or ProjectDir] <npm arguments>"); return ExecutionResult.Failure; } string npmPath; try { npmPath = NpmHelpers.GetPathToNpm( nodejsProject != null ? nodejsProject.GetProjectProperty(NodejsConstants.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(SR.GetString(SR.NpmReplCommandCompletedWithErrors, arguments)); } else { window.WriteLine(SR.GetString(SR.NpmSuccessfullyCompleted, arguments)); } if (nodejsProject != null) { await nodejsProject.CheckForLongPaths(npmArguments); } return ExecutionResult.Success; }
public async Task<ExecutionResult> Execute(IReplWindow window, string arguments) { string projectPath = string.Empty; string 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; IEnumerable<IVsProject> loadedProjects = solution.EnumerateLoadedProjects(onlyNodeProjects: false); var projectNameToDirectoryDictionary = new Dictionary<string, Tuple<string, IVsHierarchy>>(StringComparer.OrdinalIgnoreCase); foreach (IVsProject project in loadedProjects) { var hierarchy = (IVsHierarchy)project; object extObject; var projectResult = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out extObject); if (!ErrorHandler.Succeeded(projectResult)) { continue; } EnvDTE.Project dteProject = extObject as EnvDTE.Project; if (dteProject == null) { continue; } string projectName = dteProject.Name; if (string.IsNullOrEmpty(projectName)) { continue; } // Try checking the `ProjectHome` property first EnvDTE.Properties 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 string 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(); } } bool 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 string projectDirectoryPath = File.Exists(projectPath) ? Path.GetDirectoryName(projectPath) : projectPath; if (!isGlobalCommand && !Directory.Exists(projectDirectoryPath)) { window.WriteError("Please specify a valid Node.js project or project directory. If your solution contains multiple projects, specify a target project using .npm [ProjectName or ProjectDir] <npm arguments> For example: .npm [MyApp] list"); 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; }