Пример #1
0
        private static ToolWindowPane ActivateInteractiveWindow(ReplWindowProxySettings settings, VisualStudioApp app, string projectName, string workspaceName, string backend)
        {
            string description = null;

            if (settings.Version.IsCPython)
            {
                description = string.Format("{0} {1}",
                                            settings.Version.Isx64 ? "Python 64-bit" : "Python 32-bit",
                                            settings.Version.Version.ToVersion()
                                            );
            }
            else if (settings.Version.IsIronPython)
            {
                description = string.Format("{0} {1}",
                                            settings.Version.Isx64 ? "IronPython 64-bit" : "IronPython",
                                            settings.Version.Version.ToVersion()
                                            );
            }
            Assert.IsNotNull(description, "Unknown interpreter");

            var automation  = (IVsPython)app.Dte.GetObject("VsPython");
            var options     = (IPythonOptions)automation;
            var replOptions = options.Interactive;

            Assert.IsNotNull(replOptions, "Could not find options for " + description);

            var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;

            app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
            options.Intellisense.AddNewLineAtEndOfFullyTypedWord = settings.AddNewLineAtEndOfFullyTypedWord;

            var interpreters = app.ComponentModel.GetService <IInterpreterRegistryService>();
            var replId       = PythonReplEvaluatorProvider.GetEvaluatorId(
                interpreters.FindConfiguration(settings.Version.Id)
                );

            if (!string.IsNullOrEmpty(projectName))
            {
                var dteProj = app.GetProject(projectName);
                var proj    = (PythonProjectNode)dteProj.GetCommonProject();
                replId = PythonReplEvaluatorProvider.GetEvaluatorId(proj);
            }
            else if (!string.IsNullOrEmpty(workspaceName))
            {
                var workspaceContextProvider = app.ComponentModel.GetService <IPythonWorkspaceContextProvider>();
                replId = PythonReplEvaluatorProvider.GetEvaluatorId(workspaceContextProvider.Workspace);
            }

            return(app.ServiceProvider.GetUIThread().Invoke(() => {
                app.ServiceProvider.GetPythonToolsService().InteractiveBackendOverride = backend;
                var provider = app.ComponentModel.GetService <InteractiveWindowProvider>();
                return (ToolWindowPane)provider.OpenOrCreate(replId);
            }));
        }
        public void TestClientServerIntelliSenseModes()
        {
            string
                solutionLabel                       = "Solution 'ClientServerCode' (1 project)",
                projectLabel                        = "ClientServerCode",
                nodeDirectoryLabel                  = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node),
                nodeSubDirectoryLabel               = NodejsFolderNode.AppendLabel("NodeSubDirectory", FolderContentType.Node),
                browserDirectoryLabel               = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser),
                emptyBrowserSubDirectoryLabel       = "BrowserSubDirectory",
                browserSubDirectoryLabel            = NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Browser),
                mixedDirectoryLabel                 = NodejsFolderNode.AppendLabel("MixedDirectory", FolderContentType.Mixed),
                mixedDirectoryBrowserDirectoryLabel = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser),
                mixedDirectoryNodeDirectoryLabel    = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node),
                browserCodeLabel                    = "browserCode.js",
                mixedDirectoryRenamedLabel          = NodejsFolderNode.AppendLabel("MixedDirectoryRenamed", FolderContentType.Mixed);

            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ClientServerCode\ClientServerCode.sln");

                using (new NodejsOptionHolder(NodejsPackage.Instance.GeneralOptionsPage, "ShowBrowserAndNodeLabels", true)) {
                    // Wait until project is loaded
                    var solutionExplorer = app.OpenSolutionExplorer();

                    solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        "app.js");

                    var nodejsProject = app.GetProject("ClientServerCode").GetNodejsProject();

                    var projectNode = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel);

                    var browserDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserDirectory,
                        "Browser directories should be labeled as such. Could not find " + browserDirectoryLabel);

                    var browserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        emptyBrowserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserSubDirectory,
                        "Project initialization: could not find " + emptyBrowserSubDirectoryLabel);

                    var nodeDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        nodeDirectoryLabel
                        );
                    Assert.IsNotNull(
                        nodeDirectory,
                        "Node directories should be labeled as such. Could not find " + nodeDirectoryLabel);

                    var nodeSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        nodeDirectoryLabel,
                        nodeSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        nodeSubDirectory,
                        "Project initialization: could not find " + nodeSubDirectoryLabel);

                    projectNode.Select();
                    using (var newItem = NewItemDialog.FromDte(app)) {
                        newItem.FileName = "newItem.js";
                        newItem.OK();
                    }

                    Assert.AreEqual(
                        "Compile",
                        nodejsProject.GetItemType("newItem.js"),
                        "Top level files should be set to item type 'Compile'");

                    Keyboard.Type("process.");
                    Keyboard.Type(Keyboard.CtrlSpace.ToString());

                    using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"newItem.js")).WaitForSession <ICompletionSession>()) {
                        var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText);
                        Assert.IsTrue(
                            completions.Contains("env"),
                            "New documents of the node type should open with default VS editor"
                            );
                    }

                    browserSubDirectory.Select();
                    using (var newBrowserItem = NewItemDialog.FromDte(app)) {
                        newBrowserItem.FileName = "newBrowserItem.js";
                        newBrowserItem.OK();
                    }

                    Keyboard.Type("document.");
                    System.Threading.Thread.Sleep(2000);
                    Keyboard.Type(Keyboard.CtrlSpace.ToString());

                    using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\browserSubDirectory\newBrowserItem.js")).WaitForSession <ICompletionSession>()) {
                        var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText);
                        Assert.IsTrue(
                            completions.Contains("body"),
                            "New documents of the browser type should open with default VS editor"
                            );
                    }

                    browserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        browserSubDirectory,
                        "Folder label was not updated to " + browserSubDirectoryLabel);

                    var newBrowserItemFile = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel,
                        "newBrowserItem.js"
                        );
                    Assert.AreEqual(
                        "Content",
                        nodejsProject.GetItemType(@"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js"),
                        "Adding a javascript file to a 'browser' directory should set the item type as Content.");

                    var mixedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryLabel
                        );
                    Assert.IsNotNull(
                        mixedDirectory,
                        "Folder with mixed browser/node content should be specified as such. Could not find: " + mixedDirectoryLabel);

                    nodeDirectory.Select();
                    using (var newTypeScriptItem = NewItemDialog.FromDte(app)) {
                        newTypeScriptItem.FileName = "newTypeScriptItem.ts";
                        newTypeScriptItem.OK();
                    }

                    Assert.AreEqual(
                        "TypeScriptCompile",
                        nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"),
                        "Non-javascript files should retain their content type.");

                    var newBrowserItemNode = nodejsProject.FindNodeByFullPath(
                        Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js")
                        );

                    newBrowserItemNode.ExcludeFromProject();
                    var excludedBrowserItem = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        emptyBrowserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        emptyBrowserSubDirectoryLabel,
                        "Label should be removed when there are no included javascript files the directory. Could not find " + emptyBrowserSubDirectoryLabel);

                    (newBrowserItemNode as NodejsFileNode).IncludeInProject(false);
                    var includedBrowserItem = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        browserDirectoryLabel,
                        browserSubDirectoryLabel
                        );
                    Assert.IsNotNull(
                        includedBrowserItem,
                        "Label should be added when a javascript file is included in the directory. Could not find " + browserSubDirectoryLabel);

                    var mixedDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath(
                        Path.Combine(nodejsProject.ProjectHome, @"MixedDirectory\"));

                    System.Threading.Thread.Sleep(2000);
                    mixedDirectory.Select();
                    Keyboard.PressAndRelease(Key.F2);
                    Keyboard.Type("MixedDirectoryRenamed");
                    Keyboard.PressAndRelease(Key.Enter);

                    mixedDirectoryNode.ExpandItem(EXPANDFLAGS.EXPF_ExpandFolderRecursively);
                    var renamedMixedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryBrowserDirectoryLabel,
                        browserCodeLabel
                        );

                    Assert.IsNotNull(
                        renamedMixedDirectory,
                        "Renaming mixed directory failed: could not find " + browserCodeLabel);

                    newBrowserItemNode.ItemNode.ItemTypeName = "Compile";

                    var nodeBrowserSubDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed),
                        NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node)
                        );
                    Assert.IsNotNull(
                        nodeBrowserSubDirectory,
                        "Changing the item type should change the directory label. Could not find " +
                        NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node)
                        );

                    var nodeDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath(
                        Path.Combine(app.GetProject("ClientServerCode").GetNodejsProject().ProjectHome,
                                     @"NodeDirectory\"));
                    (nodeDirectoryNode as NodejsFolderNode).SetItemTypeRecursively(VSLangProj.prjBuildAction.prjBuildActionContent);

                    Assert.AreEqual(
                        "Content",
                        nodejsProject.GetItemType(@"NodeDirectory\NodeSubDirectory\nodeCode.js"),
                        "nodeCode.js file should be marked as content after recursively setting directory contents as Content."
                        );
                    Assert.AreEqual(
                        "TypeScriptCompile",
                        nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"),
                        "Only javascript file item types should change when marking item types recursively."
                        );

                    var fromPoint = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryNodeDirectoryLabel
                        ).GetClickablePoint();

                    var toPoint = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        mixedDirectoryBrowserDirectoryLabel
                        ).GetClickablePoint();

                    Mouse.MoveTo(fromPoint);
                    Mouse.Down(MouseButton.Left);

                    Mouse.MoveTo(toPoint);
                    Mouse.Up(MouseButton.Left);

                    var draggedDirectory = solutionExplorer.WaitForItem(
                        solutionLabel,
                        projectLabel,
                        mixedDirectoryRenamedLabel,
                        NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed),
                        NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node)
                        );
                    Assert.IsNotNull(
                        draggedDirectory,
                        "Labels not properly updated after dragging and dropping directory."
                        );
                }
            }
        }