Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layering of Implement-Interface code-fixer vs language service #74320

Merged
merged 46 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f9073e8
Work around MSBuild task ordering bug
jjonescz Jun 28, 2024
2e4c254
Merge branch 'main' into vs-signing
CyrusNajmabadi Jul 9, 2024
787b1f8
Merge branch 'main' into vs-signing
CyrusNajmabadi Jul 9, 2024
e274a3d
Merge branch 'main' into vs-signing
jjonescz Jul 9, 2024
1f4d6a0
Merge branch 'vs-signing' of https://github.com/jjonescz/roslyn into …
CyrusNajmabadi Jul 9, 2024
279dd0c
In progress
CyrusNajmabadi Jul 9, 2024
bbec959
Renames
CyrusNajmabadi Jul 9, 2024
102e366
Move off of code action itself
CyrusNajmabadi Jul 9, 2024
deb025c
In progress
CyrusNajmabadi Jul 9, 2024
3e0a770
In progress
CyrusNajmabadi Jul 9, 2024
ee1ef9e
Fix equivalence key
CyrusNajmabadi Jul 9, 2024
ff718d1
Merge remote-tracking branch 'upstream/main' into implInterfaceSharing3
CyrusNajmabadi Jul 10, 2024
a0ad07d
Common base type
CyrusNajmabadi Jul 10, 2024
e7a3db5
Common base type
CyrusNajmabadi Jul 10, 2024
038009c
Make sealed
CyrusNajmabadi Jul 10, 2024
2164964
Rename files
CyrusNajmabadi Jul 10, 2024
d4d88ba
Move helpers to common location
CyrusNajmabadi Jul 10, 2024
45cbfdd
Simplify
CyrusNajmabadi Jul 10, 2024
c14bf6e
NRT
CyrusNajmabadi Jul 10, 2024
e23d665
IN progress
CyrusNajmabadi Jul 10, 2024
e15f39d
IN progress
CyrusNajmabadi Jul 10, 2024
64c474d
IN progress
CyrusNajmabadi Jul 10, 2024
8af38d4
IN progress
CyrusNajmabadi Jul 10, 2024
da8f7f5
IN progress
CyrusNajmabadi Jul 10, 2024
de3838a
IN progress
CyrusNajmabadi Jul 10, 2024
6d8f4d4
IN progress
CyrusNajmabadi Jul 10, 2024
e7f1586
IN progress
CyrusNajmabadi Jul 10, 2024
d4a6f32
IN progress
CyrusNajmabadi Jul 10, 2024
69a11df
Remove api
CyrusNajmabadi Jul 10, 2024
b839dfb
Braces
CyrusNajmabadi Jul 10, 2024
16f60a0
Fixes
CyrusNajmabadi Jul 10, 2024
8b342f9
Cleanup
CyrusNajmabadi Jul 10, 2024
f1d3cc4
Move type
CyrusNajmabadi Jul 10, 2024
a79bb1d
No separate subclass
CyrusNajmabadi Jul 10, 2024
2ed84a5
Simplify
CyrusNajmabadi Jul 10, 2024
e3e9412
Rename
CyrusNajmabadi Jul 10, 2024
af5195b
Simplify
CyrusNajmabadi Jul 10, 2024
74e9e55
less state passing
CyrusNajmabadi Jul 10, 2024
9a4d5b0
simplify
CyrusNajmabadi Jul 10, 2024
5b1664a
rename
CyrusNajmabadi Jul 10, 2024
bbcd00d
inline
CyrusNajmabadi Jul 10, 2024
a25ceee
Rename
CyrusNajmabadi Jul 10, 2024
f301bcd
Update eng/targets/Settings.props
CyrusNajmabadi Jul 10, 2024
61eedd3
Merge branch 'main' into implInterfaceSharing3
CyrusNajmabadi Jul 11, 2024
799974c
renames
CyrusNajmabadi Jul 11, 2024
7f84691
Cleanup
CyrusNajmabadi Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
}
}

private IEnumerable<IImplementInterfaceGenerator> GetGenerators(
private async IEnumerable<IImplementInterfaceGenerator> GetGenerators(
Document document, ImplementTypeGenerationOptions options, IImplementInterfaceInfo? state, CancellationToken cancellationToken)
{
if (state == null)
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
{
yield break;
}

var compilation = await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false);

if (state.MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented.Length > 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same logic that used to make all the code actions. now it makes the 'options' at the service layer for what possible ways there are to implement. the code action will then pass this options object to the service layer to do the actual impl.

{
var totalMemberCount = 0;
Expand All @@ -92,7 +94,7 @@ private IEnumerable<IImplementInterfaceGenerator> GetGenerators(
yield return ImplementInterfaceGenerator.CreateImplement(this, document, options, state);
}

if (ShouldImplementDisposePattern(state, explicitly: false))
if (ShouldImplementDisposePattern(compilation, state, explicitly: false))
{
yield return ImplementInterfaceWithDisposePatternGenerator.CreateImplementWithDisposePattern(this, document, options, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
Expand All @@ -20,6 +21,10 @@ internal interface IImplementInterfaceGenerator
internal interface IImplementInterfaceInfo
{
INamedTypeSymbol ClassOrStructType { get; }

ImmutableArray<(INamedTypeSymbol type, ImmutableArray<ISymbol> members)> MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented { get; }
ImmutableArray<(INamedTypeSymbol type, ImmutableArray<ISymbol> members)> MembersWithoutExplicitOrImplicitImplementation { get; }
ImmutableArray<(INamedTypeSymbol type, ImmutableArray<ISymbol> members)> MembersWithoutExplicitImplementation { get; }
}

internal readonly struct ImplementInterfaceOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ private static bool IsTypeLessAccessibleThanOtherType(ITypeSymbol? first, INamed
return false;
}

private static bool ShouldImplementDisposePattern(Compilation compilation, IImplementInterfaceInfo state, bool explicitly)
public static bool ShouldImplementDisposePattern(Compilation compilation, IImplementInterfaceInfo state, bool explicitly)
{
// Dispose pattern should be implemented only if -
// 1. An interface named 'System.IDisposable' is unimplemented.
// 2. This interface has one and only one member - a non-generic method named 'Dispose' that takes no arguments and returns 'void'.
// 3. The implementing type is a class that does not already declare any conflicting members named 'disposedValue' or 'Dispose'
// (because we will be generating a 'disposedValue' field and a couple of methods named 'Dispose' as part of implementing
// the dispose pattern).
// 3. The implementing type is a class that does not already declare any conflicting members named
// 'disposedValue' or 'Dispose' (because we will be generating a 'disposedValue' field and a couple of
// methods named 'Dispose' as part of implementing the dispose pattern).
if (state.ClassOrStructType.TypeKind != TypeKind.Class)
return false;

Expand Down