From 25c21be54168ca54007979bf5391c10f693ecdd5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:05:03 -0700 Subject: [PATCH 01/35] NRT enable code --- .../SymbolFinder.FindReferencesServerCallback.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs index 181b7893b4cff..1feb74ace7c1d 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs @@ -2,14 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Roslyn.Utilities; @@ -52,13 +51,13 @@ public ValueTask OnCompletedAsync(CancellationToken cancellationToken) public ValueTask OnFindInDocumentStartedAsync(DocumentId documentId, CancellationToken cancellationToken) { - var document = _solution.GetDocument(documentId); + var document = _solution.GetRequiredDocument(documentId); return _progress.OnFindInDocumentStartedAsync(document, cancellationToken); } public ValueTask OnFindInDocumentCompletedAsync(DocumentId documentId, CancellationToken cancellationToken) { - var document = _solution.GetDocument(documentId); + var document = _solution.GetRequiredDocument(documentId); return _progress.OnFindInDocumentCompletedAsync(document, cancellationToken); } @@ -94,8 +93,8 @@ public async ValueTask OnReferenceFoundAsync( SerializableReferenceLocation reference, CancellationToken cancellationToken) { - SymbolGroup symbolGroup; - ISymbol symbol; + SymbolGroup? symbolGroup; + ISymbol? symbol; lock (_gate) { // The definition may not be in the map if we failed to map it over using TryRehydrateAsync in OnDefinitionFoundAsync. From 78aeb05d315bb2a04d51d082f21bc85565754b99 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:06:55 -0700 Subject: [PATCH 02/35] NRT enable code --- .../Portable/FindSymbols/SymbolFinder_FindLiteralReferences.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindLiteralReferences.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindLiteralReferences.cs index 23e1b777576a2..5c13a6846c07f 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindLiteralReferences.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindLiteralReferences.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Threading; using System.Threading.Tasks; From 5cd69649e347b17cfb64a8f429f1b017ba8ea327 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:08:42 -0700 Subject: [PATCH 03/35] NRT enable code --- .../FindSymbols/SymbolFinder_Declarations_SourceDeclarations.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_SourceDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_SourceDeclarations.cs index 4df175ae40acd..9b923bb6f38ef 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_SourceDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_SourceDeclarations.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; From 75e94f8b6ecd748b95f83dae1dffb489a7b75381 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:13:41 -0700 Subject: [PATCH 04/35] NRT enable code --- .../SymbolFinder_Declarations_CustomQueries.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs index 03b165da6bf35..3b1e4f55933be 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_CustomQueries.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -11,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis.FindSymbols { @@ -56,15 +55,15 @@ internal static async Task> FindSourceDeclarationsWithCu using (Logger.LogBlock(FunctionId.SymbolFinder_Solution_Predicate_FindSourceDeclarationsAsync, cancellationToken)) { - var result = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var result); foreach (var projectId in solution.ProjectIds) { - var project = solution.GetProject(projectId); + var project = solution.GetRequiredProject(projectId); var symbols = await FindSourceDeclarationsWithCustomQueryAsync(project, query, filter, cancellationToken).ConfigureAwait(false); result.AddRange(symbols); } - return result.ToImmutableAndFree(); + return result.ToImmutable(); } } @@ -103,7 +102,7 @@ internal static async Task> FindSourceDeclarationsWithCu { if (await project.ContainsSymbolsWithNameAsync(query.GetPredicate(), filter, cancellationToken).ConfigureAwait(false)) { - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var unfiltered = compilation.GetSymbolsWithName(query.GetPredicate(), filter, cancellationToken) .ToImmutableArray(); From 8d8b172e06569523dc9795d1301acf60fbae76ea Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:15:31 -0700 Subject: [PATCH 05/35] NRT enable code --- .../FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs index 2270320cbf1a3..abafabd2fae30 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; From 9462d2bffce2b4798c641e74e802bc680715bdc7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:23:02 -0700 Subject: [PATCH 06/35] NRT enable code --- .../Portable/FindSymbols/ReferenceLocation.cs | 27 ++++++----- .../Core/Portable/Remote/RemoteArguments.cs | 47 +++++++++++-------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocation.cs b/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocation.cs index 9c495e9b9b007..1c74c357da6c9 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocation.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocation.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -26,7 +24,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols /// /// If the symbol was bound through an alias, then this is the alias that was used. /// - public IAliasSymbol Alias { get; } + public IAliasSymbol? Alias { get; } /// /// The actual source location for a given symbol. @@ -65,8 +63,15 @@ namespace Microsoft.CodeAnalysis.FindSymbols public CandidateReason CandidateReason { get; } - private ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary additionalProperties, CandidateReason candidateReason, Location containingStringLocation) - : this() + private ReferenceLocation( + Document document, + IAliasSymbol? alias, + Location location, + bool isImplicit, + SymbolUsageInfo symbolUsageInfo, + ImmutableDictionary additionalProperties, + CandidateReason candidateReason, + Location containingStringLocation) { this.Document = document; this.Alias = alias; @@ -81,7 +86,7 @@ private ReferenceLocation(Document document, IAliasSymbol alias, Location locati /// /// Creates a reference location with the given properties. /// - internal ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary additionalProperties, CandidateReason candidateReason) + internal ReferenceLocation(Document document, IAliasSymbol? alias, Location location, bool isImplicit, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary additionalProperties, CandidateReason candidateReason) : this(document, alias, location, isImplicit, symbolUsageInfo, additionalProperties, candidateReason, containingStringLocation: Location.None) { } @@ -111,10 +116,10 @@ internal ReferenceLocation(Document document, Location location, Location contai public static bool operator !=(ReferenceLocation left, ReferenceLocation right) => !(left == right); - public override bool Equals(object obj) + public override bool Equals(object? obj) { - return obj is ReferenceLocation && - Equals((ReferenceLocation)obj); + return obj is ReferenceLocation location && + Equals(location); } public bool Equals(ReferenceLocation other) @@ -140,8 +145,8 @@ public int CompareTo(ReferenceLocation other) { int compare; - var thisPath = this.Location.SourceTree.FilePath; - var otherPath = other.Location.SourceTree.FilePath; + var thisPath = this.Location.SourceTree?.FilePath; + var otherPath = other.Location.SourceTree?.FilePath; if ((compare = StringComparer.OrdinalIgnoreCase.Compare(thisPath, otherPath)) != 0 || (compare = this.Location.SourceSpan.CompareTo(other.Location.SourceSpan)) != 0) diff --git a/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs b/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs index 2e12f9f7fac59..1c84ad67c5d5f 100644 --- a/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs +++ b/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs @@ -2,17 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.FindSymbols; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -35,11 +35,14 @@ public SerializableSymbolAndProjectId(string symbolKeyData, ProjectId projectId) ProjectId = projectId; } - public override bool Equals(object obj) + public override bool Equals(object? obj) => Equals(obj as SerializableSymbolAndProjectId); - public bool Equals(SerializableSymbolAndProjectId other) + public bool Equals(SerializableSymbolAndProjectId? other) { + if (other == null) + return false; + if (this == other) return true; @@ -50,8 +53,9 @@ public bool Equals(SerializableSymbolAndProjectId other) public override int GetHashCode() => Hash.Combine(this.SymbolKeyData, this.ProjectId.GetHashCode()); - public static SerializableSymbolAndProjectId Dehydrate( - IAliasSymbol alias, Document document, CancellationToken cancellationToken) + [return: NotNullIfNotNull("alias")] + public static SerializableSymbolAndProjectId? Dehydrate( + IAliasSymbol? alias, Document document, CancellationToken cancellationToken) { return alias == null ? null @@ -72,7 +76,7 @@ public static SerializableSymbolAndProjectId Create(ISymbol symbol, Project proj public static bool TryCreate( ISymbol symbol, Solution solution, CancellationToken cancellationToken, - out SerializableSymbolAndProjectId result) + [NotNullWhen(true)] out SerializableSymbolAndProjectId? result) { var project = solution.GetOriginatingProject(symbol); if (project == null) @@ -86,7 +90,7 @@ public static bool TryCreate( public static bool TryCreate( ISymbol symbol, Project project, CancellationToken cancellationToken, - out SerializableSymbolAndProjectId result) + [NotNullWhen(true)] out SerializableSymbolAndProjectId? result) { if (!SymbolKey.CanCreate(symbol, cancellationToken)) { @@ -98,12 +102,12 @@ public static bool TryCreate( return true; } - public async Task TryRehydrateAsync( + public async Task TryRehydrateAsync( Solution solution, CancellationToken cancellationToken) { var projectId = ProjectId; - var project = solution.GetProject(projectId); - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var project = solution.GetRequiredProject(projectId); + var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); // The server and client should both be talking about the same compilation. As such // locations in symbols are save to resolve as we rehydrate the SymbolKey. @@ -134,7 +138,7 @@ internal readonly struct SerializableReferenceLocation public readonly DocumentId Document; [DataMember(Order = 1)] - public readonly SerializableSymbolAndProjectId Alias; + public readonly SerializableSymbolAndProjectId? Alias; [DataMember(Order = 2)] public readonly TextSpan Location; @@ -153,7 +157,7 @@ internal readonly struct SerializableReferenceLocation public SerializableReferenceLocation( DocumentId document, - SerializableSymbolAndProjectId alias, + SerializableSymbolAndProjectId? alias, TextSpan location, bool isImplicit, SymbolUsageInfo symbolUsageInfo, @@ -185,8 +189,8 @@ public static SerializableReferenceLocation Dehydrate( public async Task RehydrateAsync( Solution solution, CancellationToken cancellationToken) { - var document = await solution.GetDocumentAsync(this.Document, includeSourceGenerated: true, cancellationToken).ConfigureAwait(false); - var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); + var document = await solution.GetRequiredDocumentAsync(this.Document, includeSourceGenerated: true, cancellationToken).ConfigureAwait(false); + var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var aliasSymbol = await RehydrateAliasAsync(solution, cancellationToken).ConfigureAwait(false); var additionalProperties = this.AdditionalProperties; return new ReferenceLocation( @@ -199,7 +203,7 @@ public async Task RehydrateAsync( candidateReason: CandidateReason); } - private async Task RehydrateAliasAsync( + private async Task RehydrateAliasAsync( Solution solution, CancellationToken cancellationToken) { if (Alias == null) @@ -223,15 +227,18 @@ public SerializableSymbolGroup(HashSet symbols) Symbols = new HashSet(symbols); } - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is SerializableSymbolGroup group && Equals(group); - public bool Equals(SerializableSymbolGroup other) + public bool Equals(SerializableSymbolGroup? other) { + if (other == null) + return false; + if (this == other) return true; - return other != null && this.Symbols.SetEquals(other.Symbols); + return this.Symbols.SetEquals(other.Symbols); } public override int GetHashCode() @@ -241,7 +248,7 @@ public override int GetHashCode() var hashCode = 0; foreach (var symbol in Symbols) hashCode += symbol.SymbolKeyData.GetHashCode(); - _hashCode = hashCode; + _hashCode = hashCode == 0 ? 1 : hashCode; } return _hashCode; From 98d01d7b6ef9517f9ede056cc7dd94e9892171ed Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:36:50 -0700 Subject: [PATCH 07/35] NRT enable code --- .../FindSymbols/SymbolFinder_Helpers.cs | 2 +- .../FindSymbols/SymbolFinder_Hierarchy.cs | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Helpers.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Helpers.cs index e8d91427d3569..f6601c1280ca5 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Helpers.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Helpers.cs @@ -32,7 +32,7 @@ Accessibility.Protected or internal static async Task OriginalSymbolsMatchAsync( Solution solution, - ISymbol searchSymbol, + ISymbol? searchSymbol, ISymbol? symbolToMatch, CancellationToken cancellationToken) { diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs index 8db349f2014aa..f1bc8827bf03d 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Hierarchy.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -25,7 +23,7 @@ public static partial class SymbolFinder /// Find symbols for members that override the specified member symbol. /// public static async Task> FindOverridesAsync( - ISymbol symbol, Solution solution, IImmutableSet projects = null, CancellationToken cancellationToken = default) + ISymbol symbol, Solution solution, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { return await FindOverridesArrayAsync(symbol, solution, projects, cancellationToken).ConfigureAwait(false); } @@ -35,11 +33,11 @@ public static async Task> FindOverridesAsync( /// Use this overload to avoid boxing the result into an . /// internal static async Task> FindOverridesArrayAsync( - ISymbol symbol, Solution solution, IImmutableSet projects = null, CancellationToken cancellationToken = default) + ISymbol symbol, Solution solution, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { var results = ArrayBuilder.GetInstance(); - symbol = symbol?.OriginalDefinition; + symbol = symbol.OriginalDefinition; if (symbol.IsOverridable()) { // To find the overrides, we need to walk down the type hierarchy and check all @@ -81,7 +79,7 @@ internal static async Task IsOverrideAsync(Solution solution, ISymbol memb /// Find symbols for declarations that implement members of the specified interface symbol /// public static async Task> FindImplementedInterfaceMembersAsync( - ISymbol symbol, Solution solution, IImmutableSet projects = null, CancellationToken cancellationToken = default) + ISymbol symbol, Solution solution, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { return await FindImplementedInterfaceMembersArrayAsync(symbol, solution, projects, cancellationToken).ConfigureAwait(false); } @@ -97,7 +95,7 @@ internal static Task> FindImplementedInterfaceMembersArr /// Use this overload to avoid boxing the result into an . /// internal static async Task> FindImplementedInterfaceMembersArrayAsync( - ISymbol symbol, Solution solution, IImmutableSet projects, CancellationToken cancellationToken) + ISymbol symbol, Solution solution, IImmutableSet? projects, CancellationToken cancellationToken) { // Member can only implement interface members if it is an explicit member, or if it is // public @@ -139,8 +137,12 @@ internal static async Task> FindImplementedInterfaceMemb // make sure that the interface even contains a symbol with the same // name as the symbol we're looking for. var nameToLookFor = symbol.IsPropertyAccessor() - ? ((IMethodSymbol)symbol).AssociatedSymbol.Name + ? ((IMethodSymbol)symbol).AssociatedSymbol?.Name : symbol.Name; + + if (nameToLookFor == null) + continue; + if (interfaceType.MemberNames.Contains(nameToLookFor)) { foreach (var m in interfaceType.GetMembers(symbol.Name)) @@ -183,7 +185,7 @@ internal static async Task> FindImplementedInterfaceMemb /// The derived types of the symbol. The symbol passed in is not included in this list. [EditorBrowsable(EditorBrowsableState.Never)] public static Task> FindDerivedClassesAsync( - INamedTypeSymbol type, Solution solution, IImmutableSet projects, CancellationToken cancellationToken) + INamedTypeSymbol type, Solution solution, IImmutableSet? projects, CancellationToken cancellationToken) { return FindDerivedClassesAsync(type, solution, transitive: true, projects, cancellationToken); } @@ -201,7 +203,7 @@ public static Task> FindDerivedClassesAsync( /// The derived types of the symbol. The symbol passed in is not included in this list. #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static async Task> FindDerivedClassesAsync( - INamedTypeSymbol type, Solution solution, bool transitive = true, IImmutableSet projects = null, CancellationToken cancellationToken = default) + INamedTypeSymbol type, Solution solution, bool transitive = true, IImmutableSet? projects = null, CancellationToken cancellationToken = default) #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { if (type == null) @@ -216,7 +218,7 @@ public static async Task> FindDerivedClassesAsync( /// /// Use this overload to avoid boxing the result into an . internal static async Task> FindDerivedClassesArrayAsync( - INamedTypeSymbol type, Solution solution, bool transitive, IImmutableSet projects = null, CancellationToken cancellationToken = default) + INamedTypeSymbol type, Solution solution, bool transitive, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { var types = await DependentTypeFinder.FindTypesAsync( type, solution, projects, transitive, DependentTypesKind.DerivedClasses, cancellationToken).ConfigureAwait(false); @@ -237,7 +239,7 @@ internal static async Task> FindDerivedClassesA /// The derived interfaces of the symbol. The symbol passed in is not included in this list. #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static async Task> FindDerivedInterfacesAsync( - INamedTypeSymbol type, Solution solution, bool transitive = true, IImmutableSet projects = null, CancellationToken cancellationToken = default) + INamedTypeSymbol type, Solution solution, bool transitive = true, IImmutableSet? projects = null, CancellationToken cancellationToken = default) #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { if (type == null) @@ -252,7 +254,7 @@ public static async Task> FindDerivedInterfacesAsy /// /// Use this overload to avoid boxing the result into an . internal static async Task> FindDerivedInterfacesArrayAsync( - INamedTypeSymbol type, Solution solution, bool transitive, IImmutableSet projects = null, CancellationToken cancellationToken = default) + INamedTypeSymbol type, Solution solution, bool transitive, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { var types = await DependentTypeFinder.FindTypesAsync( type, solution, projects, transitive, DependentTypesKind.DerivedInterfaces, cancellationToken).ConfigureAwait(false); @@ -273,7 +275,7 @@ internal static async Task> FindDerivedInterfac /// The projects to search. Can be null to search the entire solution. #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters public static async Task> FindImplementationsAsync( - INamedTypeSymbol type, Solution solution, bool transitive = true, IImmutableSet projects = null, CancellationToken cancellationToken = default) + INamedTypeSymbol type, Solution solution, bool transitive = true, IImmutableSet? projects = null, CancellationToken cancellationToken = default) #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters { if (type == null) @@ -288,7 +290,7 @@ public static async Task> FindImplementationsAsync /// /// Use this overload to avoid boxing the result into an . internal static async Task> FindImplementationsArrayAsync( - INamedTypeSymbol type, Solution solution, bool transitive, IImmutableSet projects = null, CancellationToken cancellationToken = default) + INamedTypeSymbol type, Solution solution, bool transitive, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { var types = await DependentTypeFinder.FindTypesAsync( type, solution, projects, transitive, DependentTypesKind.ImplementingTypes, cancellationToken).ConfigureAwait(false); @@ -302,7 +304,7 @@ internal static async Task> FindImplementations /// cref="INamedTypeSymbol"/> this will be both immediate and transitive implementations. /// public static async Task> FindImplementationsAsync( - ISymbol symbol, Solution solution, IImmutableSet projects = null, CancellationToken cancellationToken = default) + ISymbol symbol, Solution solution, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { if (symbol == null) throw new ArgumentNullException(nameof(symbol)); @@ -326,7 +328,7 @@ public static async Task> FindImplementationsAsync( /// Use this overload to avoid boxing the result into an . /// internal static async Task> FindMemberImplementationsArrayAsync( - ISymbol symbol, Solution solution, IImmutableSet projects = null, CancellationToken cancellationToken = default) + ISymbol symbol, Solution solution, IImmutableSet? projects = null, CancellationToken cancellationToken = default) { if (!symbol.IsImplementableMember()) return ImmutableArray.Empty; From ffd34209a1e616cae2670c873058ae664f713007 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:40:24 -0700 Subject: [PATCH 08/35] NRT enable code --- .../Portable/EmbeddedLanguages/IEmbeddedLanguagesProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/EmbeddedLanguages/IEmbeddedLanguagesProvider.cs b/src/Workspaces/Core/Portable/EmbeddedLanguages/IEmbeddedLanguagesProvider.cs index 8dc483d351ccd..ddb7185cf11dd 100644 --- a/src/Workspaces/Core/Portable/EmbeddedLanguages/IEmbeddedLanguagesProvider.cs +++ b/src/Workspaces/Core/Portable/EmbeddedLanguages/IEmbeddedLanguagesProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using Microsoft.CodeAnalysis.Host; From 4c13017c7e62340725b63cef7f56817e0d0948c9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:42:59 -0700 Subject: [PATCH 09/35] NRT enable code --- .../FindSymbols/SyntaxTree/SyntaxTreeIndex.LiteralInfo.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.LiteralInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.LiteralInfo.cs index e918bba1aaefb..ce2f3f57e3f9c 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.LiteralInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.LiteralInfo.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using Microsoft.CodeAnalysis.Shared.Utilities; using Roslyn.Utilities; From 19e576917f3c9ad8c568014f1e0e374a5028bc1a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:45:55 -0700 Subject: [PATCH 10/35] NRT enable code --- .../FindSymbols/SyntaxTree/SyntaxTreeIndex.IdentifierInfo.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.IdentifierInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.IdentifierInfo.cs index 4608b1cb2f7a9..4d69a45bc65f0 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.IdentifierInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.IdentifierInfo.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using Microsoft.CodeAnalysis.Shared.Utilities; using Roslyn.Utilities; From 9fe660cdfd1646d2fd3f4ae8244a505768da44bf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:49:08 -0700 Subject: [PATCH 11/35] NRT enable code --- .../Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs | 6 +++--- .../FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs | 6 +++--- .../FindSymbols/SymbolTree/SymbolTreeInfo_Source.cs | 8 +++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs index e14c4313f6212..a737a7de85f65 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs @@ -98,7 +98,7 @@ private SymbolTreeInfo( ImmutableArray sortedNodes, Task spellCheckerTask, OrderPreservingMultiDictionary inheritanceMap, - MultiDictionary receiverTypeNameToExtensionMethodMap) + MultiDictionary? receiverTypeNameToExtensionMethodMap) : this(checksum, sortedNodes, spellCheckerTask, CreateIndexBasedInheritanceMap(sortedNodes, inheritanceMap), receiverTypeNameToExtensionMethodMap) @@ -496,14 +496,14 @@ private static SymbolTreeInfo CreateSymbolTreeInfo( HostWorkspaceServices services, SolutionKey solutionKey, Checksum checksum, string filePath, ImmutableArray unsortedNodes, OrderPreservingMultiDictionary inheritanceMap, - MultiDictionary simpleMethods) + MultiDictionary? receiverTypeNameToExtensionMethodMap) { SortNodes(unsortedNodes, out var sortedNodes); var createSpellCheckerTask = GetSpellCheckerAsync( services, solutionKey, checksum, filePath, sortedNodes); return new SymbolTreeInfo( - checksum, sortedNodes, createSpellCheckerTask, inheritanceMap, simpleMethods); + checksum, sortedNodes, createSpellCheckerTask, inheritanceMap, receiverTypeNameToExtensionMethodMap); } private static OrderPreservingMultiDictionary CreateIndexBasedInheritanceMap( diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs index 1c1e26f4d48f6..693d892bc16fe 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs @@ -300,11 +300,11 @@ internal SymbolTreeInfo Create() } } - var extensionMethodsMap = new MultiDictionary(); - var unsortedNodes = GenerateUnsortedNodes(extensionMethodsMap); + var receiverTypeNameToExtensionMethodMap = new MultiDictionary(); + var unsortedNodes = GenerateUnsortedNodes(receiverTypeNameToExtensionMethodMap); return CreateSymbolTreeInfo( - _services, _solutionKey, _checksum, _reference.FilePath, unsortedNodes, _inheritanceMap, extensionMethodsMap); + _services, _solutionKey, _checksum, _reference.FilePath, unsortedNodes, _inheritanceMap, receiverTypeNameToExtensionMethodMap); } public void Dispose() diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Source.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Source.cs index acf388e910315..de1d63f437d4b 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Source.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Source.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Linq; using System.Runtime.CompilerServices; @@ -37,7 +35,7 @@ public static Task GetInfoForSourceAssemblyAsync( var solution = project.Solution; var services = solution.Workspace.Services; var solutionKey = SolutionKey.ToSolutionKey(solution); - var projectFilePath = project.FilePath; + var projectFilePath = project.FilePath ?? ""; var result = TryLoadOrCreateAsync( services, @@ -124,9 +122,9 @@ internal static async Task CreateSourceSymbolTreeInfoAsync( var solutionKey = SolutionKey.ToSolutionKey(solution); return CreateSymbolTreeInfo( - services, solutionKey, checksum, project.FilePath, unsortedNodes.ToImmutableAndFree(), + services, solutionKey, checksum, project.FilePath ?? "", unsortedNodes.ToImmutableAndFree(), inheritanceMap: new OrderPreservingMultiDictionary(), - simpleMethods: null); + receiverTypeNameToExtensionMethodMap: null); } // generate nodes for the global namespace an all descendants From c89c3db503508bf1ae14b10ba59954ef342bd053 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 10:53:17 -0700 Subject: [PATCH 12/35] In progress --- .../SymbolTree/SymbolTreeInfo_Metadata.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs index 693d892bc16fe..d56c54ae82616 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -43,7 +41,7 @@ private static string GetMetadataNameWithoutBackticks(MetadataReader reader, Str } } - public static MetadataId GetMetadataIdNoThrow(PortableExecutableReference reference) + public static MetadataId? GetMetadataIdNoThrow(PortableExecutableReference reference) { try { @@ -55,7 +53,7 @@ public static MetadataId GetMetadataIdNoThrow(PortableExecutableReference refere } } - private static Metadata GetMetadataNoThrow(PortableExecutableReference reference) + private static Metadata? GetMetadataNoThrow(PortableExecutableReference reference) { try { @@ -67,7 +65,7 @@ private static Metadata GetMetadataNoThrow(PortableExecutableReference reference } } - public static ValueTask GetInfoForMetadataReferenceAsync( + public static ValueTask GetInfoForMetadataReferenceAsync( Solution solution, PortableExecutableReference reference, bool loadOnly, CancellationToken cancellationToken) { @@ -82,7 +80,7 @@ public static ValueTask GetInfoForMetadataReferenceAsync( /// Note: will never return null; /// [PerformanceSensitive("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1224834", OftenCompletesSynchronously = true)] - public static async ValueTask GetInfoForMetadataReferenceAsync( + public static async ValueTask GetInfoForMetadataReferenceAsync( Solution solution, PortableExecutableReference reference, Checksum checksum, @@ -114,13 +112,13 @@ public static async ValueTask GetInfoForMetadataReferenceAsync( solution.Workspace.Services, SolutionKey.ToSolutionKey(solution), reference, checksum, metadata, cancellationToken).ConfigureAwait(false); } - public static Task TryGetCachedInfoForMetadataReferenceIgnoreChecksumAsync(PortableExecutableReference reference, CancellationToken cancellationToken) + public static async Task TryGetCachedInfoForMetadataReferenceIgnoreChecksumAsync(PortableExecutableReference reference, CancellationToken cancellationToken) { var metadataId = GetMetadataIdNoThrow(reference); - if (metadataId != null && s_metadataIdToInfo.TryGetValue(metadataId, out var infoTask)) - return infoTask.GetValueAsync(cancellationToken); + if (metadataId == null || !s_metadataIdToInfo.TryGetValue(metadataId, out var infoTask)) + return null; - return SpecializedTasks.Null(); + return await infoTask.GetValueAsync(cancellationToken).ConfigureAwait(false); } private static async Task GetInfoForMetadataReferenceSlowAsync( @@ -139,7 +137,7 @@ private static async Task GetInfoForMetadataReferenceSlowAsync( var asyncLazy = s_metadataIdToInfo.GetValue( metadata.Id, id => new AsyncLazy( - c => TryCreateMetadataSymbolTreeInfoAsync(services, solutionKey, reference, checksum, c), + c => CreateMetadataSymbolTreeInfoAsync(services, solutionKey, reference, checksum, c), cacheResult: true)); return await asyncLazy.GetValueAsync(cancellationToken).ConfigureAwait(false); @@ -165,7 +163,7 @@ private static Checksum GetMetadataChecksumSlow(Solution solution, PortableExecu { return ChecksumCache.GetOrCreate(reference, _ => { - var serializer = solution.Workspace.Services.GetService(); + var serializer = solution.Workspace.Services.GetRequiredService(); var checksum = serializer.CreateChecksum(reference, cancellationToken); // Include serialization format version in our checksum. That way if the @@ -175,14 +173,14 @@ private static Checksum GetMetadataChecksumSlow(Solution solution, PortableExecu }); } - private static Task TryCreateMetadataSymbolTreeInfoAsync( + private static Task CreateMetadataSymbolTreeInfoAsync( HostWorkspaceServices services, SolutionKey solutionKey, PortableExecutableReference reference, Checksum checksum, CancellationToken cancellationToken) { - var filePath = reference.FilePath; + var filePath = reference.FilePath ?? ""; var result = TryLoadOrCreateAsync( services, @@ -219,7 +217,7 @@ private struct MetadataInfoCreator : IDisposable private readonly MetadataNode _rootNode; // The metadata reader for the current metadata in the PEReference. - private MetadataReader _metadataReader; + private MetadataReader? _metadataReader; // The set of type definitions we've read out of the current metadata reader. private readonly List _allTypeDefinitions = new(); @@ -249,7 +247,7 @@ public MetadataInfoCreator( _rootNode = MetadataNode.Allocate(name: ""); } - private static ImmutableArray GetModuleMetadata(Metadata metadata) + private static ImmutableArray GetModuleMetadata(Metadata? metadata) { try { @@ -304,7 +302,7 @@ internal SymbolTreeInfo Create() var unsortedNodes = GenerateUnsortedNodes(receiverTypeNameToExtensionMethodMap); return CreateSymbolTreeInfo( - _services, _solutionKey, _checksum, _reference.FilePath, unsortedNodes, _inheritanceMap, receiverTypeNameToExtensionMethodMap); + _services, _solutionKey, _checksum, _reference.FilePath ?? "", unsortedNodes, _inheritanceMap, receiverTypeNameToExtensionMethodMap); } public void Dispose() @@ -325,6 +323,7 @@ public void Dispose() private void GenerateMetadataNodes() { + Contract.ThrowIfNull(_metadataReader); var globalNamespace = _metadataReader.GetNamespaceDefinitionRoot(); var definitionMap = OrderPreservingMultiDictionary.GetInstance(); try From 8bb81a29bf5c5a0b37701ef3802d2c697329b3a5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:00:26 -0700 Subject: [PATCH 13/35] NRT enable code --- .../FindReferences/DependentTypeFinder.cs | 3 + .../SymbolTree/SymbolTreeInfo_Metadata.cs | 134 ++++++++++-------- 2 files changed, 80 insertions(+), 57 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs index 35e77017840f0..adc1dd868cc1a 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypeFinder.cs @@ -424,6 +424,9 @@ private static async Task AddMatchingMetadataTypesInMetadataReferenceAsync( var symbolTreeInfo = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync( project.Solution, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false); + // This will always be non-null since we pass loadOnly: false above. + Contract.ThrowIfNull(symbolTreeInfo); + // For each type we care about, see if we can find any derived types // in this index. foreach (var metadataType in metadataTypes) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs index d56c54ae82616..64b9d1f33fa88 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Reflection; @@ -216,9 +217,6 @@ private struct MetadataInfoCreator : IDisposable private readonly OrderPreservingMultiDictionary _parentToChildren; private readonly MetadataNode _rootNode; - // The metadata reader for the current metadata in the PEReference. - private MetadataReader? _metadataReader; - // The set of type definitions we've read out of the current metadata reader. private readonly List _allTypeDefinitions = new(); @@ -239,7 +237,6 @@ public MetadataInfoCreator( _solutionKey = solutionKey; _checksum = checksum; _reference = reference; - _metadataReader = null; _containsExtensionsMethod = false; _inheritanceMap = OrderPreservingMultiDictionary.GetInstance(); @@ -276,17 +273,17 @@ internal SymbolTreeInfo Create() { try { - _metadataReader = moduleMetadata.GetMetadataReader(); + var metadataReader = moduleMetadata.GetMetadataReader(); // First, walk all the symbols from metadata, populating the parentToChilren // map accordingly. - GenerateMetadataNodes(); + GenerateMetadataNodes(metadataReader); // Now, once we populated the initial map, go and get all the inheritance // information for all the types in the metadata. This may refer to // types that we haven't seen yet. We'll add those types to the parentToChildren // map accordingly. - PopulateInheritanceMap(); + PopulateInheritanceMap(metadataReader); // Clear the set of type definitions we read out of this piece of metadata. _allTypeDefinitions.Clear(); @@ -321,17 +318,16 @@ public void Dispose() _inheritanceMap.Free(); } - private void GenerateMetadataNodes() + private void GenerateMetadataNodes(MetadataReader metadataReader) { - Contract.ThrowIfNull(_metadataReader); - var globalNamespace = _metadataReader.GetNamespaceDefinitionRoot(); + var globalNamespace = metadataReader.GetNamespaceDefinitionRoot(); var definitionMap = OrderPreservingMultiDictionary.GetInstance(); try { - LookupMetadataDefinitions(globalNamespace, definitionMap); + LookupMetadataDefinitions(metadataReader, globalNamespace, definitionMap); foreach (var (name, definitions) in definitionMap) - GenerateMetadataNodes(_rootNode, name, definitions); + GenerateMetadataNodes(metadataReader, _rootNode, name, definitions); } finally { @@ -340,6 +336,7 @@ private void GenerateMetadataNodes() } private void GenerateMetadataNodes( + MetadataReader metadataReader, MetadataNode parentNode, string nodeName, OrderPreservingMultiDictionary.ValueSet definitionsWithSameName) @@ -364,11 +361,11 @@ private void GenerateMetadataNodes( _extensionMethodToParameterTypeInfo.Add(childNode, definition.ReceiverTypeInfo); } - LookupMetadataDefinitions(definition, definitionMap); + LookupMetadataDefinitions(metadataReader, definition, definitionMap); } foreach (var (name, definitions) in definitionMap) - GenerateMetadataNodes(childNode, name, definitions); + GenerateMetadataNodes(metadataReader, childNode, name, definitions); } finally { @@ -377,21 +374,23 @@ private void GenerateMetadataNodes( } private void LookupMetadataDefinitions( + MetadataReader metadataReader, MetadataDefinition definition, OrderPreservingMultiDictionary definitionMap) { switch (definition.Kind) { case MetadataDefinitionKind.Namespace: - LookupMetadataDefinitions(definition.Namespace, definitionMap); + LookupMetadataDefinitions(metadataReader, definition.Namespace, definitionMap); break; case MetadataDefinitionKind.Type: - LookupMetadataDefinitions(definition.Type, definitionMap); + LookupMetadataDefinitions(metadataReader, definition.Type, definitionMap); break; } } private void LookupMetadataDefinitions( + MetadataReader metadataReader, TypeDefinition typeDefinition, OrderPreservingMultiDictionary definitionMap) { @@ -406,7 +405,7 @@ private void LookupMetadataDefinitions( { foreach (var child in typeDefinition.GetMethods()) { - var method = _metadataReader.GetMethodDefinition(child); + var method = metadataReader.GetMethodDefinition(child); if ((method.Attributes & MethodAttributes.SpecialName) != 0 || (method.Attributes & MethodAttributes.RTSpecialName) != 0) { @@ -422,8 +421,8 @@ private void LookupMetadataDefinitions( method.GetCustomAttributes().Count > 0) { // Decode method signature to get the receiver type name (i.e. type name for the first parameter) - var blob = _metadataReader.GetBlobReader(method.Signature); - var decoder = new SignatureDecoder(ParameterTypeInfoProvider.Instance, _metadataReader, genericContext: null); + var blob = metadataReader.GetBlobReader(method.Signature); + var decoder = new SignatureDecoder(ParameterTypeInfoProvider.Instance, metadataReader, genericContext: null!); var signature = decoder.DecodeMethodSignature(ref blob); // It'd be good if we don't need to go through all parameters and make unnecessary allocations. @@ -432,7 +431,7 @@ private void LookupMetadataDefinitions( { _containsExtensionsMethod = true; var firstParameterTypeInfo = signature.ParameterTypes[0]; - var definition = new MetadataDefinition(MetadataDefinitionKind.Member, _metadataReader.GetString(method.Name), firstParameterTypeInfo); + var definition = new MetadataDefinition(MetadataDefinitionKind.Member, metadataReader.GetString(method.Name), firstParameterTypeInfo); definitionMap.Add(definition.Name, definition); } } @@ -441,7 +440,7 @@ private void LookupMetadataDefinitions( foreach (var child in typeDefinition.GetNestedTypes()) { - var type = _metadataReader.GetTypeDefinition(child); + var type = metadataReader.GetTypeDefinition(child); // We don't include internals from metadata assemblies. It's less likely that // a project would have IVT to it and so it helps us save on memory. It also @@ -449,7 +448,7 @@ private void LookupMetadataDefinitions( // dll was obfuscated. if (IsPublic(type.Attributes)) { - var definition = MetadataDefinition.Create(_metadataReader, type); + var definition = MetadataDefinition.Create(metadataReader, type); definitionMap.Add(definition.Name, definition); _allTypeDefinitions.Add(definition); } @@ -457,21 +456,22 @@ private void LookupMetadataDefinitions( } private void LookupMetadataDefinitions( + MetadataReader metadataReader, NamespaceDefinition namespaceDefinition, OrderPreservingMultiDictionary definitionMap) { foreach (var child in namespaceDefinition.NamespaceDefinitions) { - var definition = MetadataDefinition.Create(_metadataReader, child); + var definition = MetadataDefinition.Create(metadataReader, child); definitionMap.Add(definition.Name, definition); } foreach (var child in namespaceDefinition.TypeDefinitions) { - var typeDefinition = _metadataReader.GetTypeDefinition(child); + var typeDefinition = metadataReader.GetTypeDefinition(child); if (IsPublic(typeDefinition.Attributes)) { - var definition = MetadataDefinition.Create(_metadataReader, typeDefinition); + var definition = MetadataDefinition.Create(metadataReader, typeDefinition); definitionMap.Add(definition.Name, definition); _allTypeDefinitions.Add(definition); } @@ -484,16 +484,18 @@ private static bool IsPublic(TypeAttributes attributes) return masked is TypeAttributes.Public or TypeAttributes.NestedPublic; } - private void PopulateInheritanceMap() + private void PopulateInheritanceMap(MetadataReader metadataReader) { foreach (var typeDefinition in _allTypeDefinitions) { Debug.Assert(typeDefinition.Kind == MetadataDefinitionKind.Type); - PopulateInheritance(typeDefinition); + PopulateInheritance(metadataReader, typeDefinition); } } - private void PopulateInheritance(MetadataDefinition metadataTypeDefinition) + private void PopulateInheritance( + MetadataReader metadataReader, + MetadataDefinition metadataTypeDefinition) { var derivedTypeDefinition = metadataTypeDefinition.Type; var interfaceImplHandles = derivedTypeDefinition.GetInterfaceImplementations(); @@ -506,19 +508,20 @@ private void PopulateInheritance(MetadataDefinition metadataTypeDefinition) var derivedTypeSimpleName = metadataTypeDefinition.Name; - PopulateInheritance(derivedTypeSimpleName, derivedTypeDefinition.BaseType); + PopulateInheritance(metadataReader, derivedTypeSimpleName, derivedTypeDefinition.BaseType); foreach (var interfaceImplHandle in interfaceImplHandles) { if (!interfaceImplHandle.IsNil) { - var interfaceImpl = _metadataReader.GetInterfaceImplementation(interfaceImplHandle); - PopulateInheritance(derivedTypeSimpleName, interfaceImpl.Interface); + var interfaceImpl = metadataReader.GetInterfaceImplementation(interfaceImplHandle); + PopulateInheritance(metadataReader, derivedTypeSimpleName, interfaceImpl.Interface); } } } private void PopulateInheritance( + MetadataReader metadataReader, string derivedTypeSimpleName, EntityHandle baseTypeOrInterfaceHandle) { @@ -530,7 +533,7 @@ private void PopulateInheritance( var baseTypeNameParts = s_stringListPool.Allocate(); try { - AddBaseTypeNameParts(baseTypeOrInterfaceHandle, baseTypeNameParts); + AddBaseTypeNameParts(metadataReader, baseTypeOrInterfaceHandle, baseTypeNameParts); if (baseTypeNameParts.Count > 0 && baseTypeNameParts.TrueForAll(s_isNotNullOrEmpty)) { @@ -554,45 +557,50 @@ private void PopulateInheritance( } private void AddBaseTypeNameParts( + MetadataReader metadataReader, EntityHandle baseTypeOrInterfaceHandle, List simpleNames) { - var typeDefOrRefHandle = GetTypeDefOrRefHandle(baseTypeOrInterfaceHandle); + var typeDefOrRefHandle = GetTypeDefOrRefHandle(metadataReader, baseTypeOrInterfaceHandle); if (typeDefOrRefHandle.Kind == HandleKind.TypeDefinition) { - AddTypeDefinitionNameParts((TypeDefinitionHandle)typeDefOrRefHandle, simpleNames); + AddTypeDefinitionNameParts(metadataReader, (TypeDefinitionHandle)typeDefOrRefHandle, simpleNames); } else if (typeDefOrRefHandle.Kind == HandleKind.TypeReference) { - AddTypeReferenceNameParts((TypeReferenceHandle)typeDefOrRefHandle, simpleNames); + AddTypeReferenceNameParts(metadataReader, (TypeReferenceHandle)typeDefOrRefHandle, simpleNames); } } private void AddTypeDefinitionNameParts( - TypeDefinitionHandle handle, List simpleNames) + MetadataReader metadataReader, + TypeDefinitionHandle handle, + List simpleNames) { - var typeDefinition = _metadataReader.GetTypeDefinition(handle); + var typeDefinition = metadataReader.GetTypeDefinition(handle); var declaringType = typeDefinition.GetDeclaringType(); if (declaringType.IsNil) { // Not a nested type, just add the containing namespace. - AddNamespaceParts(typeDefinition.NamespaceDefinition, simpleNames); + AddNamespaceParts(metadataReader, typeDefinition.NamespaceDefinition, simpleNames); } else { // We're a nested type, recurse and add the type we're declared in. // It will handle adding the namespace properly. - AddTypeDefinitionNameParts(declaringType, simpleNames); + AddTypeDefinitionNameParts(metadataReader, declaringType, simpleNames); } // Now add the simple name of the type itself. - simpleNames.Add(GetMetadataNameWithoutBackticks(_metadataReader, typeDefinition.Name)); + simpleNames.Add(GetMetadataNameWithoutBackticks(metadataReader, typeDefinition.Name)); } - private void AddNamespaceParts( - StringHandle namespaceHandle, List simpleNames) + private static void AddNamespaceParts( + MetadataReader metadataReader, + StringHandle namespaceHandle, + List simpleNames) { - var blobReader = _metadataReader.GetBlobReader(namespaceHandle); + var blobReader = metadataReader.GetBlobReader(namespaceHandle); while (true) { @@ -622,26 +630,33 @@ private void AddNamespaceParts( } private void AddNamespaceParts( - NamespaceDefinitionHandle namespaceHandle, List simpleNames) + MetadataReader metadataReader, + NamespaceDefinitionHandle namespaceHandle, + List simpleNames) { if (namespaceHandle.IsNil) { return; } - var namespaceDefinition = _metadataReader.GetNamespaceDefinition(namespaceHandle); - AddNamespaceParts(namespaceDefinition.Parent, simpleNames); - simpleNames.Add(_metadataReader.GetString(namespaceDefinition.Name)); + var namespaceDefinition = metadataReader.GetNamespaceDefinition(namespaceHandle); + AddNamespaceParts(metadataReader, namespaceDefinition.Parent, simpleNames); + simpleNames.Add(metadataReader.GetString(namespaceDefinition.Name)); } - private void AddTypeReferenceNameParts(TypeReferenceHandle handle, List simpleNames) + private static void AddTypeReferenceNameParts( + MetadataReader metadataReader, + TypeReferenceHandle handle, + List simpleNames) { - var typeReference = _metadataReader.GetTypeReference(handle); - AddNamespaceParts(typeReference.Namespace, simpleNames); - simpleNames.Add(GetMetadataNameWithoutBackticks(_metadataReader, typeReference.Name)); + var typeReference = metadataReader.GetTypeReference(handle); + AddNamespaceParts(metadataReader, typeReference.Namespace, simpleNames); + simpleNames.Add(GetMetadataNameWithoutBackticks(metadataReader, typeReference.Name)); } - private EntityHandle GetTypeDefOrRefHandle(EntityHandle baseTypeOrInterfaceHandle) + private static EntityHandle GetTypeDefOrRefHandle( + MetadataReader metadataReader, + EntityHandle baseTypeOrInterfaceHandle) { switch (baseTypeOrInterfaceHandle.Kind) { @@ -650,7 +665,7 @@ private EntityHandle GetTypeDefOrRefHandle(EntityHandle baseTypeOrInterfaceHandl return baseTypeOrInterfaceHandle; case HandleKind.TypeSpecification: return FirstEntityHandleProvider.Instance.GetTypeFromSpecification( - _metadataReader, (TypeSpecificationHandle)baseTypeOrInterfaceHandle); + metadataReader, (TypeSpecificationHandle)baseTypeOrInterfaceHandle); default: return default; } @@ -697,7 +712,7 @@ private void AddUnsortedNodes(ArrayBuilder unsortedNodes, MultiDictionary receiverTypeNameToMethodMap, MetadataNode parentNode, int parentIndex, - string fullyQualifiedContainerName) + string? fullyQualifiedContainerName) { foreach (var child in _parentToChildren[parentNode]) { @@ -727,7 +742,8 @@ private void AddUnsortedNodes(ArrayBuilder unsortedNodes, AddUnsortedNodes(unsortedNodes, receiverTypeNameToMethodMap, child, childIndex, Concat(fullyQualifiedContainerName, child.Name)); } - static string Concat(string containerName, string name) + [return: NotNullIfNotNull("containerName")] + static string? Concat(string? containerName, string name) { if (containerName == null) { @@ -746,7 +762,11 @@ static string Concat(string containerName, string name) private class MetadataNode { - public string Name { get; private set; } + /// + /// Represent this as non-null because that will be true when this is not in a pool and it is being used by + /// other services. + /// + public string Name { get; private set; } = null!; private static readonly ObjectPool s_pool = SharedPools.Default(); @@ -761,7 +781,7 @@ public static MetadataNode Allocate(string name) public static void Free(MetadataNode node) { Debug.Assert(node.Name != null); - node.Name = null; + node.Name = null!; s_pool.Free(node); } } From a588eca62dac249b7aa258294ea6638997ee907b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:02:38 -0700 Subject: [PATCH 14/35] In progress --- .../SymbolTree/SymbolTreeInfo_Metadata.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs index 64b9d1f33fa88..69a9569ac8bab 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs @@ -762,14 +762,14 @@ private void AddUnsortedNodes(ArrayBuilder unsortedNodes, private class MetadataNode { + private static readonly ObjectPool s_pool = SharedPools.Default(); + /// /// Represent this as non-null because that will be true when this is not in a pool and it is being used by /// other services. /// public string Name { get; private set; } = null!; - private static readonly ObjectPool s_pool = SharedPools.Default(); - public static MetadataNode Allocate(string name) { var node = s_pool.Allocate(); @@ -793,7 +793,7 @@ private enum MetadataDefinitionKind Member, } - private struct MetadataDefinition + private readonly struct MetadataDefinition { public string Name { get; } public MetadataDefinitionKind Kind { get; } @@ -803,15 +803,21 @@ private struct MetadataDefinition /// public ParameterTypeInfo ReceiverTypeInfo { get; } - public NamespaceDefinition Namespace { get; private set; } - public TypeDefinition Type { get; private set; } + public NamespaceDefinition Namespace { get; } + public TypeDefinition Type { get; } - public MetadataDefinition(MetadataDefinitionKind kind, string name, ParameterTypeInfo receiverTypeInfo = default) - : this() + public MetadataDefinition( + MetadataDefinitionKind kind, + string name, + ParameterTypeInfo receiverTypeInfo = default, + NamespaceDefinition @namespace = default, + TypeDefinition type = default) { Kind = kind; Name = name; ReceiverTypeInfo = receiverTypeInfo; + Namespace = @namespace; + Type = type; } public static MetadataDefinition Create( @@ -820,21 +826,15 @@ public static MetadataDefinition Create( var definition = reader.GetNamespaceDefinition(namespaceHandle); return new MetadataDefinition( MetadataDefinitionKind.Namespace, - reader.GetString(definition.Name)) - { - Namespace = definition - }; + reader.GetString(definition.Name), + @namespace: definition); } public static MetadataDefinition Create( MetadataReader reader, TypeDefinition definition) { var typeName = GetMetadataNameWithoutBackticks(reader, definition.Name); - - return new MetadataDefinition(MetadataDefinitionKind.Type, typeName) - { - Type = definition - }; + return new MetadataDefinition(MetadataDefinitionKind.Type, typeName, type: definition); } } } From bb409f18ffd4de406db24df1f85cf6fde9b50780 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:06:31 -0700 Subject: [PATCH 15/35] NRT enable code --- .../Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs index c80c8ecd7b935..88be730e692c2 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Diagnostics; using System.Reflection.Metadata; From a731465fcd45fceea82e21ac8e09f5d1c6da0bf4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:09:40 -0700 Subject: [PATCH 16/35] NRT enable code --- .../SymbolTreeInfo.FirstEntityHandleProvider.cs | 12 +++++------- .../FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs | 10 +++++----- .../SymbolTree/SymbolTreeInfo_Metadata.cs | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.FirstEntityHandleProvider.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.FirstEntityHandleProvider.cs index a8e9f56f097dc..4060cc3b7dd01 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.FirstEntityHandleProvider.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.FirstEntityHandleProvider.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; @@ -20,7 +18,7 @@ internal partial class SymbolTreeInfo /// are added. For example, for the type "X.Y.O`1.I`2, we will produce [X, Y, O, I] /// /// - private class FirstEntityHandleProvider : ISignatureTypeProvider + private class FirstEntityHandleProvider : ISignatureTypeProvider { public static readonly FirstEntityHandleProvider Instance = new(); @@ -30,10 +28,10 @@ public EntityHandle GetTypeFromSpecification(MetadataReader reader, TypeSpecific // instantiated generics). It will call back into us to get the first handle // for the type def or type ref that the specification starts with. var sigReader = reader.GetBlobReader(reader.GetTypeSpecification(handle).Signature); - return new SignatureDecoder(this, reader, genericContext: null).DecodeType(ref sigReader); + return new SignatureDecoder(this, reader, genericContext: null).DecodeType(ref sigReader); } - public EntityHandle GetTypeFromSpecification(MetadataReader reader, object genericContext, TypeSpecificationHandle handle, byte rawTypeKind) => + public EntityHandle GetTypeFromSpecification(MetadataReader reader, object? genericContext, TypeSpecificationHandle handle, byte rawTypeKind) => GetTypeFromSpecification(reader, handle); public EntityHandle GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind) => handle; @@ -55,8 +53,8 @@ public EntityHandle GetTypeFromSpecification(MetadataReader reader, object gener // just return the empty string. Similarly, as we never construct generics, // there is no need to provide anything for the generic parameter names. public EntityHandle GetFunctionPointerType(MethodSignature signature) => default; - public EntityHandle GetGenericMethodParameter(object genericContext, int index) => default; - public EntityHandle GetGenericTypeParameter(object genericContext, int index) => default; + public EntityHandle GetGenericMethodParameter(object? genericContext, int index) => default; + public EntityHandle GetGenericTypeParameter(object? genericContext, int index) => default; public EntityHandle GetPrimitiveType(PrimitiveTypeCode typeCode) => default; } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs index 88be730e692c2..ce67fb5932208 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs @@ -136,7 +136,7 @@ public ExtensionMethodInfo(string fullyQualifiedContainerName, string name) } } - private sealed class ParameterTypeInfoProvider : ISignatureTypeProvider + private sealed class ParameterTypeInfoProvider : ISignatureTypeProvider { public static readonly ParameterTypeInfoProvider Instance = new(); @@ -168,10 +168,10 @@ public ParameterTypeInfo GetTypeFromReference(MetadataReader reader, TypeReferen return new ParameterTypeInfo(name, isComplex: false, isArray: false); } - public ParameterTypeInfo GetTypeFromSpecification(MetadataReader reader, object genericContext, TypeSpecificationHandle handle, byte rawTypeKind) + public ParameterTypeInfo GetTypeFromSpecification(MetadataReader reader, object? genericContext, TypeSpecificationHandle handle, byte rawTypeKind) { var sigReader = reader.GetBlobReader(reader.GetTypeSpecification(handle).Signature); - return new SignatureDecoder(Instance, reader, genericContext).DecodeType(ref sigReader); + return new SignatureDecoder(Instance, reader, genericContext).DecodeType(ref sigReader); } public ParameterTypeInfo GetArrayType(ParameterTypeInfo elementType, ArrayShape shape) => GetArrayTypeInfo(elementType); @@ -185,9 +185,9 @@ private static ParameterTypeInfo GetArrayTypeInfo(ParameterTypeInfo elementType) public ParameterTypeInfo GetFunctionPointerType(MethodSignature signature) => ComplexInfo; - public ParameterTypeInfo GetGenericMethodParameter(object genericContext, int index) => ComplexInfo; + public ParameterTypeInfo GetGenericMethodParameter(object? genericContext, int index) => ComplexInfo; - public ParameterTypeInfo GetGenericTypeParameter(object genericContext, int index) => ComplexInfo; + public ParameterTypeInfo GetGenericTypeParameter(object? genericContext, int index) => ComplexInfo; public ParameterTypeInfo GetModifiedType(ParameterTypeInfo modifier, ParameterTypeInfo unmodifiedType, bool isRequired) => ComplexInfo; diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs index 69a9569ac8bab..c6f2fef79644e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs @@ -422,7 +422,7 @@ private void LookupMetadataDefinitions( { // Decode method signature to get the receiver type name (i.e. type name for the first parameter) var blob = metadataReader.GetBlobReader(method.Signature); - var decoder = new SignatureDecoder(ParameterTypeInfoProvider.Instance, metadataReader, genericContext: null!); + var decoder = new SignatureDecoder(ParameterTypeInfoProvider.Instance, metadataReader, genericContext: null); var signature = decoder.DecodeMethodSignature(ref blob); // It'd be good if we don't need to go through all parameters and make unnecessary allocations. From 26ba8f0bffc07fc24855636ff6cd8db7f002d7c1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:14:20 -0700 Subject: [PATCH 17/35] NRT enable code --- .../Core/Portable/FindSymbols/SearchQuery.cs | 6 ++---- .../Core/Portable/FindSymbols/SymbolCallerInfo.cs | 4 +--- .../SymbolTree/ISymbolTreeInfoCacheService.cs | 6 ++---- .../Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs | 10 +++++++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs b/src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs index b7b9fe03d4fa1..b69e756726380 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SearchQuery.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using Roslyn.Utilities; @@ -13,7 +11,7 @@ internal class SearchQuery : IDisposable { /// The name being searched for. Is null in the case of custom predicate searching.. But /// can be used for faster index based searching when it is available. - public readonly string Name; + public readonly string? Name; ///The kind of search this is. Faster index-based searching can be used if the /// SearchKind is not . @@ -22,7 +20,7 @@ internal class SearchQuery : IDisposable ///The predicate to fall back on if faster index searching is not possible. private readonly Func _predicate; - private readonly WordSimilarityChecker _wordSimilarityChecker; + private readonly WordSimilarityChecker? _wordSimilarityChecker; private SearchQuery(string name, SearchKind kind) { diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolCallerInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolCallerInfo.cs index 66fe2b9233077..c9c694affb235 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolCallerInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolCallerInfo.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; namespace Microsoft.CodeAnalysis.FindSymbols @@ -17,7 +15,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols /// member that this symbol overrides, or through an interface member that this symbol /// implements will be considered 'indirect'. /// - public struct SymbolCallerInfo + public readonly struct SymbolCallerInfo { /// /// The symbol that is calling the symbol being called. diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/ISymbolTreeInfoCacheService.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/ISymbolTreeInfoCacheService.cs index c05a5b5774a8a..b93eecfcab6e8 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/ISymbolTreeInfoCacheService.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/ISymbolTreeInfoCacheService.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; @@ -15,11 +13,11 @@ internal interface ISymbolTreeInfoCacheService : IWorkspaceService /// /// Returns null if the info cannot be retrieved from the cache. /// - Task TryGetSourceSymbolTreeInfoAsync(Project project, CancellationToken cancellationToken); + Task TryGetSourceSymbolTreeInfoAsync(Project project, CancellationToken cancellationToken); /// /// Returns null if the info cannot be retrieved from the cache. /// - ValueTask TryGetMetadataSymbolTreeInfoAsync(Solution solution, PortableExecutableReference reference, CancellationToken cancellationToken); + ValueTask TryGetMetadataSymbolTreeInfoAsync(Solution solution, PortableExecutableReference reference, CancellationToken cancellationToken); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs index a737a7de85f65..d61dd88901c96 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs @@ -169,11 +169,15 @@ private Task> FindCoreAsync( // If the query has a specific string provided, then call into the SymbolTreeInfo // helpers optimized for lookup based on an exact name. + + var queryName = query.Name; + Contract.ThrowIfNull(queryName); + return query.Kind switch { - SearchKind.Exact => this.FindAsync(lazyAssembly, query.Name, ignoreCase: false, cancellationToken: cancellationToken), - SearchKind.ExactIgnoreCase => this.FindAsync(lazyAssembly, query.Name, ignoreCase: true, cancellationToken: cancellationToken), - SearchKind.Fuzzy => this.FuzzyFindAsync(lazyAssembly, query.Name, cancellationToken), + SearchKind.Exact => this.FindAsync(lazyAssembly, queryName, ignoreCase: false, cancellationToken: cancellationToken), + SearchKind.ExactIgnoreCase => this.FindAsync(lazyAssembly, queryName, ignoreCase: true, cancellationToken: cancellationToken), + SearchKind.Fuzzy => this.FuzzyFindAsync(lazyAssembly, queryName, cancellationToken), _ => throw new InvalidOperationException(), }; } From 7823c42f54bc47d8b3f76f9bcc2fedcb952e2183 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:14:39 -0700 Subject: [PATCH 18/35] NRT enable code --- src/Workspaces/Core/Portable/FindSymbols/SearchKind.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SearchKind.cs b/src/Workspaces/Core/Portable/FindSymbols/SearchKind.cs index 0af0f9bfb9480..a9950c0eb7b04 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SearchKind.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SearchKind.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindSymbols From 027ccbab7f9494b7c3a0fefd413a65356c27dbcb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:17:22 -0700 Subject: [PATCH 19/35] NRT enable code --- .../FindSymbols/FindReferences/FindReferencesProgress.cs | 2 -- .../Core/Portable/FindSymbols/IFindReferencesProgress.cs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesProgress.cs index 11d1d2e20c90e..d799784c3ef43 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesProgress.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - namespace Microsoft.CodeAnalysis.FindSymbols { /// diff --git a/src/Workspaces/Core/Portable/FindSymbols/IFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/IFindReferencesProgress.cs index f16c2ee8f3144..cc4060cc61ec5 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/IFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/IFindReferencesProgress.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - namespace Microsoft.CodeAnalysis.FindSymbols { /// From c4b4611d2e44a4279eb7adcc9265d48495edd33e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:18:09 -0700 Subject: [PATCH 20/35] NRT enable code --- .../FindReferences/NoOpStreamingFindReferencesProgress.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs index 3308d17f2bd31..64c9e5b7bda9b 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Shared.Utilities; @@ -25,10 +23,6 @@ private NoOpStreamingFindReferencesProgress() { } -#pragma warning disable IDE0060 // Remove unused parameter - public static Task ReportProgressAsync(int current, int maximum) => Task.CompletedTask; -#pragma warning restore IDE0060 // Remove unused parameter - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; public ValueTask OnStartedAsync(CancellationToken cancellationToken) => default; public ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) => default; From 784a98c307b9e8c6244b0abcab688f101a96582b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:19:14 -0700 Subject: [PATCH 21/35] NRT enable code --- .../FindReferences/MetadataUnifyingEquivalenceComparer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/MetadataUnifyingEquivalenceComparer.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/MetadataUnifyingEquivalenceComparer.cs index fe682d13f68f0..0af7cdf738a8d 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/MetadataUnifyingEquivalenceComparer.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/MetadataUnifyingEquivalenceComparer.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis.Shared.Utilities; @@ -18,7 +16,7 @@ private MetadataUnifyingEquivalenceComparer() { } - public bool Equals(ISymbol x, ISymbol y) + public bool Equals(ISymbol? x, ISymbol? y) { // If either symbol is from source, then we must do stricter equality. Consider this: // From c526be85c5572bef3141a3eb7825d72d459c68ef Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:22:16 -0700 Subject: [PATCH 22/35] NRT enable code --- .../FindReferences/IRemoteDependentTypeFinderService.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/IRemoteDependentTypeFinderService.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/IRemoteDependentTypeFinderService.cs index 45a516c4dc98a..4e59868f38b6a 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/IRemoteDependentTypeFinderService.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/IRemoteDependentTypeFinderService.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; From 7f39b56be3480d198545ffdbba2f4f0ed61ae80d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:25:51 -0700 Subject: [PATCH 23/35] NRT enable code --- .../FindReferences/StreamingFindReferencesProgress.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs index 8173504650cf8..ec17b61a5624b 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Threading; using System.Threading.Tasks; From 4009518a28dab0740ccf18b02ae97fa2c0e360ef Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:25:58 -0700 Subject: [PATCH 24/35] NRT enable code --- .../Portable/FindSymbols/FindReferences/DependentTypesKind.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypesKind.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypesKind.cs index a9ec879fd6b5b..0a87cbfc930c2 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypesKind.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentTypesKind.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - namespace Microsoft.CodeAnalysis.FindSymbols { internal enum DependentTypesKind From 1fc6e09b45c92a0e1b8d4a97db4a8dc41d68815d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:27:13 -0700 Subject: [PATCH 25/35] NRT enable code --- .../Core/Portable/FindSymbols/FindReferences/BaseTypeFinder.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/BaseTypeFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/BaseTypeFinder.cs index bb4d13878f077..2b24a0df2171f 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/BaseTypeFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/BaseTypeFinder.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; From aebd377caea03aef7ddd97b552b7d6160c926f9b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:30:20 -0700 Subject: [PATCH 26/35] NRT enable code --- .../FindLiterals/FindLiteralsSearchEngine.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindLiterals/FindLiteralsSearchEngine.cs b/src/Workspaces/Core/Portable/FindSymbols/FindLiterals/FindLiteralsSearchEngine.cs index 159d2fa0884bc..de39d1e3ba768 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindLiterals/FindLiteralsSearchEngine.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindLiterals/FindLiteralsSearchEngine.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -13,6 +11,7 @@ using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindSymbols { @@ -31,7 +30,7 @@ private enum SearchKind private readonly IStreamingProgressTracker _progressTracker; private readonly object _value; - private readonly string _stringValue; + private readonly string? _stringValue; private readonly long _longValue; private readonly SearchKind _searchKind; @@ -119,8 +118,10 @@ private async Task ProcessDocumentWorkerAsync(Document document, CancellationTok var index = await SyntaxTreeIndex.GetIndexAsync( document, cancellationToken).ConfigureAwait(false); + Contract.ThrowIfNull(index); if (_searchKind == SearchKind.StringLiterals) { + Contract.ThrowIfNull(_stringValue); if (index.ProbablyContainsStringValue(_stringValue)) { await SearchDocumentAsync(document, cancellationToken).ConfigureAwait(false); @@ -135,16 +136,14 @@ private async Task ProcessDocumentWorkerAsync(Document document, CancellationTok private async Task SearchDocumentAsync(Document document, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - var syntaxFacts = document.GetLanguageService(); - var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); + var syntaxFacts = document.GetRequiredLanguageService(); + var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - var matches = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var matches); ProcessNode(syntaxFacts, root, matches, cancellationToken); foreach (var token in matches) - { await _progress.OnReferenceFoundAsync(document, token.Span, cancellationToken).ConfigureAwait(false); - } } private void ProcessNode( @@ -156,7 +155,7 @@ private void ProcessNode( { if (child.IsNode) { - ProcessNode(syntaxFacts, child.AsNode(), matches, cancellationToken); + ProcessNode(syntaxFacts, child.AsNode()!, matches, cancellationToken); } else { From a7322b38274e7c4219ac6990eece30f49f894c6f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:30:46 -0700 Subject: [PATCH 27/35] NRT enable code --- src/Workspaces/Core/Portable/FindSymbols/Extensions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/Extensions.cs b/src/Workspaces/Core/Portable/FindSymbols/Extensions.cs index f7f027d00afc6..751a93bdeabd2 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Extensions.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Extensions.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; From 08cb9e5906a198ace2a6e46e3592a132f20a8d70 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:35:42 -0700 Subject: [PATCH 28/35] NRT enable code --- ...vigateToSearchService.CachedDocumentSearch.cs | 2 +- .../DeclarationFinder_SourceDeclarations.cs | 13 +++---------- .../Portable/PatternMatching/PatternMatcher.cs | 16 +++++++--------- .../PatternMatching/PatternMatcherExtensions.cs | 5 +++-- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.CachedDocumentSearch.cs b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.CachedDocumentSearch.cs index 868736a0b90bb..e548a495234a8 100644 --- a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.CachedDocumentSearch.cs +++ b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.CachedDocumentSearch.cs @@ -114,7 +114,7 @@ await SearchCachedDocumentsInCurrentProcessAsync( private static async Task SearchCachedDocumentsInCurrentProcessAsync( IChecksummedPersistentStorageService storageService, string patternName, - string patternContainer, + string? patternContainer, DeclaredSymbolInfoKindSet kinds, Func onItemFound, ImmutableArray documentKeys, diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs index 6421c5f5c25c1..bf39ca7e27b2d 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs @@ -2,16 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.PatternMatching; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindSymbols { @@ -214,9 +212,6 @@ private static async Task> FindSourceDeclarationsWithPat // we'll check if the full name matches the full pattern. var (namePart, containerPart) = PatternMatcher.GetNameAndContainer(pattern); - var dotIndex = pattern.LastIndexOf('.'); - var isDottedPattern = dotIndex >= 0; - // If we don't have a dot in the pattern, just make a pattern matcher for the entire // pattern they passed in. Otherwise, make a pattern matcher just for the part after // the dot. @@ -226,7 +221,7 @@ private static async Task> FindSourceDeclarationsWithPat var symbolAndProjectIds = await searchAsync(query).ConfigureAwait(false); if (symbolAndProjectIds.Length == 0 || - !isDottedPattern) + containerPart == null) { // If it wasn't a dotted pattern, or we didn't get anything back, then we're done. // We can just return whatever set of results we got so far. @@ -257,13 +252,11 @@ internal static Task> FindSourceDeclarationsWithPatternI query => SymbolFinder.FindSourceDeclarationsWithCustomQueryAsync(project, query, criteria, cancellationToken)); } - private static string GetContainer(ISymbol symbol) + private static string? GetContainer(ISymbol symbol) { var container = symbol.ContainingSymbol; if (container == null) - { return null; - } return container.ToDisplayString(DottedNameFormat); } diff --git a/src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs b/src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs index b5d864eb217f9..36c33c465e7be 100644 --- a/src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs +++ b/src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Immutable; using System.Diagnostics; @@ -66,7 +64,7 @@ public virtual void Dispose() public static PatternMatcher CreatePatternMatcher( string pattern, - CultureInfo culture = null, + CultureInfo? culture = null, bool includeMatchedSpans = false, bool allowFuzzyMatching = false) { @@ -76,7 +74,7 @@ public static PatternMatcher CreatePatternMatcher( public static PatternMatcher CreateContainerPatternMatcher( string[] patternParts, char[] containerSplitCharacters, - CultureInfo culture = null, + CultureInfo? culture = null, bool allowFuzzyMatching = false) { return new ContainerPatternMatcher( @@ -85,7 +83,7 @@ public static PatternMatcher CreateContainerPatternMatcher( public static PatternMatcher CreateDotSeparatedContainerMatcher( string pattern, - CultureInfo culture = null, + CultureInfo? culture = null, bool allowFuzzyMatching = false) { return CreateContainerPatternMatcher( @@ -93,18 +91,18 @@ public static PatternMatcher CreateDotSeparatedContainerMatcher( s_dotCharacterArray, culture, allowFuzzyMatching); } - internal static (string name, string containerOpt) GetNameAndContainer(string pattern) + internal static (string name, string? containerOpt) GetNameAndContainer(string pattern) { var dotIndex = pattern.LastIndexOf('.'); var containsDots = dotIndex >= 0; return containsDots - ? (name: pattern.Substring(dotIndex + 1), containerOpt: pattern.Substring(0, dotIndex)) + ? (name: pattern[(dotIndex + 1)..], containerOpt: pattern[..dotIndex]) : (name: pattern, containerOpt: null); } - public abstract bool AddMatches(string candidate, ref TemporaryArray matches); + public abstract bool AddMatches(string? candidate, ref TemporaryArray matches); - private bool SkipMatch(string candidate) + private bool SkipMatch(string? candidate) => _invalidPattern || string.IsNullOrWhiteSpace(candidate); private static bool ContainsUpperCaseLetter(string pattern) diff --git a/src/Workspaces/Core/Portable/PatternMatching/PatternMatcherExtensions.cs b/src/Workspaces/Core/Portable/PatternMatching/PatternMatcherExtensions.cs index f6d3ce848895b..949047b6ed66b 100644 --- a/src/Workspaces/Core/Portable/PatternMatching/PatternMatcherExtensions.cs +++ b/src/Workspaces/Core/Portable/PatternMatching/PatternMatcherExtensions.cs @@ -2,20 +2,21 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.Shared.Collections; namespace Microsoft.CodeAnalysis.PatternMatching { internal static class PatternMatcherExtensions { - public static PatternMatch? GetFirstMatch(this PatternMatcher matcher, string candidate) + public static PatternMatch? GetFirstMatch(this PatternMatcher matcher, string? candidate) { using var matches = TemporaryArray.Empty; matcher.AddMatches(candidate, ref matches.AsRef()); return matches.Count > 0 ? matches[0] : null; } - public static bool Matches(this PatternMatcher matcher, string candidate) + public static bool Matches(this PatternMatcher matcher, [NotNullWhen(true)] string? candidate) => matcher.GetFirstMatch(candidate) != null; } } From e8d65ef21dd3435b43ec9e8aa7ca09b51c2d36b1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:43:59 -0700 Subject: [PATCH 29/35] NRT enable code --- .../Declarations/DeclarationFinder.cs | 19 ++++++++++--------- .../DeclarationFinder_SourceDeclarations.cs | 12 ++++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs index 796e5747e837f..f8e232f60a3c8 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Immutable; using System.Linq; @@ -36,8 +34,8 @@ private static async Task AddCompilationDeclarationsWithNormalQueryAsync( SearchQuery query, SymbolFilter filter, ArrayBuilder list, - Compilation startingCompilation, - IAssemblySymbol startingAssembly, + Compilation? startingCompilation, + IAssemblySymbol? startingAssembly, CancellationToken cancellationToken) { if (!project.SupportsCompilation) @@ -47,7 +45,7 @@ private static async Task AddCompilationDeclarationsWithNormalQueryAsync( using (Logger.LogBlock(FunctionId.SymbolFinder_Project_AddDeclarationsAsync, cancellationToken)) { - var syntaxFacts = project.LanguageServices.GetService(); + var syntaxFacts = project.GetRequiredLanguageService(); // If this is an exact query, we can speed things up by just calling into the // compilation entrypoints that take a string directly. @@ -64,16 +62,16 @@ private static async Task AddCompilationDeclarationsWithNormalQueryAsync( // exact name search, then we will run the query's predicate over every DeclaredSymbolInfo stored in // the doc. var containsSymbol = isExactNameSearch - ? await project.ContainsSymbolsWithNameAsync(query.Name, cancellationToken).ConfigureAwait(false) + ? await project.ContainsSymbolsWithNameAsync(query.Name!, cancellationToken).ConfigureAwait(false) : await project.ContainsSymbolsWithNameAsync(query.GetPredicate(), filter, cancellationToken).ConfigureAwait(false); if (!containsSymbol) return; - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var symbols = isExactNameSearch - ? compilation.GetSymbolsWithName(query.Name, filter, cancellationToken) + ? compilation.GetSymbolsWithName(query.Name!, filter, cancellationToken) : compilation.GetSymbolsWithName(query.GetPredicate(), filter, cancellationToken); var symbolsWithName = symbols.ToImmutableArray(); @@ -105,7 +103,10 @@ private static async Task AddMetadataDeclarationsWithNormalQueryAsync( if (referenceOpt != null) { var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync( - project.Solution, referenceOpt, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false); + project.Solution, referenceOpt, loadOnly: false, cancellationToken).ConfigureAwait(false); + + // We must have an index since we passed in loadOnly: false here. + Contract.ThrowIfNull(info); var symbols = await info.FindAsync( query, assembly, filter, cancellationToken).ConfigureAwait(false); diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs index bf39ca7e27b2d..542c7f6693198 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.PatternMatching; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; +using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindSymbols @@ -179,9 +180,8 @@ internal static async Task> FindSourceDeclarationsWithNo using var query = SearchQuery.Create(name, ignoreCase); var result = ArrayBuilder.GetInstance(); - foreach (var projectId in solution.ProjectIds) + foreach (var project in solution.Projects) { - var project = solution.GetProject(projectId); await AddCompilationDeclarationsWithNormalQueryAsync( project, query, criteria, result, cancellationToken).ConfigureAwait(false); } @@ -192,13 +192,13 @@ await AddCompilationDeclarationsWithNormalQueryAsync( internal static async Task> FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync( Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken) { - var list = ArrayBuilder.GetInstance(); - + using var _ = ArrayBuilder.GetInstance(out var result); using var query = SearchQuery.Create(name, ignoreCase); await AddCompilationDeclarationsWithNormalQueryAsync( - project, query, filter, list, cancellationToken).ConfigureAwait(false); - return list.ToImmutableAndFree(); + project, query, filter, result, cancellationToken).ConfigureAwait(false); + + return result.ToImmutable(); } private static async Task> FindSourceDeclarationsWithPatternInCurrentProcessAsync( From edc55accb156e680b31688267a9d5cf7be74ae1c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:44:42 -0700 Subject: [PATCH 30/35] NRT enable code --- .../Declarations/DeclarationFinder_SourceDeclarations.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs index 542c7f6693198..8ccc648c416ab 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_SourceDeclarations.cs @@ -179,14 +179,14 @@ internal static async Task> FindSourceDeclarationsWithNo { using var query = SearchQuery.Create(name, ignoreCase); - var result = ArrayBuilder.GetInstance(); + using var _ = ArrayBuilder.GetInstance(out var result); foreach (var project in solution.Projects) { await AddCompilationDeclarationsWithNormalQueryAsync( project, query, criteria, result, cancellationToken).ConfigureAwait(false); } - return result.ToImmutableAndFree(); + return result.ToImmutable(); } internal static async Task> FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync( From 9c85aff2b2f43f9a396efd01f07fea37007daf86 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:47:42 -0700 Subject: [PATCH 31/35] NRT enable code --- .../Declarations/DeclarationFinder.cs | 15 +++++++----- .../DeclarationFinder_AllDeclarations.cs | 24 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs index f8e232f60a3c8..a984cd82e69fb 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs @@ -90,8 +90,12 @@ private static async Task AddCompilationDeclarationsWithNormalQueryAsync( } private static async Task AddMetadataDeclarationsWithNormalQueryAsync( - Project project, IAssemblySymbol assembly, PortableExecutableReference referenceOpt, - SearchQuery query, SymbolFilter filter, ArrayBuilder list, + Project project, + IAssemblySymbol assembly, + PortableExecutableReference? reference, + SearchQuery query, + SymbolFilter filter, + ArrayBuilder list, CancellationToken cancellationToken) { // All entrypoints to this function are Find functions that are only searching @@ -100,16 +104,15 @@ private static async Task AddMetadataDeclarationsWithNormalQueryAsync( using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken)) { - if (referenceOpt != null) + if (reference != null) { var info = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync( - project.Solution, referenceOpt, loadOnly: false, cancellationToken).ConfigureAwait(false); + project.Solution, reference, loadOnly: false, cancellationToken).ConfigureAwait(false); // We must have an index since we passed in loadOnly: false here. Contract.ThrowIfNull(info); - var symbols = await info.FindAsync( - query, assembly, filter, cancellationToken).ConfigureAwait(false); + var symbols = await info.FindAsync(query, assembly, filter, cancellationToken).ConfigureAwait(false); list.AddRange(symbols); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs index c3dce2134a243..1bc58ccfabdb6 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -63,15 +61,16 @@ public static async Task> FindAllDeclarationsWithNormalQ internal static async Task> FindAllDeclarationsWithNormalQueryInCurrentProcessAsync( Project project, SearchQuery query, SymbolFilter criteria, CancellationToken cancellationToken) { - var list = ArrayBuilder.GetInstance(); + using var _1 = ArrayBuilder.GetInstance(out var buffer); + using var _2 = ArrayBuilder.GetInstance(out var result); if (project.SupportsCompilation) { - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); // get declarations from the compilation's assembly await AddCompilationDeclarationsWithNormalQueryAsync( - project, query, criteria, list, cancellationToken).ConfigureAwait(false); + project, query, criteria, buffer, cancellationToken).ConfigureAwait(false); // get declarations from directly referenced projects and metadata foreach (var assembly in compilation.GetReferencedAssemblySymbols()) @@ -80,30 +79,33 @@ await AddCompilationDeclarationsWithNormalQueryAsync( if (assemblyProject != null) { await AddCompilationDeclarationsWithNormalQueryAsync( - assemblyProject, query, criteria, list, + assemblyProject, query, criteria, buffer, compilation, assembly, cancellationToken).ConfigureAwait(false); } else { await AddMetadataDeclarationsWithNormalQueryAsync( project, assembly, compilation.GetMetadataReference(assembly) as PortableExecutableReference, - query, criteria, list, cancellationToken).ConfigureAwait(false); + query, criteria, buffer, cancellationToken).ConfigureAwait(false); } } // Make certain all namespace symbols returned by API are from the compilation // for the passed in project. - for (var i = 0; i < list.Count; i++) + foreach (var symbol in buffer) { - var symbol = list[i]; if (symbol is INamespaceSymbol ns) { - list[i] = compilation.GetCompilationNamespace(ns); + result.AddIfNotNull(compilation.GetCompilationNamespace(ns)); + } + else + { + result.Add(symbol); } } } - return list.ToImmutableAndFree(); + return result.ToImmutable(); } private static async Task> RehydrateAsync( From 726a73a6dcd071fdf19dd2c8e67690b2683c628e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:51:16 -0700 Subject: [PATCH 32/35] NRT enable code --- .../Declarations/DeclarationFinder_AllDeclarations.cs | 7 ++----- .../Portable/FindSymbols/IRemoteSymbolFinderService.cs | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs index 1bc58ccfabdb6..896b7613e04a1 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs @@ -27,14 +27,11 @@ public static async Task> FindAllDeclarationsWithNormalQ Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); if (project == null) - { throw new ArgumentNullException(nameof(project)); - } - if (query.Name != null && string.IsNullOrWhiteSpace(query.Name)) - { + Contract.ThrowIfNull(query.Name); + if (string.IsNullOrWhiteSpace(query.Name)) return ImmutableArray.Empty; - } var client = await RemoteHostClient.TryGetClientAsync(project, cancellationToken).ConfigureAwait(false); if (client != null) diff --git a/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinderService.cs b/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinderService.cs index 3c2dd216c7f5e..4a9eac28592b0 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinderService.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinderService.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Immutable; using System.Threading; From 78a4d3006ea3bcf38c8b23c778384b070d3592bf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 11:53:56 -0700 Subject: [PATCH 33/35] NRT enable code --- .../Portable/FindSymbols/ReferenceLocationExtensions.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocationExtensions.cs b/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocationExtensions.cs index be877c762a146..15ca8fee89438 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocationExtensions.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/ReferenceLocationExtensions.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -30,12 +28,12 @@ public static async Task>> FindReferencingSym var project = projectGroup.Key; if (project.SupportsCompilation) { - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); foreach (var documentGroup in projectGroup) { var document = documentGroup.Key; - var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); + var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); AddSymbols(semanticModel, documentGroup, result); } @@ -68,7 +66,7 @@ private static void AddSymbols( } } - private static ISymbol GetEnclosingMethodOrPropertyOrField( + private static ISymbol? GetEnclosingMethodOrPropertyOrField( SemanticModel semanticModel, ReferenceLocation reference) { From 66f6e8bdf47c204edfd43c3f726636bb3566ffba Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 12:00:01 -0700 Subject: [PATCH 34/35] NRT enable code --- .../FindReferences/FindReferenceCache.cs | 42 +++++++------------ .../FindReferencesSearchEngine.cs | 2 +- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs index 307e6066438da..a274ce2d39a58 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferenceCache.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -36,19 +34,15 @@ public static SymbolInfo GetSymbolInfo(SemanticModel model, SyntaxNode node, Can return nodeCache.GetOrAdd(node, static (n, arg) => arg.model.GetSymbolInfo(n, arg.cancellationToken), (model, cancellationToken)); } - public static IAliasSymbol GetAliasInfo( + public static IAliasSymbol? GetAliasInfo( ISemanticFactsService semanticFacts, SemanticModel model, SyntaxToken token, CancellationToken cancellationToken) { if (semanticFacts == null) - { - return model.GetAliasInfo(token.Parent, cancellationToken); - } + return model.GetAliasInfo(token.GetRequiredParent(), cancellationToken); var entry = GetCachedEntry(model); if (entry == null) - { - return model.GetAliasInfo(token.Parent, cancellationToken); - } + return model.GetAliasInfo(token.GetRequiredParent(), cancellationToken); if (entry.AliasNameSet == null) { @@ -57,9 +51,7 @@ public static IAliasSymbol GetAliasInfo( } if (entry.AliasNameSet.Contains(token.ValueText)) - { - return model.GetAliasInfo(token.Parent, cancellationToken); - } + return model.GetAliasInfo(token.GetRequiredParent(), cancellationToken); return null; } @@ -68,7 +60,7 @@ public static ImmutableArray GetIdentifierOrGlobalNamespaceTokensWi ISyntaxFactsService syntaxFacts, SemanticModel model, SyntaxNode root, - SourceText sourceText, + SourceText? sourceText, string text, CancellationToken cancellationToken) { @@ -76,9 +68,7 @@ public static ImmutableArray GetIdentifierOrGlobalNamespaceTokensWi var entry = GetCachedEntry(model); if (entry == null) - { return GetIdentifierOrGlobalNamespaceTokensWithText(syntaxFacts, root, sourceText, normalized, cancellationToken); - } return entry.IdentifierCache.GetOrAdd(normalized, key => GetIdentifierOrGlobalNamespaceTokensWithText( @@ -87,8 +77,11 @@ public static ImmutableArray GetIdentifierOrGlobalNamespaceTokensWi [PerformanceSensitive("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1224834", AllowCaptures = false)] private static ImmutableArray GetIdentifierOrGlobalNamespaceTokensWithText( - ISyntaxFactsService syntaxFacts, SyntaxNode root, SourceText sourceText, - string text, CancellationToken cancellationToken) + ISyntaxFactsService syntaxFacts, + SyntaxNode root, + SourceText? sourceText, + string text, + CancellationToken cancellationToken) { if (sourceText != null) { @@ -182,18 +175,13 @@ private static List GetConstructorInitializerTokens( return initializers; } - private static ConcurrentDictionary GetNodeCache(SemanticModel model) + private static ConcurrentDictionary? GetNodeCache(SemanticModel model) { var entry = GetCachedEntry(model); - if (entry == null) - { - return null; - } - - return entry.SymbolInfoCache; + return entry?.SymbolInfoCache; } - private static Entry GetCachedEntry(SemanticModel model) + private static Entry? GetCachedEntry(SemanticModel model) { using (s_gate.DisposableRead()) { @@ -244,8 +232,8 @@ public static void Stop(SemanticModel model) private class Entry { public int Count; - public ImmutableHashSet AliasNameSet; - public List ConstructorInitializerCache; + public ImmutableHashSet? AliasNameSet; + public List? ConstructorInitializerCache; public readonly ConcurrentDictionary> IdentifierCache = new(); public readonly ConcurrentDictionary SymbolInfoCache = new(); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs index 6d6d06211e299..7f2084a096386 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs @@ -284,7 +284,7 @@ private async Task ProcessDocumentAsync( } finally { - FindReferenceCache.Stop(model); + FindReferenceCache.Stop(model!); await _progress.OnFindInDocumentCompletedAsync(document, cancellationToken).ConfigureAwait(false); } From e945e2e6f351e03caa57efca8824f8712bd48bc0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Jun 2022 15:05:48 -0700 Subject: [PATCH 35/35] Fix for generated docs --- .../SymbolFinder.FindReferencesServerCallback.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs index 1feb74ace7c1d..1c26f07869644 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs @@ -49,16 +49,16 @@ public ValueTask OnStartedAsync(CancellationToken cancellationToken) public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => _progress.OnCompletedAsync(cancellationToken); - public ValueTask OnFindInDocumentStartedAsync(DocumentId documentId, CancellationToken cancellationToken) + public async ValueTask OnFindInDocumentStartedAsync(DocumentId documentId, CancellationToken cancellationToken) { - var document = _solution.GetRequiredDocument(documentId); - return _progress.OnFindInDocumentStartedAsync(document, cancellationToken); + var document = await _solution.GetRequiredDocumentAsync(documentId, includeSourceGenerated: true, cancellationToken).ConfigureAwait(false); + await _progress.OnFindInDocumentStartedAsync(document, cancellationToken).ConfigureAwait(false); } - public ValueTask OnFindInDocumentCompletedAsync(DocumentId documentId, CancellationToken cancellationToken) + public async ValueTask OnFindInDocumentCompletedAsync(DocumentId documentId, CancellationToken cancellationToken) { - var document = _solution.GetRequiredDocument(documentId); - return _progress.OnFindInDocumentCompletedAsync(document, cancellationToken); + var document = await _solution.GetRequiredDocumentAsync(documentId, includeSourceGenerated: true, cancellationToken).ConfigureAwait(false); + await _progress.OnFindInDocumentCompletedAsync(document, cancellationToken).ConfigureAwait(false); } public async ValueTask OnDefinitionFoundAsync(SerializableSymbolGroup dehydrated, CancellationToken cancellationToken)