Esempio n. 1
0
        public async Task FilterCompletions_SearchTextDoesNotContainAtSign_ReturnAllMatchingCompletions()
        {
            var testObj = new LibraryIdViewModel(GetTestSearchService(), "test");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 0);

            Assert.AreEqual(3, result.Completions.Count());
        }
Esempio n. 2
0
        public async Task FilterCompletions_SearchTextEndsWithAfterAt_ReturnFilteredCompletions()
        {
            var testObj = new LibraryIdViewModel(GetTestSearchService(), "test@2");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 0);

            // This will match both 1.2 and 2.0
            Assert.AreEqual(2, result.Completions.Count());
        }
Esempio n. 3
0
        public async Task FilterCompletions_SearchTextEndsWithAt_ReturnAllMatchingCompletions()
        {
            var testObj = new LibraryIdViewModel(GetTestSearchService(), "test@");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 0);

            // the version segment is "", which matches all versions
            Assert.AreEqual(3, result.Completions.Count());
        }
        public async Task FilterCompletions_ScopedPackageWithoutTrailingAt_ReturnAllMatchingCompletions()
        {
            ILibraryCatalog testCatalog = new LibraryCatalog()
                                          .AddLibrary(new Library {
                Name = "test", Version = "1.0"
            })
                                          .AddLibrary(new Library {
                Name = "@types/test", Version = "1.2"
            });

            var testObj = new LibraryIdViewModel(GetTestSearchService(testCatalog), "@types/test");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 11);

            Assert.AreEqual(1, result.Completions.Count());
        }
        public async Task FilterCompletions_SearchTextDoesNotContainAtSign_ReturnAllMatchingCompletions()
        {
            ILibraryCatalog testCatalog = new LibraryCatalog()
                                          .AddLibrary(new Library {
                Name = "test", Version = "1.0"
            })
                                          .AddLibrary(new Library {
                Name = "@types/test", Version = "1.2"
            });

            var testObj = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 3);

            Assert.AreEqual(1, result.Completions.Count());
        }
        public async Task GetRecommendedSelectedCompletionAsync_SearchTextDoesContainAt_NonMatching_ReturnsFirstItem()
        {
            ILibraryCatalog testCatalog = CreateLibraryCatalogWithUnscopedLibrary();

            var testObj = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test@3");

            CompletionItem[] completions = new[] {
                new CompletionItem {
                    DisplayText = "1.2"
                },
                new CompletionItem {
                    DisplayText = "2.1"
                },
            };

            CompletionItem result = await testObj.GetRecommendedSelectedCompletionAsync(completions, null);

            Assert.AreEqual("1.2", result.DisplayText);
        }
        public async Task FilterCompletions_SearchTextEndsWithAt_ReturnAllMatchingCompletions()
        {
            ILibraryCatalog testCatalog = new LibraryCatalog()
                                          .AddLibrary(new Library {
                Name = "test", Version = "1.0"
            })
                                          .AddLibrary(new Library {
                Name = "test", Version = "1.2"
            })
                                          .AddLibrary(new Library {
                Name = "@types/test", Version = "1.2"
            });

            var testObj = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test@");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 5);

            // the version segment is "", which matches all versions
            Assert.AreEqual(2, result.Completions.Count());
        }
Esempio n. 8
0
        public async Task GetRecommendedSelectedCompletionAsync_DoesNotContainAt_ReturnsFirstItem()
        {
            var testObj       = new LibraryIdViewModel(GetTestSearchService(), "test");
            var completionSet = new CompletionSet
            {
                Start       = 0,
                Length      = 4,
                Completions = new[] {
                    new CompletionItem {
                        DisplayText = "[email protected]"
                    },
                    new CompletionItem {
                        DisplayText = "[email protected]"
                    },
                },
            };

            CompletionItem result = await testObj.GetRecommendedSelectedCompletionAsync(completionSet, null);

            Assert.AreEqual("[email protected]", result.DisplayText);
        }
        public async Task FilterCompletions_SearchTextEndsWithAfterAt_ReturnFilteredCompletions()
        {
            ILibraryCatalog testCatalog = new LibraryCatalog()
                                          .AddLibrary(new Library {
                Name = "test", Version = "1.0"
            })
                                          .AddLibrary(new Library {
                Name = "test", Version = "1.2"
            })
                                          .AddLibrary(new Library {
                Name = "test", Version = "2.0"
            })
                                          .AddLibrary(new Library {
                Name = "@types/test", Version = "1.2"
            });

            var testObj = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test@2");

            CompletionSet result = await testObj.GetCompletionSetAsync(caretIndex : 5);

            // This will match both 1.2 and 2.0
            Assert.AreEqual(2, result.Completions.Count());
        }
Esempio n. 10
0
        public async Task GetRecommendedSelectedCompletionAsync_SearchTextDoesContainAt_ReturnsItemThatStartsWithPrefix()
        {
            ILibraryCatalog testCatalog = CreateLibraryCatalogWithUnscopedLibrary();

            var testObj       = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test@2");
            var completionSet = new CompletionSet
            {
                Start       = 0,
                Length      = 4,
                Completions = new[] {
                    new CompletionItem {
                        DisplayText = "1.2"
                    },
                    new CompletionItem {
                        DisplayText = "2.1"
                    },
                },
            };

            CompletionItem result = await testObj.GetRecommendedSelectedCompletionAsync(completionSet, null);

            Assert.AreEqual("2.1", result.DisplayText);
        }
        private async Task ExecuteAsync(object sender, EventArgs e)
        {
            Telemetry.TrackUserTask("Execute-InstallLibraryCommand");

            ProjectItem item = await VsHelpers.GetSelectedItemAsync().ConfigureAwait(false);

            Project project = await VsHelpers.GetProjectOfSelectedItemAsync().ConfigureAwait(false);

            if (project != null)
            {
                string rootFolder = await project.GetRootFolderAsync().ConfigureAwait(false);

                string        configFilePath = Path.Combine(rootFolder, Constants.ConfigFileName);
                IDependencies dependencies   = _dependenciesFactory.FromConfigFile(configFilePath);

                Manifest manifest = await GetManifestAsync(configFilePath, dependencies).ConfigureAwait(false);

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // If the manifest contains errors, we will not invoke the "Add Client-Side libraries" dialog
                // Instead we will display a message box indicating the syntax errors in manifest file.
                if (manifest == null)
                {
                    IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
                    int        result;

                    shell.ShowMessageBox(dwCompRole: 0,
                                         rclsidComp: Guid.Empty,
                                         pszTitle: null,
                                         pszText: PredefinedErrors.ManifestMalformed().Message,
                                         pszHelpFile: null,
                                         dwHelpContextID: 0,
                                         msgbtn: OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                         msgdefbtn: OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                         msgicon: OLEMSGICON.OLEMSGICON_WARNING,
                                         fSysAlert: 0,
                                         pnResult: out result);

                    return;
                }

                string target = string.Empty;

                // Install command was invoked from a folder.
                // So the initial target location should be name of the folder from which
                // the command was invoked.
                if (item != null)
                {
                    target = item.FileNames[1];
                }
                else
                {
                    // Install command was invoked from project scope.
                    // If wwwroot exists, initial target location should be - wwwroot/lib.
                    // Else, target location should be - lib
                    if (Directory.Exists(Path.Combine(rootFolder, "wwwroot")))
                    {
                        target = Path.Combine(rootFolder, "wwwroot", "lib") + Path.DirectorySeparatorChar;
                    }
                    else
                    {
                        target = Path.Combine(rootFolder, "lib") + Path.DirectorySeparatorChar;
                    }
                }

                string initialTargetLocation = CalculateSuggestedInstallPath(target, rootFolder);


                var selectedProviderBinding = new SelectedProviderBinding();
                var libraryIdViewModel      = new LibraryIdViewModel(new ProviderCatalogSearchService(() => selectedProviderBinding.SelectedProvider),
                                                                     string.Empty);

                var libraryNameBinding      = new LibraryNameBinding();
                var targetLocationViewModel = new TargetLocationViewModel(initialTargetLocation,
                                                                          libraryNameBinding,
                                                                          new LocationSearchService(dependencies.GetHostInteractions()));

                var dialogViewModel = new InstallDialogViewModel(
                    _libraryCommandService,
                    configFilePath,
                    dependencies,
                    libraryIdViewModel,
                    targetLocationViewModel,
                    selectedProviderBinding,
                    libraryNameBinding,
                    target,
                    project);

                var dialog = new UI.InstallDialog(dialogViewModel);
                dialog.ShowModal();

                Telemetry.TrackUserTask("Open-InstallDialog");
            }
        }