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

Adds 💡 Implement Using Copilot for NotImplementedException #77299

Open
wants to merge 120 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
b6b952a
wip
akhera99 Nov 26, 2024
5ed5ee7
wip
akhera99 Nov 27, 2024
f416e98
wip
akhera99 Nov 27, 2024
38fa91a
wip
akhera99 Nov 27, 2024
1f6a30f
wip
akhera99 Nov 29, 2024
6de1307
wip
akhera99 Nov 29, 2024
ed36e8f
wip
akhera99 Nov 29, 2024
9fd8f89
remove some commented out code
akhera99 Dec 3, 2024
36a8305
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 Jan 6, 2025
9c33d32
still cleaning up
akhera99 Jan 7, 2025
f2ec7f1
revert file
akhera99 Jan 7, 2025
0f8e4f3
clean up + option
akhera99 Jan 9, 2025
c096031
wip
akhera99 Jan 21, 2025
f46e751
dispose of disable of intellicode line completions
akhera99 Jan 27, 2025
0676f73
comments
akhera99 Jan 27, 2025
c028cc9
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 Jan 27, 2025
5ffb800
comments
akhera99 Jan 27, 2025
30c4aaf
add quota exceeded checks
akhera99 Jan 27, 2025
1f93a1f
fix tests
akhera99 Jan 28, 2025
8f64473
revert file
akhera99 Jan 28, 2025
2e2f6f0
remove unused optional params
akhera99 Jan 28, 2025
77a3f0c
last few fixes
akhera99 Jan 30, 2025
ae0ffe6
feedback
akhera99 Feb 4, 2025
ce330fe
fix tests
akhera99 Feb 4, 2025
ed65b3b
small fix
akhera99 Feb 4, 2025
73e3e8e
Merge branch 'main' into dev/ankitakhera/aai_doc_comments
akhera99 Feb 7, 2025
c756a4a
fix
akhera99 Feb 7, 2025
5fef68f
feedback
akhera99 Feb 7, 2025
dde66ab
feedback
akhera99 Feb 7, 2025
4e8f752
removed per comments
akhera99 Feb 11, 2025
b6688d6
remove unused usings
akhera99 Feb 11, 2025
ab35eeb
Fixer/Analyzer for implementing method
maryamariyan Feb 11, 2025
5decd9b
feedback
akhera99 Feb 12, 2025
daff7a1
feedback
akhera99 Feb 12, 2025
4dc63b8
move stuff around with new EA structure in roslyn
akhera99 Feb 13, 2025
96bd8e2
wip
akhera99 Feb 13, 2025
906aed9
feedback
akhera99 Feb 13, 2025
61acead
feedbacl
akhera99 Feb 15, 2025
ae609fa
fix
akhera99 Feb 15, 2025
423a6df
feedback
akhera99 Feb 15, 2025
7683098
feedback
akhera99 Feb 18, 2025
ec34831
feedback
akhera99 Feb 18, 2025
b6b8e8c
revert
akhera99 Feb 18, 2025
dbff122
remove null check
akhera99 Feb 18, 2025
41be07f
clean up
akhera99 Feb 18, 2025
a63b731
fix
akhera99 Feb 19, 2025
835c7ec
Merge remote-tracking branch 'origin/main' into dev/maryamariyan/dev1…
maryamariyan Feb 19, 2025
faea3a8
fix tests
akhera99 Feb 19, 2025
3851626
Merge remote-tracking branch 'origin/main' into dev/ankitakhera/aai_d…
maryamariyan Feb 19, 2025
b98a886
local ad ons
maryamariyan Feb 20, 2025
7b6d468
local ad ons
maryamariyan Feb 20, 2025
6d46c43
Merge branch 'dev/maryamariyan/dev17-implement-method-fixer' into dev…
maryamariyan Feb 20, 2025
2c62d7b
Add main bits for generating method implementation
maryamariyan Feb 20, 2025
c49fdcc
todo next
maryamariyan Feb 20, 2025
ee3b104
update APIs
maryamariyan Feb 20, 2025
bdcfbf4
trial 1
maryamariyan Feb 21, 2025
9db6634
Merge remote-tracking branch 'origin/main' into dev/maryamariyan/repl…
maryamariyan Feb 21, 2025
7431087
Fix compile after merge
maryamariyan Feb 21, 2025
e6153f0
temp1
maryamariyan Feb 22, 2025
b2c0584
temp2
maryamariyan Feb 22, 2025
e1e6fd3
Implement method, end-to-end for one-off code action
maryamariyan Feb 22, 2025
ba32b2b
corrections
maryamariyan Feb 22, 2025
e6c9ef2
cleanup
maryamariyan Feb 24, 2025
d595c6a
cleanup preliminary check
maryamariyan Feb 24, 2025
86e8bf9
Fix bug
maryamariyan Feb 24, 2025
d993617
cleanup and fixes
maryamariyan Feb 25, 2025
3360777
remove local changes for pr
maryamariyan Feb 25, 2025
de14ec1
correct spacing
maryamariyan Feb 25, 2025
56b16f9
cleanup
maryamariyan Feb 25, 2025
8c89fee
Add unit test - takes code block suggestion to replace with method body
maryamariyan Feb 25, 2025
5150992
Add test, support expression body clause later
maryamariyan Feb 25, 2025
47c913c
Change the FAR API call
maryamariyan Feb 25, 2025
b8f70c6
using `.Parent.FirstAncestorOrSelf`
maryamariyan Feb 25, 2025
b02349f
Improve wrapper implementation
maryamariyan Feb 25, 2025
ba4b470
Apply first round code review
maryamariyan Feb 26, 2025
688b3ea
Merge DualChangeAction into DocumentChangeAction
sharwell Feb 28, 2025
42b8763
Make IDE3000 not configurable
sharwell Feb 28, 2025
998a3d8
Simplify analyzer code and improve robustness
sharwell Feb 28, 2025
0aa9356
Simplifies fixer and applies most remaining feedback
maryamariyan Mar 1, 2025
f5116f2
Merge remote-tracking branch 'maryam/dev/maryamariyan/replicate-for-f…
maryamariyan Mar 1, 2025
1c9ba44
Fix compile related to DocumentChangeAction
maryamariyan Mar 1, 2025
2ed4649
Cleanup messaging
maryamariyan Mar 1, 2025
24f76b2
Add resources for messaging
maryamariyan Mar 1, 2025
744eb42
Adds a few basic tests
maryamariyan Mar 1, 2025
b077c3f
Merge remote-tracking branch 'origin/main' into dev/maryamariyan/repl…
maryamariyan Mar 2, 2025
70209d7
Undo most recent analyzer changes,
maryamariyan Mar 2, 2025
ffd9bce
Apply PR feedback
maryamariyan Mar 2, 2025
e8596bc
Tests renamed
maryamariyan Mar 2, 2025
1923930
Correct test setup
maryamariyan Mar 2, 2025
0cc13f3
Improves readability and removes unreachable code
maryamariyan Mar 3, 2025
fbcd111
Correct mistakes in tests
maryamariyan Mar 3, 2025
41a421f
Adds more unit tests
maryamariyan Mar 3, 2025
9222c16
Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-…
maryamariyan Mar 3, 2025
1452aa0
Fixes Analyzer tests
maryamariyan Mar 3, 2025
6fb4938
Makes sure original and replacement text are properly aligned
maryamariyan Mar 3, 2025
c270a76
Apply partial PR feedback
maryamariyan Mar 3, 2025
061d448
cleanup
maryamariyan Mar 3, 2025
faa4722
Applies feedback to change API surface
maryamariyan Mar 4, 2025
f48bf92
All tests pass
maryamariyan Mar 4, 2025
af8ca36
tests are actually failing
maryamariyan Mar 4, 2025
770fc86
Fix Quota bug and show failing tests
maryamariyan Mar 4, 2025
6d20484
Update tests for error conditions where diagnostics are not corrected
sharwell Mar 4, 2025
2b7487a
undo IsImplementNotImplementedExceptionEnabledAsync change
maryamariyan Mar 5, 2025
8b53fe0
Fixes remaining tests
maryamariyan Mar 5, 2025
dbc3919
cleanup
maryamariyan Mar 5, 2025
3e3bd88
Add back referencedSymbols to API call to help with perf
maryamariyan Mar 5, 2025
16d2481
Gracefully comment when result is unexpected
maryamariyan Mar 5, 2025
3b0ba9a
Remove unused resource
maryamariyan Mar 5, 2025
b20b2cb
Simplify error messages
maryamariyan Mar 5, 2025
384ce72
Cleanup tests
maryamariyan Mar 5, 2025
79bebb1
Add missing entry for IDE3000
maryamariyan Mar 5, 2025
517d977
Add Missing Help Link
maryamariyan Mar 5, 2025
8aaa595
mid stage
maryamariyan Mar 6, 2025
9eb2e7c
Removes QuotaExceeds property, received as message
maryamariyan Mar 6, 2025
d088c36
Update signature
maryamariyan Mar 6, 2025
7127ff7
Merge remote-tracking branch 'origin/main' into dev/maryamariyan/repl…
maryamariyan Mar 6, 2025
2f934a6
Fix missed out warning
maryamariyan Mar 6, 2025
4eecdc6
Fix test correctness issue picked up by CI
maryamariyan Mar 6, 2025
44a65e1
Add logging
maryamariyan Mar 6, 2025
960a9cd
Apply PR feedback
maryamariyan Mar 7, 2025
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
1 change: 1 addition & 0 deletions src/Analyzers/CSharp/Analyzers/CSharpAnalyzers.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ConvertProgram\ConvertProgramAnalysis_ProgramMain.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConvertProgram\ConvertToTopLevelStatementsDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConvertTypeofToNameof\CSharpConvertTypeOfToNameOfDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Copilot\CSharpImplementNotImplementedExceptionDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ForEachCast\CSharpForEachCastDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Formatting\CSharpFormattingAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MakeAnonymousFunctionStatic\MakeAnonymousFunctionStaticDiagnosticAnalyzer.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@
<data name="Use_unbound_generic_type" xml:space="preserve">
<value>Use unbound generic type</value>
</data>
<data name="Implement_with_Copilot" xml:space="preserve">
<value>Implement with Copilot</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;

namespace Microsoft.CodeAnalysis.CSharp.Copilot;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal sealed class CSharpImplementNotImplementedExceptionDiagnosticAnalyzer()
: AbstractBuiltInCodeStyleDiagnosticAnalyzer(
IDEDiagnosticIds.CopilotImplementNotImplementedExceptionDiagnosticId,
EnforceOnBuildValues.CopilotImplementNotImplementedException,
option: null,
new LocalizableResourceString(
nameof(CSharpAnalyzersResources.Implement_with_Copilot), CSharpAnalyzersResources.ResourceManager, typeof(CSharpAnalyzersResources)),
configurable: false)
{
public override DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticSpanAnalysis;

protected override void InitializeWorker(AnalysisContext context)
{
context.RegisterCompilationStartAction(context =>
{
var fullName = typeof(NotImplementedException).FullName;
Contract.ThrowIfNull(fullName);
var notImplementedExceptionType = context.Compilation.GetTypeByMetadataName(fullName);
if (notImplementedExceptionType != null)
context.RegisterOperationAction(context => AnalyzeThrow(context, notImplementedExceptionType), OperationKind.Throw);
});
}

private void AnalyzeThrow(OperationAnalysisContext context, INamedTypeSymbol notImplementedExceptionType)
{
var throwOperation = (IThrowOperation)context.Operation;
if (throwOperation is
{
Exception: IConversionOperation
{
Operand: IObjectCreationOperation
{
Constructor.ContainingType: INamedTypeSymbol constructedType,
},
},
Syntax: ThrowExpressionSyntax or ThrowStatementSyntax,
} &&
notImplementedExceptionType.Equals(constructedType))
{
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
throwOperation.Syntax.GetLocation()));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Compile Include="$(MSBuildThisFileDirectory)AliasAmbiguousType\AliasAmbiguousTypeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AssignOutParameters\AssignOutParametersAboveReturnTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AssignOutParameters\AssignOutParametersAtStartTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Copilot\CSharpImplementNotImplementedExceptionDiagnosticAnalyzerTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DocumentationComments\AddDocCommentNodesCodeFixProviderTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DocumentationComments\RemoveDocCommentNodeCodeFixProviderTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConditionalExpressionInStringInterpolation\CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs" />
Expand Down Expand Up @@ -202,6 +203,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)AbstractBuiltInCodeStyleDiagnosticAnalyzer\" />
<Folder Include="$(MSBuildThisFileDirectory)Copilot\" />
<Folder Include="$(MSBuildThisFileDirectory)UseImplicitlyTypedLambdaExpression\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Testing;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.Copilot.UnitTests;

using VerifyCS = CSharpCodeFixVerifier<
CSharpImplementNotImplementedExceptionDiagnosticAnalyzer,
EmptyCodeFixProvider>;

public class CSharpImplementNotImplementedExceptionDiagnosticAnalyzerTests
{
[Fact]
public async Task TestThrowNotImplementedExceptionInStatement()
{
var testCode = """
using System;

class C
{
void M()
{
{|IDE3000:throw new NotImplementedException();|}
}
}
""";

await new VerifyCS.Test
{
TestCode = testCode,
LanguageVersion = LanguageVersion.CSharp11,
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
}.RunAsync();
}

[Fact]
public async Task TestThrowNotImplementedExceptionInExpression()
{
var testCode = """
using System;

class C
{
int P => {|IDE3000:throw new NotImplementedException()|};
}
""";

await new VerifyCS.Test
{
TestCode = testCode,
LanguageVersion = LanguageVersion.CSharp11,
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
}.RunAsync();
}

[Fact]
public async Task TestDifferentFlavorsOfThrowNotImplementedException()
{
var testCode = """
using System;

class C
{
void M1()
{
{|IDE3000:throw new NotImplementedException("Not implemented");|}
}

void M2()
{
{|IDE3000:throw new NotImplementedException("Not implemented");|}
}

void M3()
{
try
{
// Some code
}
catch (Exception)
{
{|IDE3000:throw new NotImplementedException();|}
}
}

int P1
{
get { {|IDE3000:throw new NotImplementedException();|} }
}

int P2
{
get { {|IDE3000:throw new NotImplementedException();|} }
set { {|IDE3000:throw new NotImplementedException();|} }
}

int this[int index]
{
get { {|IDE3000:throw new NotImplementedException();|} }
set { {|IDE3000:throw new NotImplementedException();|} }
}

void M4()
{
Action action = () => {|IDE3000:throw new NotImplementedException()|};
action();
}

void M5()
{
Func<int> func = () => {|IDE3000:throw new NotImplementedException()|};
func();
}

void M6()
{
{|IDE3000:throw new NotImplementedException();|}
}

void M7()
{
{|IDE3000:throw new NotImplementedException("Not implemented");|}
}
}
""";

await new VerifyCS.Test
{
TestCode = testCode,
LanguageVersion = LanguageVersion.CSharp11,
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
}.RunAsync();
}
}
1 change: 1 addition & 0 deletions src/Analyzers/Core/Analyzers/EnforceOnBuildValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ internal static class EnforceOnBuildValues
public const EnforceOnBuild ConvertAnonymousTypeToTuple = /*IDE0050*/ EnforceOnBuild.Never;
public const EnforceOnBuild RemoveUnreachableCode = /*IDE0035*/ EnforceOnBuild.Never; // Non-configurable fading diagnostic corresponding to CS0162.
public const EnforceOnBuild RemoveUnnecessarySuppression = /*IDE0079*/ EnforceOnBuild.Never; // IDE-only analyzer.
public const EnforceOnBuild CopilotImplementNotImplementedException = /*IDE3000*/ EnforceOnBuild.Never; // IDE-only analyzer.

// Pure IDE feature for lighting up editor features. Do not enforce on build.
public const EnforceOnBuild DetectProbableJsonStrings = /*JSON002*/ EnforceOnBuild.Never;
Expand Down
Loading
Loading