示例#1
0
        ///<summary>Sends a series of keypress command to Visual Studio.</summary>
        public static void TypeChars(string s)
        {
            var target = (IOleCommandTarget)ProjectHelpers.GetCurrentNativeTextView();

            IntPtr variantIn = IntPtr.Zero;

            try
            {
                // Thanks @JaredPar
                variantIn = Marshal.AllocCoTaskMem(16); // size of(VARIANT)
                NativeMethods.VariantInit(variantIn);

                foreach (var c in s)
                {
                    var special = GetSpecialCommand(c);
                    if (special != null)
                    {
                        target.Execute(special.Value);
                    }
                    else
                    {
                        Marshal.GetNativeVariantForObject(c, variantIn);
                        target.Execute(VSConstants.VSStd2KCmdID.TYPECHAR, variantIn);
                    }
                }
            }
            finally
            {
                if (variantIn != IntPtr.Zero)
                {
                    NativeMethods.VariantClear(variantIn);
                    Marshal.FreeCoTaskMem(variantIn);
                }
            }
        }
示例#2
0
        public async Task DeletedImports()
        {
            var s2 = (Solution2)VSHost.DTE.Solution;

            s2.Create(TestCaseDirectory, "ImportDeleteTests");
            var template = s2.GetProjectTemplate("EmptyWebApplicationProject40.zip", "CSharp");

            s2.AddFromTemplate(template, Path.Combine(TestCaseDirectory, "WebAppProject2"), "WebAppProject.csproj");

            // To be discovered on save of dependent file
            File.WriteAllText(Path.Combine(TestCaseDirectory, "WebAppProject2", "_mixins.less"), "// Content...");

            AddProjectFile(Path.Combine(TestCaseDirectory, "WebAppProject2", "page.less"), "@import '_mixins';");

            await graph.RescanComplete;

            var deps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(TestCaseDirectory, "WebAppProject2", "_mixins.less")
                );

            deps
            .Select(Path.GetFileName)
            .Should()
            .BeEquivalentTo(new[] { "page.less" });

            var window = VSHost.DTE.ItemOperations.OpenFile(Path.Combine(TestCaseDirectory, "WebAppProject2", "page.less"));

            await VSHost.Dispatcher.NextFrame();    // Text editoro commands must be sent from the UI thread

            var target = (IOleCommandTarget)ProjectHelpers.GetCurrentNativeTextView();

            target.Execute(VSConstants.VSStd97CmdID.SelectAll);
            await VSHost.TypeString("// Import was removed");

            window.Document.Save();

            await graph.RescanComplete;

            deps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(TestCaseDirectory, "WebAppProject2", "_mixins.less")
                );

            deps
            .Select(Path.GetFileName)
            .Should()
            .BeEmpty();
        }