From 1889c70add179100c2cbb99180fb3696ac0cc553 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 1 Mar 2016 14:13:45 -0800 Subject: [PATCH 1/4] a --- .../Utilities.UI/UI/InteractiveWindow.cs | 620 +++++++++--------- .../NodejsPackageParametersExtension.cs | 40 +- 2 files changed, 330 insertions(+), 330 deletions(-) diff --git a/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs b/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs index 99669bd41..2abcdb569 100644 --- a/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs +++ b/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs @@ -1,310 +1,310 @@ -/* **************************************************************************** - * - * Copyright (c) Microsoft Corporation. - * - * This source code is subject to terms and conditions of the Apache License, Version 2.0. A - * copy of the license can be found in the License.html file at the root of this distribution. If - * you cannot locate the Apache License, Version 2.0, please send an email to - * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound - * by the terms of the Apache License, Version 2.0. - * - * You must not remove this notice, or any other, from this software. - * - * ***************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using System.Windows; -using System.Windows.Automation; -using System.Windows.Threading; -using Microsoft.VisualStudio.ComponentModelHost; -#if NTVS_FEATURE_INTERACTIVEWINDOW -using Microsoft.NodejsTools.Repl; -#else -using Microsoft.VisualStudio.Repl; -#endif -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.VisualStudio.Text.Editor; -using Microsoft.VisualStudioTools.VSTestHost; - -namespace TestUtilities.UI { - public class InteractiveWindow : EditorWindow { - const string CommandBase = "PythonInteractive."; - - - private sealed class ReplWindowInfo { - public readonly ManualResetEvent Idle = new ManualResetEvent(false); - public readonly ManualResetEvent ReadyForInput = new ManualResetEvent(false); - - public void OnReadyForInput() { - Console.WriteLine("Ready for input"); - ReadyForInput.Set(); - } - } - - private static ConditionalWeakTable _replWindows = new ConditionalWeakTable(); - - private readonly VisualStudioApp _app; - private readonly string _title; - private readonly ReplWindow _replWindow; - private readonly ReplWindowInfo _replWindowInfo; - - public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app) - : base(null, element) { - _app = app; - _title = title; - - var compModel = _app.GetService(typeof(SComponentModel)); - var replWindowProvider = compModel.GetService(); - _replWindow = replWindowProvider.GetReplWindows() - .OfType() - .FirstOrDefault(p => p.Title.Equals(title, StringComparison.CurrentCulture)); - - _replWindowInfo = _replWindows.GetValue(_replWindow, window => { - var info = new ReplWindowInfo(); - window.ReadyForInput += new Action(info.OnReadyForInput); - return info; - }); - } - - public void Close() { - var frame = _replWindow.Frame as IVsWindowFrame; - if (frame != null) { - frame.Hide(); - } - } - - public static void CloseAll(VisualStudioApp app = null) { - IComponentModel compModel; - if (app != null) { - compModel = app.GetService(typeof(SComponentModel)); - } else { - compModel = (IComponentModel)VSTestContext.ServiceProvider.GetService(typeof(SComponentModel)); - } - var replWindowProvider = compModel.GetService(); - foreach (var frame in replWindowProvider.GetReplWindows() - .OfType() - .Select(r => r.Frame) - .OfType()) { - frame.Hide(); - } - } - - public void WaitForIdleState() { - DispatchAndWait(_replWindowInfo.Idle, () => { }, DispatcherPriority.ApplicationIdle); - } - - public void DispatchAndWait(EventWaitHandle waitHandle, Action action, DispatcherPriority priority = DispatcherPriority.Normal) { - Dispatcher dispatcher = ((FrameworkElement)ReplWindow.TextView).Dispatcher; - waitHandle.Reset(); - - dispatcher.Invoke(new Action(() => { - action(); - waitHandle.Set(); - }), priority); - - Assert.IsTrue(waitHandle.WaitOne(500)); - } - - public void WaitForText(params string[] text) { - WaitForText((IList)text); - } - - public void WaitForText(IList text) { - string expected = null; - for (int i = 0; i < 100; i++) { - WaitForIdleState(); - expected = GetExpectedText(text); - if (expected.Equals(Text, StringComparison.CurrentCulture)) { - return; - } - Thread.Sleep(100); - } - - FailWrongText(expected); - } - - public void WaitForTextContainsAll(params string[] substrings) { - for (int i = 0; i < 100; ++i) { - WaitForIdleState(); - var text = Text; - if (substrings.All(s => text.Contains(s))) { - return; - } - Thread.Sleep(100); - } - - FailWrongText("All of: " + string.Join(", ", substrings.Select(s => "<" + s + ">"))); - } - - public void WaitForTextIPython(params string[] text) { - WaitForTextIPython((IList)text); - } - - public void WaitForTextIPython(IList text) { - string expected = null; - for (int i = 0; i < 100; i++) { - WaitForIdleState(); - expected = GetExpectedText(text); - if (expected.Equals(GetIPythonText(), StringComparison.CurrentCulture)) { - return; - } - Thread.Sleep(100); - } - - FailWrongTextIPython(expected); - } - - private string GetIPythonText() { - var text = Text; - var lines = Text.Split(new[] { "\r\n" }, StringSplitOptions.None); - StringBuilder res = new StringBuilder(); - for (int i = 0; i < lines.Length; i++) { - var line = lines[i]; - - if (!line.StartsWith("[IPKernelApp] ")) { - if (i != lines.Length - 1 || text.EndsWith("\r\n")) { - res.AppendLine(line); - } else { - res.Append(line); - } - } - } - return res.ToString(); - } - - public void WaitForTextStartIPython(params string[] text) { - string expected = GetExpectedText(text); - - for (int i = 0; i < 100; i++) { - string curText = Text; - - if (GetIPythonText().StartsWith(expected, StringComparison.CurrentCulture)) { - return; - } - Thread.Sleep(100); - } - - FailWrongText(expected); - } - - private void FailWrongText(string expected) { - StringBuilder msg = new StringBuilder("Did not get text: "); - AppendRepr(msg, expected); - msg.Append(" instead got "); - AppendRepr(msg, Text); - Assert.Fail(msg.ToString()); - } - - private void FailWrongTextIPython(string expected) { - StringBuilder msg = new StringBuilder("Did not get text: "); - AppendRepr(msg, expected); - msg.Append(" instead got "); - AppendRepr(msg, GetIPythonText()); - Assert.Fail(msg.ToString()); - } - - public void WaitForSessionDismissed() { - var sessionStack = IntellisenseSessionStack; - for (int i = 0; i < 20; i++) { - if (sessionStack.TopSession == null) { - break; - } - System.Threading.Thread.Sleep(500); - } - - while (sessionStack.TopSession != null) { - sessionStack.TopSession.Dismiss(); - } - Assert.AreEqual(null, sessionStack.TopSession); - } - - public ManualResetEvent ReadyForInput { - get { - return _replWindowInfo.ReadyForInput; - } - } - - public void ClearInput() { - var buffer = _replWindow.CurrentLanguageBuffer; - if (buffer == null) { - return; - } - - var edit = buffer.CreateEdit(); - edit.Delete(0, edit.Snapshot.Length); - edit.Apply(); - } - - public void ClearScreen(bool waitForReady = true) { - Console.WriteLine("REPL Clearing screen"); - if (waitForReady) { - ReadyForInput.Reset(); - } - _app.ExecuteCommand(CommandBase + "ClearScreen"); - if (waitForReady) { - Assert.IsTrue(ReadyForInput.WaitOne(1000)); - } - } - - public void CancelExecution(int attempts = 100) { - Console.WriteLine("REPL Cancelling Execution"); - ReadyForInput.Reset(); - for (int i = 0; i < attempts && !_replWindowInfo.ReadyForInput.WaitOne(0); i++) { - ReadyForInput.Reset(); - try { - _app.ExecuteCommand(CommandBase + "CancelExecution"); - } catch { - // command may not be immediately available - } - if (ReadyForInput.WaitOne(1000)) { - break; - } - } - Assert.IsTrue(ReadyForInput.WaitOne(10000)); - } - - internal IReplWindow2 ReplWindow { - get { - return _replWindow; - } - } - - public override IWpfTextView TextView { - get { - return ReplWindow.TextView; - } - } - - public void Reset() { - Console.WriteLine("REPL resetting"); - - Assert.IsTrue(ReplWindow.Reset().Wait(10000)); - } - - public void WithStandardInputPrompt(string prompt, Action action) { - if ((bool)ReplWindow.GetOptionValue(ReplOptions.DisplayPromptInMargin)) { - action(String.Empty); - return; - } - - string oldPrompt = (string)ReplWindow.GetOptionValue(ReplOptions.StandardInputPrompt); - ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, prompt); - try { - action(prompt); - } finally { - ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, oldPrompt); - } - } - - internal virtual bool IsTabGroupContainer(AutomationElement element) { - var clsName = element.GetCurrentPropertyValue(AutomationElement.ClassNameProperty) as string; - return clsName == "ToolWindowTabGroupContainer" || clsName == "FloatingWindow"; - } - } -} +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Threading; +using Microsoft.VisualStudio.ComponentModelHost; +#if NTVS_FEATURE_INTERACTIVEWINDOW +using Microsoft.NodejsTools.Repl; +#else +using Microsoft.VisualStudio.Repl; +#endif +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.Text.Editor; +using Microsoft.VisualStudioTools.VSTestHost; + +namespace TestUtilities.UI { + public class InteractiveWindow : EditorWindow { + const string CommandBase = "PythonInteractive."; + + + private sealed class ReplWindowInfo { + public readonly ManualResetEvent Idle = new ManualResetEvent(false); + public readonly ManualResetEvent ReadyForInput = new ManualResetEvent(false); + + public void OnReadyForInput() { + Console.WriteLine("Ready for input"); + ReadyForInput.Set(); + } + } + + private static ConditionalWeakTable _replWindows = new ConditionalWeakTable(); + + private readonly VisualStudioApp _app; + private readonly string _title; + private readonly ReplWindow _replWindow; + private readonly ReplWindowInfo _replWindowInfo; + + public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app) + : base(null, element) { + _app = app; + _title = title; + + var compModel = _app.GetService(typeof(SComponentModel)); + var replWindowProvider = compModel.GetService(); + _replWindow = replWindowProvider.GetReplWindows() + .OfType() + .FirstOrDefault(p => p.Title.Equals(title, StringComparison.CurrentCulture)); + + _replWindowInfo = _replWindows.GetValue(_replWindow, window => { + var info = new ReplWindowInfo(); + window.ReadyForInput += new Action(info.OnReadyForInput); + return info; + }); + } + + public void Close() { + var frame = _replWindow.Frame as IVsWindowFrame; + if (frame != null) { + frame.Hide(); + } + } + + public static void CloseAll(VisualStudioApp app = null) { + IComponentModel compModel; + if (app != null) { + compModel = app.GetService(typeof(SComponentModel)); + } else { + compModel = (IComponentModel)VSTestContext.ServiceProvider.GetService(typeof(SComponentModel)); + } + var replWindowProvider = compModel.GetService(); + foreach (var frame in replWindowProvider.GetReplWindows() + .OfType() + .Select(r => r.Frame) + .OfType()) { + frame.Hide(); + } + } + + public void WaitForIdleState() { + DispatchAndWait(_replWindowInfo.Idle, () => { }, DispatcherPriority.ApplicationIdle); + } + + public void DispatchAndWait(EventWaitHandle waitHandle, Action action, DispatcherPriority priority = DispatcherPriority.Normal) { + Dispatcher dispatcher = ((FrameworkElement)ReplWindow.TextView).Dispatcher; + waitHandle.Reset(); + + dispatcher.Invoke(new Action(() => { + action(); + waitHandle.Set(); + }), priority); + + Assert.IsTrue(waitHandle.WaitOne(500)); + } + + public void WaitForText(params string[] text) { + WaitForText((IList)text); + } + + public void WaitForText(IList text) { + string expected = null; + for (int i = 0; i < 100; i++) { + WaitForIdleState(); + expected = GetExpectedText(text); + if (expected.Equals(Text, StringComparison.CurrentCulture)) { + return; + } + Thread.Sleep(100); + } + + FailWrongText(expected); + } + + public void WaitForTextContainsAll(params string[] substrings) { + for (int i = 0; i < 100; ++i) { + WaitForIdleState(); + var text = Text; + if (substrings.All(s => text.Contains(s))) { + return; + } + Thread.Sleep(100); + } + + FailWrongText("All of: " + string.Join(", ", substrings.Select(s => "<" + s + ">"))); + } + + public void WaitForTextIPython(params string[] text) { + WaitForTextIPython((IList)text); + } + + public void WaitForTextIPython(IList text) { + string expected = null; + for (int i = 0; i < 100; i++) { + WaitForIdleState(); + expected = GetExpectedText(text); + if (expected.Equals(GetIPythonText(), StringComparison.CurrentCulture)) { + return; + } + Thread.Sleep(100); + } + + FailWrongTextIPython(expected); + } + + private string GetIPythonText() { + var text = Text; + var lines = Text.Split(new[] { "\r\n" }, StringSplitOptions.None); + StringBuilder res = new StringBuilder(); + for (int i = 0; i < lines.Length; i++) { + var line = lines[i]; + + if (!line.StartsWith("[IPKernelApp] ")) { + if (i != lines.Length - 1 || text.EndsWith("\r\n")) { + res.AppendLine(line); + } else { + res.Append(line); + } + } + } + return res.ToString(); + } + + public void WaitForTextStartIPython(params string[] text) { + string expected = GetExpectedText(text); + + for (int i = 0; i < 100; i++) { + string curText = Text; + + if (GetIPythonText().StartsWith(expected, StringComparison.CurrentCulture)) { + return; + } + Thread.Sleep(100); + } + + FailWrongText(expected); + } + + private void FailWrongText(string expected) { + StringBuilder msg = new StringBuilder("Did not get text: "); + AppendRepr(msg, expected); + msg.Append(" instead got "); + AppendRepr(msg, Text); + Assert.Fail(msg.ToString()); + } + + private void FailWrongTextIPython(string expected) { + StringBuilder msg = new StringBuilder("Did not get text: "); + AppendRepr(msg, expected); + msg.Append(" instead got "); + AppendRepr(msg, GetIPythonText()); + Assert.Fail(msg.ToString()); + } + + public void WaitForSessionDismissed() { + var sessionStack = IntellisenseSessionStack; + for (int i = 0; i < 20; i++) { + if (sessionStack.TopSession == null) { + break; + } + System.Threading.Thread.Sleep(500); + } + + while (sessionStack.TopSession != null) { + sessionStack.TopSession.Dismiss(); + } + Assert.AreEqual(null, sessionStack.TopSession); + } + + public ManualResetEvent ReadyForInput { + get { + return _replWindowInfo.ReadyForInput; + } + } + + public void ClearInput() { + var buffer = _replWindow.CurrentLanguageBuffer; + if (buffer == null) { + return; + } + + var edit = buffer.CreateEdit(); + edit.Delete(0, edit.Snapshot.Length); + edit.Apply(); + } + + public void ClearScreen(bool waitForReady = true) { + Console.WriteLine("REPL Clearing screen"); + if (waitForReady) { + ReadyForInput.Reset(); + } + _app.ExecuteCommand(CommandBase + "ClearScreen"); + if (waitForReady) { + Assert.IsTrue(ReadyForInput.WaitOne(1000)); + } + } + + public void CancelExecution(int attempts = 100) { + Console.WriteLine("REPL Cancelling Execution"); + ReadyForInput.Reset(); + for (int i = 0; i < attempts && !_replWindowInfo.ReadyForInput.WaitOne(0); i++) { + ReadyForInput.Reset(); + try { + _app.ExecuteCommand(CommandBase + "CancelExecution"); + } catch { + // command may not be immediately available + } + if (ReadyForInput.WaitOne(1000)) { + break; + } + } + Assert.IsTrue(ReadyForInput.WaitOne(10000)); + } + + internal IReplWindow2 ReplWindow { + get { + return _replWindow; + } + } + + public override IWpfTextView TextView { + get { + return ReplWindow.TextView; + } + } + + public void Reset() { + Console.WriteLine("REPL resetting"); + + Assert.IsTrue(ReplWindow.Reset().Wait(10000)); + } + + public void WithStandardInputPrompt(string prompt, Action action) { + if ((bool)ReplWindow.GetOptionValue(ReplOptions.DisplayPromptInMargin)) { + action(String.Empty); + return; + } + + string oldPrompt = (string)ReplWindow.GetOptionValue(ReplOptions.StandardInputPrompt); + ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, prompt); + try { + action(prompt); + } finally { + ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, oldPrompt); + } + } + + internal virtual bool IsTabGroupContainer(AutomationElement element) { + var clsName = element.GetCurrentPropertyValue(AutomationElement.ClassNameProperty) as string; + return clsName == "ToolWindowTabGroupContainer" || clsName == "FloatingWindow"; + } + } +} diff --git a/Nodejs/Product/ProjectWizard/NodejsPackageParametersExtension.cs b/Nodejs/Product/ProjectWizard/NodejsPackageParametersExtension.cs index 406411bbf..49101ccf8 100644 --- a/Nodejs/Product/ProjectWizard/NodejsPackageParametersExtension.cs +++ b/Nodejs/Product/ProjectWizard/NodejsPackageParametersExtension.cs @@ -19,7 +19,7 @@ using System.Text.RegularExpressions; using EnvDTE; using Microsoft.VisualStudio.TemplateWizard; - + namespace Microsoft.NodejsTools.ProjectWizard { class NodejsPackageParametersExtension : IWizard { public void RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { @@ -45,25 +45,25 @@ public void BeforeOpeningFile(ProjectItem projectItem) { public void RunFinished() { return; - } - - private const int NpmPackageNameMaxLength = 214; - - /// - /// Normalize a project name to be a valid Npm package name: https://docs.npmjs.com/files/package.json#name - /// - /// Name of a VS project. - private static string NormalizeNpmPackageName(string projectName) { - // Remove all leading url-invalid, underscore, and period characters - var npmProjectNameTransform = Regex.Replace(projectName, "^[^a-zA-Z0-9-~]*", string.Empty); - - // Replace all invalid characters with a dash - npmProjectNameTransform = Regex.Replace(npmProjectNameTransform, "[^a-zA-Z0-9-_~.]", "-"); - - // Insert hyphens between camelcased sections. - npmProjectNameTransform = Regex.Replace(npmProjectNameTransform, "([a-z0-9])([A-Z])", "$1-$2").ToLowerInvariant(); - - return npmProjectNameTransform.Substring(0, Math.Min(npmProjectNameTransform.Length, NpmPackageNameMaxLength)); + } + + private const int NpmPackageNameMaxLength = 214; + + /// + /// Normalize a project name to be a valid Npm package name: https://docs.npmjs.com/files/package.json#name + /// + /// Name of a VS project. + private static string NormalizeNpmPackageName(string projectName) { + // Remove all leading url-invalid, underscore, and period characters + var npmProjectNameTransform = Regex.Replace(projectName, "^[^a-zA-Z0-9-~]*", string.Empty); + + // Replace all invalid characters with a dash + npmProjectNameTransform = Regex.Replace(npmProjectNameTransform, "[^a-zA-Z0-9-_~.]", "-"); + + // Insert hyphens between camelcased sections. + npmProjectNameTransform = Regex.Replace(npmProjectNameTransform, "([a-z0-9])([A-Z])", "$1-$2").ToLowerInvariant(); + + return npmProjectNameTransform.Substring(0, Math.Min(npmProjectNameTransform.Length, NpmPackageNameMaxLength)); } } } From e03d93d4233b6896113c6441f9fde7190a777c8d Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 2 Mar 2016 14:15:35 -0800 Subject: [PATCH 2/4] Remove text attribute from .gitattributes for *.cs files I added the text attribute after bulk converting all *.cs files to crlf line endings, thinking that it would force edits to also use crlf going foward. Instead, it's causing a ton of trouble for me and introducing lots of fake edits. Here's the problem: * On a clean branch, use VS to edit a file. * Verify that the file has crlf line endings before editing it. * Save the file. * File still has crlf line endings. * git now shows the entire file has been changed. Removing the text attribute gets us back to where we started and fixed the problem for me. --- .gitattributes | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index 613f8f6e5..a77fe007e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,4 @@ # Do not normalize line endings from CR LF to LF, regardless of core.autocrlf. * -text -# Normalize C# source files to use CR LF line endings. -*.cs text eol=crlf +*.cs diff=csharp From 6a070e7bcbcae05ef35636e65f17a802a1f9c19b Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 2 Mar 2016 14:25:04 -0800 Subject: [PATCH 3/4] Undo InteractiveWindow.cs change --- .../Utilities.UI/UI/InteractiveWindow.cs | 620 +++++++++--------- 1 file changed, 310 insertions(+), 310 deletions(-) diff --git a/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs b/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs index 2abcdb569..99669bd41 100644 --- a/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs +++ b/Common/Tests/Utilities.UI/UI/InteractiveWindow.cs @@ -1,310 +1,310 @@ -/* **************************************************************************** - * - * Copyright (c) Microsoft Corporation. - * - * This source code is subject to terms and conditions of the Apache License, Version 2.0. A - * copy of the license can be found in the License.html file at the root of this distribution. If - * you cannot locate the Apache License, Version 2.0, please send an email to - * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound - * by the terms of the Apache License, Version 2.0. - * - * You must not remove this notice, or any other, from this software. - * - * ***************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using System.Windows; -using System.Windows.Automation; -using System.Windows.Threading; -using Microsoft.VisualStudio.ComponentModelHost; -#if NTVS_FEATURE_INTERACTIVEWINDOW -using Microsoft.NodejsTools.Repl; -#else -using Microsoft.VisualStudio.Repl; -#endif -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.VisualStudio.Text.Editor; -using Microsoft.VisualStudioTools.VSTestHost; - -namespace TestUtilities.UI { - public class InteractiveWindow : EditorWindow { - const string CommandBase = "PythonInteractive."; - - - private sealed class ReplWindowInfo { - public readonly ManualResetEvent Idle = new ManualResetEvent(false); - public readonly ManualResetEvent ReadyForInput = new ManualResetEvent(false); - - public void OnReadyForInput() { - Console.WriteLine("Ready for input"); - ReadyForInput.Set(); - } - } - - private static ConditionalWeakTable _replWindows = new ConditionalWeakTable(); - - private readonly VisualStudioApp _app; - private readonly string _title; - private readonly ReplWindow _replWindow; - private readonly ReplWindowInfo _replWindowInfo; - - public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app) - : base(null, element) { - _app = app; - _title = title; - - var compModel = _app.GetService(typeof(SComponentModel)); - var replWindowProvider = compModel.GetService(); - _replWindow = replWindowProvider.GetReplWindows() - .OfType() - .FirstOrDefault(p => p.Title.Equals(title, StringComparison.CurrentCulture)); - - _replWindowInfo = _replWindows.GetValue(_replWindow, window => { - var info = new ReplWindowInfo(); - window.ReadyForInput += new Action(info.OnReadyForInput); - return info; - }); - } - - public void Close() { - var frame = _replWindow.Frame as IVsWindowFrame; - if (frame != null) { - frame.Hide(); - } - } - - public static void CloseAll(VisualStudioApp app = null) { - IComponentModel compModel; - if (app != null) { - compModel = app.GetService(typeof(SComponentModel)); - } else { - compModel = (IComponentModel)VSTestContext.ServiceProvider.GetService(typeof(SComponentModel)); - } - var replWindowProvider = compModel.GetService(); - foreach (var frame in replWindowProvider.GetReplWindows() - .OfType() - .Select(r => r.Frame) - .OfType()) { - frame.Hide(); - } - } - - public void WaitForIdleState() { - DispatchAndWait(_replWindowInfo.Idle, () => { }, DispatcherPriority.ApplicationIdle); - } - - public void DispatchAndWait(EventWaitHandle waitHandle, Action action, DispatcherPriority priority = DispatcherPriority.Normal) { - Dispatcher dispatcher = ((FrameworkElement)ReplWindow.TextView).Dispatcher; - waitHandle.Reset(); - - dispatcher.Invoke(new Action(() => { - action(); - waitHandle.Set(); - }), priority); - - Assert.IsTrue(waitHandle.WaitOne(500)); - } - - public void WaitForText(params string[] text) { - WaitForText((IList)text); - } - - public void WaitForText(IList text) { - string expected = null; - for (int i = 0; i < 100; i++) { - WaitForIdleState(); - expected = GetExpectedText(text); - if (expected.Equals(Text, StringComparison.CurrentCulture)) { - return; - } - Thread.Sleep(100); - } - - FailWrongText(expected); - } - - public void WaitForTextContainsAll(params string[] substrings) { - for (int i = 0; i < 100; ++i) { - WaitForIdleState(); - var text = Text; - if (substrings.All(s => text.Contains(s))) { - return; - } - Thread.Sleep(100); - } - - FailWrongText("All of: " + string.Join(", ", substrings.Select(s => "<" + s + ">"))); - } - - public void WaitForTextIPython(params string[] text) { - WaitForTextIPython((IList)text); - } - - public void WaitForTextIPython(IList text) { - string expected = null; - for (int i = 0; i < 100; i++) { - WaitForIdleState(); - expected = GetExpectedText(text); - if (expected.Equals(GetIPythonText(), StringComparison.CurrentCulture)) { - return; - } - Thread.Sleep(100); - } - - FailWrongTextIPython(expected); - } - - private string GetIPythonText() { - var text = Text; - var lines = Text.Split(new[] { "\r\n" }, StringSplitOptions.None); - StringBuilder res = new StringBuilder(); - for (int i = 0; i < lines.Length; i++) { - var line = lines[i]; - - if (!line.StartsWith("[IPKernelApp] ")) { - if (i != lines.Length - 1 || text.EndsWith("\r\n")) { - res.AppendLine(line); - } else { - res.Append(line); - } - } - } - return res.ToString(); - } - - public void WaitForTextStartIPython(params string[] text) { - string expected = GetExpectedText(text); - - for (int i = 0; i < 100; i++) { - string curText = Text; - - if (GetIPythonText().StartsWith(expected, StringComparison.CurrentCulture)) { - return; - } - Thread.Sleep(100); - } - - FailWrongText(expected); - } - - private void FailWrongText(string expected) { - StringBuilder msg = new StringBuilder("Did not get text: "); - AppendRepr(msg, expected); - msg.Append(" instead got "); - AppendRepr(msg, Text); - Assert.Fail(msg.ToString()); - } - - private void FailWrongTextIPython(string expected) { - StringBuilder msg = new StringBuilder("Did not get text: "); - AppendRepr(msg, expected); - msg.Append(" instead got "); - AppendRepr(msg, GetIPythonText()); - Assert.Fail(msg.ToString()); - } - - public void WaitForSessionDismissed() { - var sessionStack = IntellisenseSessionStack; - for (int i = 0; i < 20; i++) { - if (sessionStack.TopSession == null) { - break; - } - System.Threading.Thread.Sleep(500); - } - - while (sessionStack.TopSession != null) { - sessionStack.TopSession.Dismiss(); - } - Assert.AreEqual(null, sessionStack.TopSession); - } - - public ManualResetEvent ReadyForInput { - get { - return _replWindowInfo.ReadyForInput; - } - } - - public void ClearInput() { - var buffer = _replWindow.CurrentLanguageBuffer; - if (buffer == null) { - return; - } - - var edit = buffer.CreateEdit(); - edit.Delete(0, edit.Snapshot.Length); - edit.Apply(); - } - - public void ClearScreen(bool waitForReady = true) { - Console.WriteLine("REPL Clearing screen"); - if (waitForReady) { - ReadyForInput.Reset(); - } - _app.ExecuteCommand(CommandBase + "ClearScreen"); - if (waitForReady) { - Assert.IsTrue(ReadyForInput.WaitOne(1000)); - } - } - - public void CancelExecution(int attempts = 100) { - Console.WriteLine("REPL Cancelling Execution"); - ReadyForInput.Reset(); - for (int i = 0; i < attempts && !_replWindowInfo.ReadyForInput.WaitOne(0); i++) { - ReadyForInput.Reset(); - try { - _app.ExecuteCommand(CommandBase + "CancelExecution"); - } catch { - // command may not be immediately available - } - if (ReadyForInput.WaitOne(1000)) { - break; - } - } - Assert.IsTrue(ReadyForInput.WaitOne(10000)); - } - - internal IReplWindow2 ReplWindow { - get { - return _replWindow; - } - } - - public override IWpfTextView TextView { - get { - return ReplWindow.TextView; - } - } - - public void Reset() { - Console.WriteLine("REPL resetting"); - - Assert.IsTrue(ReplWindow.Reset().Wait(10000)); - } - - public void WithStandardInputPrompt(string prompt, Action action) { - if ((bool)ReplWindow.GetOptionValue(ReplOptions.DisplayPromptInMargin)) { - action(String.Empty); - return; - } - - string oldPrompt = (string)ReplWindow.GetOptionValue(ReplOptions.StandardInputPrompt); - ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, prompt); - try { - action(prompt); - } finally { - ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, oldPrompt); - } - } - - internal virtual bool IsTabGroupContainer(AutomationElement element) { - var clsName = element.GetCurrentPropertyValue(AutomationElement.ClassNameProperty) as string; - return clsName == "ToolWindowTabGroupContainer" || clsName == "FloatingWindow"; - } - } -} +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Threading; +using Microsoft.VisualStudio.ComponentModelHost; +#if NTVS_FEATURE_INTERACTIVEWINDOW +using Microsoft.NodejsTools.Repl; +#else +using Microsoft.VisualStudio.Repl; +#endif +using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.Text.Editor; +using Microsoft.VisualStudioTools.VSTestHost; + +namespace TestUtilities.UI { + public class InteractiveWindow : EditorWindow { + const string CommandBase = "PythonInteractive."; + + + private sealed class ReplWindowInfo { + public readonly ManualResetEvent Idle = new ManualResetEvent(false); + public readonly ManualResetEvent ReadyForInput = new ManualResetEvent(false); + + public void OnReadyForInput() { + Console.WriteLine("Ready for input"); + ReadyForInput.Set(); + } + } + + private static ConditionalWeakTable _replWindows = new ConditionalWeakTable(); + + private readonly VisualStudioApp _app; + private readonly string _title; + private readonly ReplWindow _replWindow; + private readonly ReplWindowInfo _replWindowInfo; + + public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app) + : base(null, element) { + _app = app; + _title = title; + + var compModel = _app.GetService(typeof(SComponentModel)); + var replWindowProvider = compModel.GetService(); + _replWindow = replWindowProvider.GetReplWindows() + .OfType() + .FirstOrDefault(p => p.Title.Equals(title, StringComparison.CurrentCulture)); + + _replWindowInfo = _replWindows.GetValue(_replWindow, window => { + var info = new ReplWindowInfo(); + window.ReadyForInput += new Action(info.OnReadyForInput); + return info; + }); + } + + public void Close() { + var frame = _replWindow.Frame as IVsWindowFrame; + if (frame != null) { + frame.Hide(); + } + } + + public static void CloseAll(VisualStudioApp app = null) { + IComponentModel compModel; + if (app != null) { + compModel = app.GetService(typeof(SComponentModel)); + } else { + compModel = (IComponentModel)VSTestContext.ServiceProvider.GetService(typeof(SComponentModel)); + } + var replWindowProvider = compModel.GetService(); + foreach (var frame in replWindowProvider.GetReplWindows() + .OfType() + .Select(r => r.Frame) + .OfType()) { + frame.Hide(); + } + } + + public void WaitForIdleState() { + DispatchAndWait(_replWindowInfo.Idle, () => { }, DispatcherPriority.ApplicationIdle); + } + + public void DispatchAndWait(EventWaitHandle waitHandle, Action action, DispatcherPriority priority = DispatcherPriority.Normal) { + Dispatcher dispatcher = ((FrameworkElement)ReplWindow.TextView).Dispatcher; + waitHandle.Reset(); + + dispatcher.Invoke(new Action(() => { + action(); + waitHandle.Set(); + }), priority); + + Assert.IsTrue(waitHandle.WaitOne(500)); + } + + public void WaitForText(params string[] text) { + WaitForText((IList)text); + } + + public void WaitForText(IList text) { + string expected = null; + for (int i = 0; i < 100; i++) { + WaitForIdleState(); + expected = GetExpectedText(text); + if (expected.Equals(Text, StringComparison.CurrentCulture)) { + return; + } + Thread.Sleep(100); + } + + FailWrongText(expected); + } + + public void WaitForTextContainsAll(params string[] substrings) { + for (int i = 0; i < 100; ++i) { + WaitForIdleState(); + var text = Text; + if (substrings.All(s => text.Contains(s))) { + return; + } + Thread.Sleep(100); + } + + FailWrongText("All of: " + string.Join(", ", substrings.Select(s => "<" + s + ">"))); + } + + public void WaitForTextIPython(params string[] text) { + WaitForTextIPython((IList)text); + } + + public void WaitForTextIPython(IList text) { + string expected = null; + for (int i = 0; i < 100; i++) { + WaitForIdleState(); + expected = GetExpectedText(text); + if (expected.Equals(GetIPythonText(), StringComparison.CurrentCulture)) { + return; + } + Thread.Sleep(100); + } + + FailWrongTextIPython(expected); + } + + private string GetIPythonText() { + var text = Text; + var lines = Text.Split(new[] { "\r\n" }, StringSplitOptions.None); + StringBuilder res = new StringBuilder(); + for (int i = 0; i < lines.Length; i++) { + var line = lines[i]; + + if (!line.StartsWith("[IPKernelApp] ")) { + if (i != lines.Length - 1 || text.EndsWith("\r\n")) { + res.AppendLine(line); + } else { + res.Append(line); + } + } + } + return res.ToString(); + } + + public void WaitForTextStartIPython(params string[] text) { + string expected = GetExpectedText(text); + + for (int i = 0; i < 100; i++) { + string curText = Text; + + if (GetIPythonText().StartsWith(expected, StringComparison.CurrentCulture)) { + return; + } + Thread.Sleep(100); + } + + FailWrongText(expected); + } + + private void FailWrongText(string expected) { + StringBuilder msg = new StringBuilder("Did not get text: "); + AppendRepr(msg, expected); + msg.Append(" instead got "); + AppendRepr(msg, Text); + Assert.Fail(msg.ToString()); + } + + private void FailWrongTextIPython(string expected) { + StringBuilder msg = new StringBuilder("Did not get text: "); + AppendRepr(msg, expected); + msg.Append(" instead got "); + AppendRepr(msg, GetIPythonText()); + Assert.Fail(msg.ToString()); + } + + public void WaitForSessionDismissed() { + var sessionStack = IntellisenseSessionStack; + for (int i = 0; i < 20; i++) { + if (sessionStack.TopSession == null) { + break; + } + System.Threading.Thread.Sleep(500); + } + + while (sessionStack.TopSession != null) { + sessionStack.TopSession.Dismiss(); + } + Assert.AreEqual(null, sessionStack.TopSession); + } + + public ManualResetEvent ReadyForInput { + get { + return _replWindowInfo.ReadyForInput; + } + } + + public void ClearInput() { + var buffer = _replWindow.CurrentLanguageBuffer; + if (buffer == null) { + return; + } + + var edit = buffer.CreateEdit(); + edit.Delete(0, edit.Snapshot.Length); + edit.Apply(); + } + + public void ClearScreen(bool waitForReady = true) { + Console.WriteLine("REPL Clearing screen"); + if (waitForReady) { + ReadyForInput.Reset(); + } + _app.ExecuteCommand(CommandBase + "ClearScreen"); + if (waitForReady) { + Assert.IsTrue(ReadyForInput.WaitOne(1000)); + } + } + + public void CancelExecution(int attempts = 100) { + Console.WriteLine("REPL Cancelling Execution"); + ReadyForInput.Reset(); + for (int i = 0; i < attempts && !_replWindowInfo.ReadyForInput.WaitOne(0); i++) { + ReadyForInput.Reset(); + try { + _app.ExecuteCommand(CommandBase + "CancelExecution"); + } catch { + // command may not be immediately available + } + if (ReadyForInput.WaitOne(1000)) { + break; + } + } + Assert.IsTrue(ReadyForInput.WaitOne(10000)); + } + + internal IReplWindow2 ReplWindow { + get { + return _replWindow; + } + } + + public override IWpfTextView TextView { + get { + return ReplWindow.TextView; + } + } + + public void Reset() { + Console.WriteLine("REPL resetting"); + + Assert.IsTrue(ReplWindow.Reset().Wait(10000)); + } + + public void WithStandardInputPrompt(string prompt, Action action) { + if ((bool)ReplWindow.GetOptionValue(ReplOptions.DisplayPromptInMargin)) { + action(String.Empty); + return; + } + + string oldPrompt = (string)ReplWindow.GetOptionValue(ReplOptions.StandardInputPrompt); + ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, prompt); + try { + action(prompt); + } finally { + ReplWindow.SetOptionValue(ReplOptions.StandardInputPrompt, oldPrompt); + } + } + + internal virtual bool IsTabGroupContainer(AutomationElement element) { + var clsName = element.GetCurrentPropertyValue(AutomationElement.ClassNameProperty) as string; + return clsName == "ToolWindowTabGroupContainer" || clsName == "FloatingWindow"; + } + } +} From b3e1d831f04c07893f6280359272540311c7a1cb Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 2 Mar 2016 14:29:27 -0800 Subject: [PATCH 4/4] Just remove entire c# section for now --- .gitattributes | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index a77fe007e..1db95efd6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,2 @@ # Do not normalize line endings from CR LF to LF, regardless of core.autocrlf. * -text - -*.cs diff=csharp