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 Task <ExecutionResult> Execute(IReplWindow window, string arguments) { var eval = window.Evaluator as PythonDebugReplEvaluator; if (eval != null) { if (string.IsNullOrEmpty(arguments)) { eval.DisplayActiveThread(); } else { long id; if (long.TryParse(arguments, out id)) { eval.ChangeActiveThread(id, true); } else { window.WriteError(String.Format("Invalid arguments '{0}'. Expected thread id.", arguments)); } } } return(ExecutionResult.Succeeded); }
public override void TextViewCreated(IReplWindow window, VisualStudio.Text.Editor.ITextView view) { var adapterFactory = IronPythonToolsPackage.ComponentModel.GetService<IVsEditorAdaptersFactoryService>(); new EditFilter(IronPythonToolsPackage.ComponentModel.GetService<IPythonAnalyzer>(), (IWpfTextView)view, adapterFactory.GetViewAdapter(view)); window.UseSmartUpDown = IronPythonToolsPackage.Instance.OptionsPage.ReplSmartHistory; base.TextViewCreated(window, view); }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { var eval = window.Evaluator as PythonDebugReplEvaluator; if (eval != null) { eval.Resume(); } return ExecutionResult.Succeeded; }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { var eval = window.Evaluator as PythonDebugReplEvaluator; if (eval != null) { eval.DisplayProcesses(); } return ExecutionResult.Succeeded; }
public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { var eval = window.Evaluator as PythonReplEvaluator; if (eval != null) { if (eval.AttachEnabled) { string error = eval.AttachDebugger(); if (error != null) { window.WriteError("Failed to attach: " + error); } } else { window.WriteError( "Attaching to an interactive window requires enabling attach " + "support in Tools->Options->Python Tools->Interactive Windows." + Environment.NewLine + Environment.NewLine + "This will cause the debugger to track necessary state to enable " + "debugging until the attach is requested. Once enabled the " + "interactive window will need to be reset for the change to take " + "effect."); } } else { window.WriteError("attach only supports Python interactive windows"); } return(ExecutionResult.Succeeded); }
public void Execute(IReplWindow window, string arguments) { var remoteEval = window.Evaluator as RemotePythonEvaluator; if(remoteEval != null) { remoteEval.SetScope(arguments); } }
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); }
public void ReplWindowCreated(IReplWindow window) { var textViewAdapter = _adapterFact.GetViewAdapter(window.TextView); BraceMatcher.WatchBraceHighlights(window.TextView, PythonToolsPackage.ComponentModel); new EditFilter(window.TextView, textViewAdapter, _editorOpsFactory.GetEditorOperations(window.TextView)); }
public override void TextViewCreated(IReplWindow window, VisualStudio.Text.Editor.ITextView view) { var adapterFactory = IronPythonToolsPackage.ComponentModel.GetService <IVsEditorAdaptersFactoryService>(); new EditFilter(IronPythonToolsPackage.ComponentModel.GetService <IPythonAnalyzer>(), (IWpfTextView)view, adapterFactory.GetViewAdapter(view)); window.UseSmartUpDown = IronPythonToolsPackage.Instance.OptionsPage.ReplSmartHistory; base.TextViewCreated(window, view); }
public void Execute(IReplWindow window, string arguments) { var remoteEval = window.Evaluator as RemotePythonEvaluator; if (remoteEval != null) { remoteEval.SetScope(arguments); } }
public void Execute(IReplWindow window, string arguments) { arguments = arguments .ToLowerInvariant(); if (arguments == "on") { window.ShowOutput = true; } else { window.ShowOutput = false; } }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { arguments = arguments.ToLowerInvariant(); if (arguments == "on") { window.SetOptionValue(ReplOptions.ShowOutput, true); } else { window.SetOptionValue(ReplOptions.ShowOutput, false); } return ExecutionResult.Succeeded; }
public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { var remoteEval = window.Evaluator as IMultipleScopeEvaluator; if (remoteEval != null) { remoteEval.SetScope(arguments); } return(ExecutionResult.Succeeded); }
public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { var eval = window.Evaluator as PythonDebugReplEvaluator; if (eval != null) { eval.FrameUp(); } return(ExecutionResult.Succeeded); }
private static bool IsCaretInStringLiteral(IReplWindow buffer) { var caret = buffer.TextView.Caret; var spans = GetClassifier(buffer).GetClassificationSpans(buffer.TextView.GetTextElementSpan(caret.Position.BufferPosition)); if (spans.Count > 0) { return(spans[0].ClassificationType.IsOfType(PredefinedClassificationTypeNames.String)); } return(false); }
public void Execute(IReplWindow window, string arguments) { arguments = arguments.ToLowerInvariant(); if (arguments == "on") { window.SetOptionValue(ReplOptions.ShowOutput, true); } else { window.SetOptionValue(ReplOptions.ShowOutput, false); } }
public void Execute(IReplWindow window, string arguments) { arguments = arguments.ToLowerInvariant(); if (arguments == "on") { window.ShowOutput = true; } else { window.ShowOutput = false; } }
public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { arguments = arguments.ToLowerInvariant(); if (arguments == "on") { window.SetOptionValue(ReplOptions.ShowOutput, true); } else { window.SetOptionValue(ReplOptions.ShowOutput, false); } 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 void Start(IReplWindow window) { _window = window; _window.SetOptionValue(ReplOptions.CommandPrefix, "$"); Connect(); window.SetOptionValue(ReplOptions.UseSmartUpDown, CurrentOptions.ReplSmartHistory); UpdatePrompts(); window.SetOptionValue(ReplOptions.DisplayPromptInMargin, !CurrentOptions.InlinePrompts); window.SetOptionValue(ReplOptions.SupportAnsiColors, true); window.SetOptionValue(ReplOptions.FormattedPrompts, true); }
public Task <ExecutionResult> Initialize(IReplWindow window) { PowerShellToolsPackage.Debugger.ReplWindow = window; var page = PowerShellToolsPackage.Instance.GetDialogPage <GeneralDialogPage>(); window.TextView.Properties.AddProperty(BufferProperties.FromRepl, null); window.SetOptionValue(ReplOptions.Multiline, page.MutlilineRepl); window.SetOptionValue(ReplOptions.UseSmartUpDown, true); return(tf.StartNew(() => { Window = window; return new ExecutionResult(true); })); }
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> 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; }
public void Execute(IReplWindow window, string arguments) { using (var stream = new StreamReader(arguments)) { string line; while ((line = stream.ReadLine()) != null) { if (line.StartsWith("%%")) { window.PasteText(String.Empty); } else { window.PasteText(line); } } } window.PasteText(window.CurrentView.Options.GetNewLineCharacter()); }
public void Execute(IReplWindow window, string arguments) { using (var stream = new StreamReader(arguments)) { string line; while ((line = stream.ReadLine()) != null) { if (!line.StartsWith("%%")) { window.PasteText(line); } } } window.PasteText(window.TextView.Options.GetNewLineCharacter()); }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { var delay = new TimeSpan(0, 0, 0, 0, int.Parse(arguments)); var start = DateTime.UtcNow; while ((start + delay) > DateTime.UtcNow) { var frame = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke( DispatcherPriority.Background, new Action<DispatcherFrame>(f => f.Continue = false), frame ); Dispatcher.PushFrame(frame); } 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); }
private IReplWindow GetReplWindow(IReplWindowProvider replWindowProvider) { IReplWindow curWindow = null; foreach (var provider in replWindowProvider.GetReplWindows()) { if (provider.Title == _title) { curWindow = provider; break; } } return(curWindow); }
public Task<ExecutionResult> Initialize(IReplWindow window) { PowerShellToolsPackage.Debugger.ReplWindow = window; var page = PowerShellToolsPackage.Instance.GetDialogPage<GeneralDialogPage>(); window.TextView.Properties.AddProperty(BufferProperties.FromRepl, null); window.SetOptionValue(ReplOptions.Multiline, page.MutlilineRepl); window.SetOptionValue(ReplOptions.UseSmartUpDown, true); return tf.StartNew(() => { Window = window; return new ExecutionResult(true); }); }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { var eval = window.Evaluator as PythonDebugReplEvaluator; if (eval != null) { if (string.IsNullOrEmpty(arguments)) { eval.DisplayActiveThread(); } else { long id; if (long.TryParse(arguments, out id)) { eval.ChangeActiveThread(id, true); } else { window.WriteError(String.Format("Invalid arguments '{0}'. Expected thread id.", arguments)); } } } return ExecutionResult.Succeeded; }
public void ReplWindowCreated(IReplWindow window) { var textView = window.TextView; var editFilter = new EditFilter( textView, _editorOperationsFactory.GetEditorOperations(textView), _editorOptionsFactory.GetOptions(textView), _compModel.GetService <IIntellisenseSessionStackMapService>().GetStackForTextView(textView), _compModel ); IntellisenseController controller = IntellisenseControllerProvider.GetOrCreateController(_compModel, textView); controller.AttachKeyboardFilter(); editFilter.AttachKeyboardFilter(_adaptersFactory.GetViewAdapter(window.TextView)); }
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 void Execute(IReplWindow window, string arguments) { var delay = new TimeSpan(0, 0, 0, 0, int.Parse(arguments)); var start = DateTime.UtcNow; while ((start + delay) > DateTime.UtcNow) { var frame = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke( DispatcherPriority.Background, new Action <DispatcherFrame>(f => f.Continue = false), frame ); Dispatcher.PushFrame(frame); } }
public void ReplWindowCreated(IReplWindow window) { var model = _serviceProvider.GetComponentModel(); var textView = window.TextView; var vsTextView = _adapterFact.GetViewAdapter(textView); if (window.Evaluator is PythonReplEvaluator) { textView.Properties.AddProperty(typeof(PythonReplEvaluator), (PythonReplEvaluator)window.Evaluator); } var editFilter = new EditFilter(window.TextView, _editorOpsFactory.GetEditorOperations(textView), _serviceProvider); var intellisenseController = IntellisenseControllerProvider.GetOrCreateController( _serviceProvider, model, textView ); editFilter.AttachKeyboardFilter(vsTextView); intellisenseController.AttachKeyboardFilter(); }
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(); }
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 void ReplWindowCreated(IReplWindow window) { var model = _serviceProvider.GetComponentModel(); var textView = window.TextView; var vsTextView = _adapterFact.GetViewAdapter(textView); if (window.Evaluator is PythonReplEvaluator) { textView.Properties.AddProperty(typeof(PythonReplEvaluator), (PythonReplEvaluator)window.Evaluator); } var editFilter = new EditFilter(window.TextView, _editorOpsFactory.GetEditorOperations(textView), _serviceProvider); var intellisenseController = IntellisenseControllerProvider.GetOrCreateController( _serviceProvider, model, textView ); editFilter.AttachKeyboardFilter(vsTextView); intellisenseController.AttachKeyboardFilter(); }
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 void Execute(IReplWindow window, string arguments) { window.ClearScreen(); }
public void Execute(IReplWindow window, string arguments) { window.Reset(); }
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 NpmReplRedirector(IReplWindow window) { _window = window; HasErrors = false; }
public Task <ExecutionResult> Execute(IReplWindow window, string arguments) { ((NodejsReplEvaluator)window.Evaluator).Clear(); return(ExecutionResult.Succeeded); }
public void ReplWindowCreated(IReplWindow window) { var textView = window.TextView; var editFilter = new EditFilter( _serviceProvider, textView, _editorOperationsFactory.GetEditorOperations(textView), _editorOptionsFactory.GetOptions(textView), _compModel.GetService<IIntellisenseSessionStackMapService>().GetStackForTextView(textView), _compModel ); IntellisenseController controller = IntellisenseControllerProvider.GetOrCreateController(_compModel, textView, _serviceProvider); controller.AttachKeyboardFilter(); editFilter.AttachKeyboardFilter(_adaptersFactory.GetViewAdapter(window.TextView)); }
public static Task<ExecutionResult> _Initialize(this IReplEvaluator self, IReplWindow window) { return self.Initialize(window); }
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 Task<ExecutionResult> Execute(IReplWindow window, string arguments) { return window.Reset(); }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { ((NodejsReplEvaluator)window.Evaluator).Clear(); return ExecutionResult.Succeeded; }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { window.ClearScreen(); return ExecutionResult.Succeeded; }
public Task<ExecutionResult> Execute(IReplWindow window, string arguments) { window.AbortCommand(); 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(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; }
public virtual void TextViewCreated(IReplWindow window, ITextView view) { }
public void Execute(IReplWindow window, string arguments) { window.AbortCommand(); }
public static Task<ExecutionResult> _Initialize(this IReplEvaluator self, IReplWindow window) { self.CurrentWindow = window; return self.InitializeAsync(); }
public static Task <ExecutionResult> Initialize(this IReplEvaluator self, IReplWindow window) { self.CurrentWindow = window; return(self.InitializeAsync()); }
public NpmReplRedirector(IReplWindow window) { _window = window; HasErrors = false; }