private static void GoToDefinition(PackageDatabase db, MemberQuery[] searches, int iterations = 1) { PartialArray <Symbol> lastSuccessfulResults = new PartialArray <Symbol>(); PartialArray <Symbol> results = new PartialArray <Symbol>(10); using (new TraceWatch("Go To Definition {0:n0} times across {1:n0} values...", iterations, searches.Length)) { for (int iteration = 0; iteration < iterations; ++iteration) { MemberQuery query = searches[iteration % searches.Length]; query.TryFindMembers(db, ref results); if (results.Count > 0) { results.CopyTo(ref lastSuccessfulResults); } } } if (lastSuccessfulResults.Count > 0) { lastSuccessfulResults[0].WriteLocation(Console.Out); Console.WriteLine(); } else { Console.WriteLine("NOT FOUND."); } Console.WriteLine(); }
internal static string SearchToString(IMemberDatabase db, string memberName) { MemberQuery query = new MemberQuery(memberName, false, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); query.TryFindMembers(db, ref results); return(ResultToString(results)); }
public void Indexer_NestedClass() { MemberQuery q = new MemberQuery("NestedClass", true, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); // Verify the nested class is found and listed under the class Assert.IsTrue(q.TryFindMembers(DB, ref results)); Symbol first = results[0]; Assert.AreEqual(s_indexerTestsNamespace + ".IndexerTests.NestedClass", first.FullName.ToString()); // Verify a field within it is found q.SymbolName = "NestedClass.PublicStringField"; Assert.IsTrue(q.TryFindMembers(DB, ref results)); first = results[0]; Assert.AreEqual(SymbolType.Field, first.Type); Assert.AreEqual(SymbolModifier.Public, first.Modifiers); Assert.AreEqual(s_indexerTestsNamespace + ".IndexerTests.NestedClass.PublicStringField", first.FullName.ToString()); }
public void Indexer_GenericSignature() { MemberQuery q = new MemberQuery("GenericSignature", true, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); Assert.IsTrue(q.TryFindMembers(DB, ref results)); Symbol first = results[0]; Assert.AreEqual("List<Q>", first.Parameters.ToString()); }
public void Indexer_PrivateMethod() { MemberQuery q = new MemberQuery("PrivateMethod", true, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); // Verify private methods are indexed and modifiers are right Assert.IsTrue(q.TryFindMembers(DB, ref results)); Symbol first = results[0]; Assert.AreEqual(SymbolModifier.Private, first.Modifiers); }
public bool Run(TextWriter writer) { bool result = true; string testDataPath = Path.Combine(Environment.CurrentDirectory, @"..\..\TestData\PackageDatabases"); string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); string[] dirs = new string[] { "v4.0", "v4.5.2" }; string[] files = new string[] { "System.Data.dll" }; rootPath = Path.Combine(rootPath, @"Reference Assemblies\Microsoft\Framework\.NETFramework\"); foreach (string dir in dirs) { foreach (string file in files) { HashSet <string> publicNonNested = new HashSet <string>(); HashSet <string> otherTypes = new HashSet <string>(); string assemblyPath = Path.Combine(rootPath, dir, file); Walk(assemblyPath, publicNonNested, otherTypes); PackageDatabase db = Indexer.IndexCommand.Index(assemblyPath, true, true); File.WriteAllText(Path.Combine(testDataPath, file + "." + dir + ".actual.txt"), db.ToString()); db.ConvertToImmutable(); var results = new PartialArray <Symbol>(10); foreach (string typeName in publicNonNested) { var query = new MemberQuery(typeName, false, false); query.TryFindMembers(db, ref results); if (results.Count == 0) { writer.WriteLine("Found " + results.Count + " (instead of 1 or more) matches for " + typeName); result = false; } } foreach (string typeName in otherTypes) { var query = new MemberQuery(typeName, true, true); query.TryFindMembers(db, ref results); if (results.Count == 0) { writer.WriteLine("Found " + results.Count + " (instead of 1 or more) matches for " + typeName); result = false; } } } } return(result); }
internal static Symbol GetTryLogFromSample(PackageDatabase db) { db.ConvertToImmutable(); MemberQuery q = new MemberQuery("TryLog", false, false); PartialArray <Symbol> matches = new PartialArray <Symbol>(5); Assert.IsTrue(q.TryFindMembers(db, ref matches)); Assert.AreEqual(2, matches.Count); return(matches[0]); }
private void GoToDefinition() { Position current = new Position(); current.Save(); current.ClearUpTo(CommandEnd); Console.WriteLine(); LocationWithinFile p = VS.GetCurrentLocation(Options.DatabasePath); if (p == null) { Console.WriteLine("Unable to find current cursor position."); return; } else { Console.WriteLine("Finding Symbol at {0}({1}, {2})", p.FilePath, p.Line, p.CharInLine); } RoslynDefinitionFinder finder = new RoslynDefinitionFinder(p.FilePath, this.References); MemberQuery query = finder.BuildQueryForMemberUsedAt(p.Line, p.CharInLine); query.IgnoreCase = Options.IgnoreCase; if (query == null) { Console.WriteLine("Unable to identify symbol."); return; } Console.Write("Roslyn identified as {0}", query.SymbolName); if (query.Parameters.Length > 0) { Console.Write("({0})", query.Parameters); } Console.WriteLine(); PartialArray <Symbol> results = new PartialArray <Symbol>(1); if (query.TryFindMembers(this.Database, ref results)) { OpenSymbol(results[0]); } else { Console.WriteLine("NOT FOUND"); } CommandEnd.Save(); }
public void AddReferenceDatabase_PackagePrereleaseVersion() { AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current); // Build and add the sample PackageDatabase PackageDatabase source = PackageDatabaseTests.BuildPreleaseSample(); ardb.AddUniqueMembers(source); ardb.ConvertToImmutable(); MemberQuery query = new MemberQuery(PackageDatabaseTests.TYPE_LOGGER, false, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); query.TryFindMembers(ardb, ref results); Assert.AreEqual(1, results.Count); Assert.AreEqual(PackageDatabaseTests.PRERELEASE_VERSION, ardb.GetPackageVersion(results[0].Index).ToString()); }
public Task <ImmutableArray <ReferenceAssemblyWithTypeResult> > FindReferenceAssembliesWithTypeAsync( string name, int arity, CancellationToken cancellationToken) { // Our reference assembly data is stored in the nuget.org DB. if (!_sourceToDatabase.TryGetValue(NugetOrgSource, out var databaseWrapper)) { // Don't have a database to search. return(SpecializedTasks.EmptyImmutableArray <ReferenceAssemblyWithTypeResult>()); } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. return(SpecializedTasks.EmptyImmutableArray <ReferenceAssemblyWithTypeResult>()); } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray <Symbol>(100); var results = ArrayBuilder <ReferenceAssemblyWithTypeResult> .GetInstance(); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); foreach (var type in types) { cancellationToken.ThrowIfCancellationRequested(); // Only look at reference assembly results. if (type.PackageName.ToString() == MicrosoftAssemblyReferencesName) { var nameParts = ArrayBuilder <string> .GetInstance(); GetFullName(nameParts, type.FullName.Parent); var result = new ReferenceAssemblyWithTypeResult( type.AssemblyName.ToString(), type.Name.ToString(), containingNamespaceNames: nameParts.ToImmutableAndFree()); results.Add(result); } } } return(Task.FromResult(results.ToImmutableAndFree())); }
public void AddReferenceDatabase_PackageReleaseVersion() { AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current); // Build and add the sample PackageDatabase PackageDatabase source = PackageDatabaseTests.BuildDefaultSample(); ardb.AddUniqueMembers(source); ardb.ConvertToImmutable(); MemberQuery query = new MemberQuery(PackageDatabaseTests.TYPE_LOGGER, false, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); query.TryFindMembers(ardb, ref results); Assert.AreEqual(1, results.Count); // We shouldn't persist non-prerelease version details in the ARDB Assert.AreEqual(String.Empty, ardb.GetPackageVersion(results[0].Index).ToString()); }
public void Indexer_EndToEnd_Basic() { // Verify this class itself is represented MemberQuery q = new MemberQuery("IndexerTests", true, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); Assert.IsTrue(q.TryFindMembers(DB, ref results)); Symbol first = results[0]; Assert.AreEqual("Elfie.NonCore.Test", first.AssemblyName.ToString(), "Unexpected assembly name:" + first.AssemblyName.ToString()); Assert.AreEqual("IndexerTests", first.Name.ToString()); Assert.AreEqual(s_indexerTestsNamespace + ".IndexerTests", first.FullName.ToString()); Assert.AreEqual(SymbolType.Class, first.Type); Assert.AreEqual(SymbolModifier.Public, first.Modifiers); Assert.AreEqual("IndexerTests.cs", first.FilePath.Name.ToString()); Assert.AreEqual(18, first.CharInLine); }
public IEnumerable <ReferenceAssemblyWithTypeResult> FindReferenceAssembliesWithType( string name, int arity, CancellationToken cancellationToken) { // Our reference assembly data is stored in the nuget.org DB. IAddReferenceDatabaseWrapper databaseWrapper; if (!_sourceToDatabase.TryGetValue(NugetOrgSource, out databaseWrapper)) { // Don't have a database to search. yield break; } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. yield break; } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray <Symbol>(100); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); foreach (var type in types) { // Only look at reference assembly results. if (type.PackageName.ToString() == MicrosoftAssemblyReferencesName) { var nameParts = new List <string>(); GetFullName(nameParts, type.FullName.Parent); yield return(new ReferenceAssemblyWithTypeResult( type.AssemblyName.ToString(), type.Name.ToString(), containingNamespaceNames: nameParts)); } } } }
public Task <ImmutableArray <PackageWithTypeResult> > FindPackagesWithTypeAsync( string source, string name, int arity, CancellationToken cancellationToken) { if (!_sourceToDatabase.TryGetValue(source, out var databaseWrapper)) { // Don't have a database to search. return(SpecializedTasks.EmptyImmutableArray <PackageWithTypeResult>()); } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. return(SpecializedTasks.EmptyImmutableArray <PackageWithTypeResult>()); } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray <Symbol>(100); var result = ArrayBuilder <PackageWithTypeResult> .GetInstance(); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); foreach (var type in types) { cancellationToken.ThrowIfCancellationRequested(); // Ignore any reference assembly results. if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { result.Add(CreateResult(database, type)); } } } return(Task.FromResult(result.ToImmutableAndFree())); }
public static PartialArray <Symbol> SearchPerformance(IMemberDatabase db, MemberQuery[] searches, int iterations = 1) { PartialArray <Symbol> lastSuccessfulResults = new PartialArray <Symbol>(); PartialArray <Symbol> results = new PartialArray <Symbol>(20); using (new TraceWatch("Searching {0:n0} times across {1:n0} values...", iterations, searches.Length)) { for (int iteration = 0; iteration < iterations; ++iteration) { MemberQuery query = searches[iteration % searches.Length]; query.TryFindMembers(db, ref results); if (results.Count > 0) { results.CopyTo(ref lastSuccessfulResults); } } } if (lastSuccessfulResults.Count > 0) { for (int i = 0; i < Math.Min(lastSuccessfulResults.Count, 5); ++i) { Symbol result = lastSuccessfulResults[i]; int lengthWritten = 0; lengthWritten += result.FullName.WriteTo(Console.Out); Console.Write(new string(' ', Math.Max(1, 60 - lengthWritten))); result.PackageName.WriteTo(Console.Out); Console.WriteLine(); } } else { Console.WriteLine("NOT FOUND."); } Console.WriteLine(); return(results); }
internal static string GetLocation(IMemberDatabase db, MemberQuery query) { PartialArray <Symbol> results = new PartialArray <Symbol>(10); query.TryFindMembers(db, ref results); StringBuilder resultText = new StringBuilder(); using (StringWriter writer = new StringWriter(resultText)) { for (int i = 0; i < results.Count; ++i) { if (i > 0) { writer.WriteLine(); } results[i].WriteLocation(writer); } } return(resultText.ToString()); }
private void VerifyQueryResults(AddReferenceDatabase ardb, ArdbVersion version) { // "Diagnostics." MemberQuery query = new MemberQuery(PackageDatabaseTests.NS_DIAGNOSTICS + ".", false, false); PartialArray <Symbol> results = new PartialArray <Symbol>(10); query.TryFindMembers(ardb, ref results); Assert.AreEqual(3, results.Count); Assert.AreEqual("Logger, Memory, TraceWatch", PackageDatabaseTests.ResultNamesToString(results)); if (version == ArdbVersion.V1) { // V1 has no TFM data. This call also verifies that most current client // can query older format without raising an exception. Assert.AreEqual(String8.Empty, ardb.GetFrameworkTargets(results[0].Index)); return; } for (int i = 0; i < results.Count; i++) { Symbol symbol = results[i]; string fx = ardb.GetFrameworkTargets(symbol.Index).ToString(); if (symbol.Name.ToString() == "TraceWatch") { Assert.AreEqual(PackageDatabaseTests.NET20, fx); } else if (symbol.Name.ToString() == "Memory") { Assert.AreEqual(PackageDatabaseTests.NET35, fx); } else { Assert.AreEqual(@"<tfms><tfm>net20</tfm><tfm>net35</tfm></tfms>", fx); } } }
public void PackageDatabase_SearchCaseSensitivity() { int expectedCount = 2; // PackageDatabase db = BuildDefaultSample(); db.ConvertToImmutable(); string tree = db.ToString(); Console.WriteLine(tree); PartialArray <Symbol> results = new PartialArray <Symbol>(10); MemberQuery query = new MemberQuery("TryLog", true, false); // Test expects case sensitive to be false by default Assert.IsTrue(query.IgnoreCase); query.IgnoreCase = true; // Exact casing matches [default] query.TryFindMembers(db, ref results); Assert.AreEqual(expectedCount, results.Count); // Different casing matches [default] query.SymbolName = "trylog"; query.TryFindMembers(db, ref results); Assert.AreEqual(expectedCount, results.Count); // Different containing type casing matches [default] query.SymbolName = "logger.TryLog"; query.TryFindMembers(db, ref results); Assert.AreEqual(expectedCount, results.Count); // Different namespace casing matches [default] query.SymbolName = "DIagnostics.Logger.TryLog"; query.TryFindMembers(db, ref results); Assert.AreEqual(expectedCount, results.Count); // Different params casing matches [default] query.Parameters = "String, string"; query.TryFindMembers(db, ref results); Assert.AreEqual(expectedCount, results.Count); query.Parameters = ""; // Different partially typed suffix casing matches [default] query.IsFullSuffix = false; query.SymbolName = "Logger.log"; query.TryFindMembers(db, ref results); Assert.AreEqual(6, results.Count); query.IsFullSuffix = true; query.IgnoreCase = false; // Exact casing matches [case sensitive] query.SymbolName = "TryLog"; query.TryFindMembers(db, ref results); Assert.AreEqual(expectedCount, results.Count); // Different casing doesn't match [case sensitive] query.SymbolName = "trylog"; query.TryFindMembers(db, ref results); Assert.AreEqual(0, results.Count); // Ancestor casing causes non-match [case sensitive] query.SymbolName = "logger.TryLog"; query.TryFindMembers(db, ref results); Assert.AreEqual(0, results.Count); // Ancestor casing causes non-match [case sensitive] query.SymbolName = "DIagnostics.Logger.TryLog"; query.TryFindMembers(db, ref results); Assert.AreEqual(0, results.Count); // Parameters casing causes non-match [case sensitive] query.SymbolName = "TryLog"; query.Parameters = "String, string"; query.TryFindMembers(db, ref results); Assert.AreEqual(0, results.Count); query.Parameters = ""; // Different partially typed suffix causes non-match [case sensitive] query.IsFullSuffix = false; query.SymbolName = "Logger.log"; query.TryFindMembers(db, ref results); Assert.AreEqual(0, results.Count); query.IsFullSuffix = true; }
public Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync( string source, string name, int arity) { if (!_sourceToDatabase.TryGetValue(source, out var databaseWrapper)) { // Don't have a database to search. return SpecializedTasks.EmptyImmutableArray<PackageWithTypeResult>(); } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. return SpecializedTasks.EmptyImmutableArray<PackageWithTypeResult>(); } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray<Symbol>(100); var result = ArrayBuilder<PackageWithTypeResult>.GetInstance(); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); foreach (var type in types) { // Ignore any reference assembly results. if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { result.Add(CreateResult(database, type)); } } } return Task.FromResult(result.ToImmutableAndFree()); }
public Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync( string name, int arity) { // Our reference assembly data is stored in the nuget.org DB. if (!_sourceToDatabase.TryGetValue(NugetOrgSource, out var databaseWrapper)) { // Don't have a database to search. return SpecializedTasks.EmptyImmutableArray<ReferenceAssemblyWithTypeResult>(); } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. return SpecializedTasks.EmptyImmutableArray<ReferenceAssemblyWithTypeResult>(); } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray<Symbol>(100); var results = ArrayBuilder<ReferenceAssemblyWithTypeResult>.GetInstance(); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); foreach (var type in types) { // Only look at reference assembly results. if (type.PackageName.ToString() == MicrosoftAssemblyReferencesName) { var nameParts = new List<string>(); GetFullName(nameParts, type.FullName.Parent); var result = new ReferenceAssemblyWithTypeResult( type.AssemblyName.ToString(), type.Name.ToString(), containingNamespaceNames: nameParts); results.Add(result); } } } return Task.FromResult(results.ToImmutableAndFree()); }
public IEnumerable <PackageWithTypeResult> FindPackagesWithType( string source, string name, int arity, CancellationToken cancellationToken) { //if (!StringComparer.OrdinalIgnoreCase.Equals(source, NugetOrgSource)) //{ // // We only support searching nuget.org // yield break; //} AddReferenceDatabase database; if (!_sourceToDatabase.TryGetValue(source, out database)) { // Don't have a database to search. yield break; } if (name == "var") { // never find anything named 'var'. yield break; } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray <Symbol>(100); if (query.TryFindMembers(database, ref symbols)) { // Don't return nested types. Currently their value does not seem worth // it given all the extra stuff we'd have to plumb through. Namely // going down the "using static" code path and whatnot. var types = new List <Symbol>( from symbol in symbols where this.IsType(symbol) && !this.IsType(symbol.Parent()) select symbol); var typesFromPackagesUsedInOtherProjects = new List <Symbol>(); var typesFromPackagesNotUsedInOtherProjects = new List <Symbol>(); foreach (var type in types) { var packageName = type.PackageName.ToString(); if (_installerService.GetInstalledVersions(packageName).Any()) { typesFromPackagesUsedInOtherProjects.Add(type); } else { typesFromPackagesNotUsedInOtherProjects.Add(type); } } var result = new List <Symbol>(); // We always returm types from packages that we've use elsewhere in the project. int?bestRank = null; foreach (var type in typesFromPackagesUsedInOtherProjects) { if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { var rank = GetRank(type); bestRank = bestRank == null ? rank : Math.Max(bestRank.Value, rank); } yield return(CreateResult(database, type)); } // For all other hits include as long as the popularity is high enough. // Popularity ranks are in powers of two. So if two packages differ by // one rank, then one is at least twice as popular as the next. Two // ranks would be four times as popular. Three ranks = 8 times, etc. // etc. We keep packages that within 1 rank of the best package we find. // // Note: we only do rankings for nuget packages. Results from reference // assemblies are always returned. foreach (var type in typesFromPackagesNotUsedInOtherProjects) { if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { var rank = GetRank(type); bestRank = bestRank == null ? rank : Math.Max(bestRank.Value, rank); if (Math.Abs(bestRank.Value - rank) > 1) { yield break; } } yield return(CreateResult(database, type)); } } }
public IEnumerable <PackageWithTypeResult> FindPackagesWithType( string source, string name, int arity, CancellationToken cancellationToken) { AddReferenceDatabase database; if (!_sourceToDatabase.TryGetValue(source, out database)) { // Don't have a database to search. yield break; } if (name == "var") { // never find anything named 'var'. yield break; } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray <Symbol>(100); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); var typesFromPackagesUsedInOtherProjects = new List <Symbol>(); var typesFromPackagesNotUsedInOtherProjects = new List <Symbol>(); foreach (var type in types) { // Ignore any reference assembly results. if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { var packageName = type.PackageName.ToString(); if (_installerService.GetInstalledVersions(packageName).Any()) { typesFromPackagesUsedInOtherProjects.Add(type); } else { typesFromPackagesNotUsedInOtherProjects.Add(type); } } } var result = new List <Symbol>(); // We always returm types from packages that we've use elsewhere in the project. int?bestRank = null; foreach (var type in typesFromPackagesUsedInOtherProjects) { yield return(CreateResult(database, type)); } // For all other hits include as long as the popularity is high enough. // Popularity ranks are in powers of two. So if two packages differ by // one rank, then one is at least twice as popular as the next. Two // ranks would be four times as popular. Three ranks = 8 times, etc. // etc. We keep packages that within 1 rank of the best package we find. foreach (var type in typesFromPackagesNotUsedInOtherProjects) { var rank = GetRank(type); bestRank = bestRank == null ? rank : Math.Max(bestRank.Value, rank); if (Math.Abs(bestRank.Value - rank) > 1) { yield break; } yield return(CreateResult(database, type)); } } }
public IEnumerable<PackageWithTypeResult> FindPackagesWithType( string source, string name, int arity, CancellationToken cancellationToken) { IAddReferenceDatabaseWrapper databaseWrapper; if (!_sourceToDatabase.TryGetValue(source, out databaseWrapper)) { // Don't have a database to search. yield break; } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. yield break; } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray<Symbol>(100); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); var typesFromPackagesUsedInOtherProjects = new List<Symbol>(); var typesFromPackagesNotUsedInOtherProjects = new List<Symbol>(); foreach (var type in types) { // Ignore any reference assembly results. if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { var packageName = type.PackageName.ToString(); if (_installerService.GetInstalledVersions(packageName).Any()) { typesFromPackagesUsedInOtherProjects.Add(type); } else { typesFromPackagesNotUsedInOtherProjects.Add(type); } } } var result = new List<Symbol>(); // We always returm types from packages that we've use elsewhere in the project. int? bestRank = null; foreach (var type in typesFromPackagesUsedInOtherProjects) { yield return CreateResult(database, type); } // For all other hits include as long as the popularity is high enough. // Popularity ranks are in powers of two. So if two packages differ by // one rank, then one is at least twice as popular as the next. Two // ranks would be four times as popular. Three ranks = 8 times, etc. // etc. We keep packages that within 1 rank of the best package we find. foreach (var type in typesFromPackagesNotUsedInOtherProjects) { var rank = GetRank(type); bestRank = bestRank == null ? rank : Math.Max(bestRank.Value, rank); if (Math.Abs(bestRank.Value - rank) > 1) { yield break; } yield return CreateResult(database, type); } } }
public IEnumerable<PackageWithTypeResult> FindPackagesWithType( string source, string name, int arity, CancellationToken cancellationToken) { //if (!StringComparer.OrdinalIgnoreCase.Equals(source, NugetOrgSource)) //{ // // We only support searching nuget.org // yield break; //} AddReferenceDatabase database; if (!_sourceToDatabase.TryGetValue(source, out database)) { // Don't have a database to search. yield break; } if (name == "var") { // never find anything named 'var'. yield break; } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray<Symbol>(100); if (query.TryFindMembers(database, ref symbols)) { // Don't return nested types. Currently their value does not seem worth // it given all the extra stuff we'd have to plumb through. Namely // going down the "using static" code path and whatnot. var types = new List<Symbol>( from symbol in symbols where this.IsType(symbol) && !this.IsType(symbol.Parent()) select symbol); var typesFromPackagesUsedInOtherProjects = new List<Symbol>(); var typesFromPackagesNotUsedInOtherProjects = new List<Symbol>(); foreach (var type in types) { var packageName = type.PackageName.ToString(); if (_installerService.GetInstalledVersions(packageName).Any()) { typesFromPackagesUsedInOtherProjects.Add(type); } else { typesFromPackagesNotUsedInOtherProjects.Add(type); } } var result = new List<Symbol>(); // We always returm types from packages that we've use elsewhere in the project. int? bestRank = null; foreach (var type in typesFromPackagesUsedInOtherProjects) { if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { var rank = GetRank(type); bestRank = bestRank == null ? rank : Math.Max(bestRank.Value, rank); } yield return CreateResult(database, type); } // For all other hits include as long as the popularity is high enough. // Popularity ranks are in powers of two. So if two packages differ by // one rank, then one is at least twice as popular as the next. Two // ranks would be four times as popular. Three ranks = 8 times, etc. // etc. We keep packages that within 1 rank of the best package we find. // // Note: we only do rankings for nuget packages. Results from reference // assemblies are always returned. foreach (var type in typesFromPackagesNotUsedInOtherProjects) { if (type.PackageName.ToString() != MicrosoftAssemblyReferencesName) { var rank = GetRank(type); bestRank = bestRank == null ? rank : Math.Max(bestRank.Value, rank); if (Math.Abs(bestRank.Value - rank) > 1) { yield break; } } yield return CreateResult(database, type); } } }
public IEnumerable<ReferenceAssemblyWithTypeResult> FindReferenceAssembliesWithType( string name, int arity, CancellationToken cancellationToken) { // Our reference assembly data is stored in the nuget.org DB. IAddReferenceDatabaseWrapper databaseWrapper; if (!_sourceToDatabase.TryGetValue(NugetOrgSource, out databaseWrapper)) { // Don't have a database to search. yield break; } var database = databaseWrapper.Database; if (name == "var") { // never find anything named 'var'. yield break; } var query = new MemberQuery(name, isFullSuffix: true, isFullNamespace: false); var symbols = new PartialArray<Symbol>(100); if (query.TryFindMembers(database, ref symbols)) { var types = FilterToViableTypes(symbols); foreach (var type in types) { // Only look at reference assembly results. if (type.PackageName.ToString() == MicrosoftAssemblyReferencesName) { var nameParts = new List<string>(); GetFullName(nameParts, type.FullName.Parent); yield return new ReferenceAssemblyWithTypeResult( type.AssemblyName.ToString(), type.Name.ToString(), containingNamespaceNames: nameParts); } } } }