internal PipEnvironmentView( EnvironmentView view, PipExtensionProvider provider ) { _view = view; _provider = provider; _provider.UpdateStarted += PipExtensionProvider_UpdateStarted; _provider.UpdateComplete += PipExtensionProvider_UpdateComplete; _provider.IsPipInstalledChanged += PipExtensionProvider_IsPipInstalledChanged; _installCommandView = new InstallPackageView(this); _matcher = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreCase); _installed = new ObservableCollection <PipPackageView>(); _installedView = new CollectionViewSource { Source = _installed }; _installedView.Filter += InstalledView_Filter; _installedView.View.CurrentChanged += InstalledView_CurrentChanged; _installable = new List <PackageResultView>(); _installableFiltered = new List <PackageResultView>(); _installableView = new CollectionViewSource { Source = _installableFiltered }; _installableView.View.CurrentChanged += InstallableView_CurrentChanged; _installableViewRefreshTimer = new Timer(InstallablePackages_Refresh); FinishInitialization(); }
public void SortOrder_Regex() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.Regex); TestSortOrder("h.+o", cmp, "hello_world", "helloWorld", "hElLoWoRlD", "hello", "world_hello"); TestSortOrder("h[^_]+w", cmp); TestSortOrder("h[^_]+W", cmp, "helloWorld", "hElLoWoRlD"); TestSortOrder("w.+d", cmp, "world_hello", "hello_world"); }
public void SortOrder_Fuzzy() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.Fuzzy); TestSortOrder("hello", cmp, "hello", "hello_world", "helloWorld", "world_hello"); TestSortOrder("hellow", cmp, "hello_world"); TestSortOrder("helloW", cmp, "helloWorld"); TestSortOrder("world", cmp, "world_hello", "hello_world"); }
public void SortKey_Prefix() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.Prefix); Assert.AreEqual(11, cmp.GetSortKey("hello", "hello")); Assert.AreEqual(10, cmp.GetSortKey("helloWorld", "hello")); Assert.AreEqual(0, cmp.GetSortKey("Hello", "hello")); Assert.AreEqual(0, cmp.GetSortKey("hello", "helloThere")); }
public void SortOrder_FuzzyIgnoreLowerCase() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreLowerCase); TestSortOrder("hello", cmp, "hello", "hello_world", "helloWorld", "HelloWorld", "Hello_World", "hElLoWoRlD", "world_hello"); TestSortOrder("hellow", cmp, "helloWorld", "HelloWorld", "hElLoWoRlD", "hello_world", "Hello_World"); TestSortOrder("helloW", cmp, "helloWorld", "HelloWorld", "hElLoWoRlD", "Hello_World", "hello_world"); TestSortOrder("Hellow", cmp, "HelloWorld", "helloWorld", "hElLoWoRlD", "Hello_World", "hello_world"); TestSortOrder("world", cmp, "world_hello", "hello_world", "Hello_World", "helloWorld", "HelloWorld", "hElLoWoRlD"); }
public LibraryNodeVisitor(PythonToolsService pyService, PythonNavigateToItemProvider itemProvider, INavigateToCallback navCallback, string searchValue) { _pyService = pyService; _itemProvider = itemProvider; _navCallback = navCallback; _searchValue = searchValue; _path.Push(null); _comparer = new FuzzyStringMatcher(_pyService.AdvancedOptions.SearchMode); _regexComparer = new FuzzyStringMatcher(FuzzyMatchMode.RegexIgnoreCase); }
public void SortKey_Substring() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.Substring); Assert.AreEqual(11, cmp.GetSortKey("hello", "hello")); Assert.AreEqual(11, cmp.GetSortKey("helloWorld", "hello")); Assert.AreEqual(0, cmp.GetSortKey("Hello", "hello")); Assert.AreEqual(6, cmp.GetSortKey("hello", "llo")); Assert.AreEqual(4, cmp.GetSortKey("hello", "ll")); Assert.AreEqual(4, cmp.GetSortKey("hello", "lo")); Assert.AreEqual(0, cmp.GetSortKey("hello", "helloThere")); }
public void SortKey_Regex() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.Regex); Assert.AreEqual(11, cmp.GetSortKey("hello", "he..o")); Assert.AreEqual(11, cmp.GetSortKey("helloWorld", "he..o")); Assert.AreEqual(0, cmp.GetSortKey("Hello", "he.+o")); Assert.AreEqual(6, cmp.GetSortKey("hello", "l+o")); Assert.AreEqual(4, cmp.GetSortKey("hello", "l+")); Assert.AreEqual(4, cmp.GetSortKey("hello", "lo(x?)")); Assert.AreEqual(0, cmp.GetSortKey("hello", "h[elo]+There")); }
public void SortKey_Fuzzy() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.Fuzzy); Assert.AreEqual(35, cmp.GetSortKey("hello", "hello")); Assert.AreEqual(35, cmp.GetSortKey("helloWorld", "hello")); Assert.AreEqual(0, cmp.GetSortKey("Hello", "hello")); Assert.AreEqual(6, cmp.GetSortKey("hello", "llo")); Assert.AreEqual(3, cmp.GetSortKey("hello", "ll")); Assert.AreEqual(2, cmp.GetSortKey("hello", "lo")); Assert.AreEqual(0, cmp.GetSortKey("hello", "helloThere")); }
public void SortKey_RegexIgnoreCase() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.RegexIgnoreCase); Assert.AreEqual(11, cmp.GetSortKey("hello", "he..o")); Assert.AreEqual(11, cmp.GetSortKey("helloWorld", "he..o")); Assert.AreEqual(6, cmp.GetSortKey("Hello", "he.+o")); Assert.AreEqual(8, cmp.GetSortKey("HelloWorld", "he.+o")); Assert.AreEqual(6, cmp.GetSortKey("hello", "l+o")); Assert.AreEqual(3, cmp.GetSortKey("hello", "L+O")); Assert.AreEqual(2, cmp.GetSortKey("hello", "L+")); Assert.AreEqual(2, cmp.GetSortKey("hello", "LO(X?)")); Assert.AreEqual(0, cmp.GetSortKey("hello", "h[elo]+There")); }
public void SortKey_FuzzyIgnoreLowerCase() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreLowerCase); Assert.AreEqual(35, cmp.GetSortKey("hello", "hello")); Assert.AreEqual(35, cmp.GetSortKey("helloWorld", "hello")); Assert.AreEqual(34, cmp.GetSortKey("Hello", "hello")); Assert.AreEqual(34, cmp.GetSortKey("HelloWorld", "hello")); Assert.AreEqual(6, cmp.GetSortKey("hello", "llo")); Assert.AreEqual(0, cmp.GetSortKey("hello", "LLO")); Assert.AreEqual(-1, cmp.GetSortKey("hello", "LL")); Assert.AreEqual(-2, cmp.GetSortKey("hello", "LO")); Assert.AreEqual(0, cmp.GetSortKey("hello", "helloThere")); }
public void SortKey_SubstringIgnoreCase() { var cmp = new FuzzyStringMatcher(FuzzyMatchMode.SubstringIgnoreCase); Assert.AreEqual(11, cmp.GetSortKey("hello", "hello")); Assert.AreEqual(11, cmp.GetSortKey("helloWorld", "hello")); Assert.AreEqual(6, cmp.GetSortKey("Hello", "hello")); Assert.AreEqual(6, cmp.GetSortKey("HelloWorld", "hello")); Assert.AreEqual(6, cmp.GetSortKey("hello", "llo")); Assert.AreEqual(3, cmp.GetSortKey("hello", "LLO")); Assert.AreEqual(2, cmp.GetSortKey("hello", "LL")); Assert.AreEqual(2, cmp.GetSortKey("hello", "LO")); Assert.AreEqual(0, cmp.GetSortKey("hello", "helloThere")); }
public LibraryNodeVisitor( PythonNavigateToItemProvider itemProvider, INavigateToCallback navCallback, string searchValue, FuzzyMatchMode matchMode ) { _itemProvider = itemProvider; _navCallback = navCallback; _searchValue = searchValue; _path.Push(null); _comparer = new FuzzyStringMatcher(matchMode); _regexComparer = new FuzzyStringMatcher(FuzzyMatchMode.RegexIgnoreCase); }
public void FuzzyAcronymCompletions() { var cmp1 = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreLowerCase); var cmp2 = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreCase); Assert.AreEqual("MyClassName", GetBestMatch("MCN", cmp1, "MyClassName", "MyOtherClassName")); Assert.AreEqual("MyOtherClassName", GetBestMatch("MOCN", cmp1, "MyClassName", "MyOtherClassName")); // FuzzyIgnoreLowerCase is required to handle the case where a // lowercase character appears before its uppercase, which spoils // the score. Assert.AreEqual("MycClassName", GetBestMatch("MCN", cmp1, "MycClassName", "MyClassName")); Assert.AreEqual("MyClassName", GetBestMatch("MCN", cmp2, "MycClassName", "MyClassName")); }
private string GetBestMatch(string pattern, FuzzyStringMatcher comparer, params string[] options) { string best = null; int bestValue = 0; foreach (global::System.String opt in options) { int value = comparer.GetSortKey(opt, pattern); Console.WriteLine("GetSortKey(\"{0}\", \"{1}\") = {2}", opt, pattern, value); if (value > bestValue) { best = opt; bestValue = value; } } Console.WriteLine(); return best; }
private void TestSortOrderInternal(string pattern, FuzzyStringMatcher comparer, IEnumerable<string> data, string[] expected) { var sorted = data.Where(s => comparer.IsCandidateMatch(s, pattern)) .Select((s, i) => new { S = s, I = i }) .OrderBy(t => t.S, new Comparer(pattern, comparer)) .ThenBy(t => t.I) .Select(t => t.S) .ToList(); Console.WriteLine("Pattern: {0}", pattern); Console.WriteLine("Expected: {0}", string.Join(", ", expected)); Console.WriteLine("Actual: {0}", string.Join(", ", sorted)); Console.WriteLine(); Assert.AreEqual(expected.Length, sorted.Count); foreach (var tup in sorted.Zip(expected, (x, y) => Tuple.Create(x, y))) { Assert.AreEqual(tup.Item2, tup.Item1); } }
/// <summary> /// Initializes a new instance with the specified properties. /// </summary> /// <param name="moniker">The unique, non-localized identifier for the /// completion set.</param> /// <param name="displayName">The localized name of the completion set. /// </param> /// <param name="applicableTo">The tracking span to which the /// completions apply.</param> /// <param name="completions">The list of completions.</param> /// <param name="options">The options to use for filtering and /// selecting items.</param> /// <param name="comparer">The comparer to use to order the provided /// completions.</param> /// <param name="matchInsertionText">If true, matches user input against /// the insertion text; otherwise, uses the display text.</param> public FuzzyCompletionSet( string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable <DynamicallyVisibleCompletion> completions, CompletionOptions options, IComparer <Completion> comparer, bool matchInsertionText = false ) : base(moniker, displayName, applicableTo, null, null) { _matchInsertionText = matchInsertionText; _completions = new BulkObservableCollection <Completion>(); _completions.AddRange(completions .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText)) .OrderBy(c => c, comparer) ); _comparer = new FuzzyStringMatcher(FuzzyMatchMode.Default); _shouldFilter = options.FilterCompletions; _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced); if (!_completions.Any()) { _completions = null; } if (_completions != null && _shouldFilter | _shouldHideAdvanced) { _filteredCompletions = new FilteredObservableCollection <Completion>(_completions); foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>()) { c.Visible = !_shouldHideAdvanced || !IsAdvanced(c); } _filteredCompletions.Filter(IsVisible); } CommitByDefault = DefaultCommitByDefault; }
internal PipEnvironmentView( EnvironmentView view, PipExtensionProvider provider ) { _view = view; _provider = provider; _provider.OperationStarted += PipExtensionProvider_UpdateStarted; _provider.OperationFinished += PipExtensionProvider_UpdateComplete; _provider.IsPipInstalledChanged += PipExtensionProvider_IsPipInstalledChanged; _provider.InstalledPackagesChanged += PipExtensionProvider_InstalledPackagesChanged; IsPipInstalled = _provider.IsPipInstalled ?? true; ShowSecurityWarning = provider._packageManager.UniqueKey == "pip" && view.Configuration.Version != new Version(2, 7) && view.Configuration.Version < new Version(3, 3); _installCommandView = new InstallPackageView(this); _matcher = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreCase); _installed = new ObservableCollection <PipPackageView>(); _installedView = new CollectionViewSource { Source = _installed }; _installedView.Filter += InstalledView_Filter; _installedView.View.CurrentChanged += InstalledView_CurrentChanged; _installable = new List <PackageResultView>(); _installableFiltered = new ObservableCollection <PackageResultView>(); _installableView = new CollectionViewSource { Source = _installableFiltered }; _installableView.View.CurrentChanged += InstallableView_CurrentChanged; _installableViewRefreshTimer = new Timer(InstallablePackages_Refresh); FinishInitialization().DoNotWait(); }
void TestSortOrder(string pattern, FuzzyStringMatcher comparer, IEnumerable <string> data, params string[] expected) { TestSortOrderInternal(pattern, comparer, data, expected); }
public Comparer(string pattern, FuzzyStringMatcher outer) { _cache = new Dictionary <string, int>(); _pattern = pattern; _outer = outer; }
void TestSortOrder(string pattern, FuzzyStringMatcher comparer, params string[] expected) { TestSortOrderInternal(pattern, comparer, Data, expected); }