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

wip #76922

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

wip #76922

Show file tree
Hide file tree
Changes from 15 commits
Commits
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
2 changes: 1 addition & 1 deletion eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageTags>Roslyn CodeAnalysis Compiler CSharp VB VisualBasic Parser Scanner Lexer Emit CodeGeneration Metadata IL Compilation Scripting Syntax Semantics</PackageTags>
<ThirdPartyNoticesFilePath>$(MSBuildThisFileDirectory)..\..\src\NuGet\ThirdPartyNotices.rtf</ThirdPartyNoticesFilePath>

<VSSDKTargetPlatformRegRootSuffix>RoslynDev</VSSDKTargetPlatformRegRootSuffix>
<VSSDKTargetPlatformRegRootSuffix>Exp</VSSDKTargetPlatformRegRootSuffix>
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved

<!-- Workaround for old Microsoft.VisualStudio.Progression.* packages -->
<NoWarn>$(NoWarn);VSIXCompatibility1001</NoWarn>
Expand Down
4 changes: 4 additions & 0 deletions src/Analyzers/CSharp/Analyzers/CSharpAnalyzers.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ConvertTypeofToNameof\CSharpConvertTypeOfToNameOfDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ForEachCast\CSharpForEachCastDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Formatting\CSharpFormattingAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Copilot\CSharpImplementNotImplementedExceptionDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MakeAnonymousFunctionStatic\MakeAnonymousFunctionStaticDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MakeFieldReadonly\CSharpMakeFieldReadonlyDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MakeStructMemberReadOnly\CSharpMakeStructMemberReadOnlyAnalyzer.cs" />
Expand Down Expand Up @@ -165,4 +166,7 @@
<ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' AND '$(BuildingInsideVisualStudio)' != 'true'">
<ExpectedCompile Include="$(MSBuildThisFileDirectory)**\*$(DefaultLanguageSourceExtension)" />
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Copilot\" />
</ItemGroup>
</Project>
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,52 @@
// 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 ImplementNotImplementedExceptionDiagnosticAnalyzer()
: AbstractBuiltInCodeStyleDiagnosticAnalyzer(
IDEDiagnosticIds.ImplementNotImplementedExceptionDiagnosticAnalyzer,
EnforceOnBuildValues.ImplementNotImplementedException,
option: null,
new LocalizableResourceString(
nameof(CSharpAnalyzersResources.Implement_with_Copilot), CSharpAnalyzersResources.ResourceManager, typeof(CSharpAnalyzersResources)))
{
public override DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticSpanAnalysis;

protected override void InitializeWorker(AnalysisContext context)
{
context.RegisterCompilationStartAction(context =>
{
var notImplementedExceptionType = context.Compilation.GetTypeByMetadataName(typeof(NotImplementedException).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 IObjectCreationOperation
{
Constructor.ContainingType: INamedTypeSymbol constructedType,
Syntax: ThrowExpressionSyntax or ThrowStatementSyntax,
} &&
notImplementedExceptionType.Equals(constructedType))
{
context.ReportDiagnostic(Diagnostic.Create(
Descriptor,
throwOperation.Syntax.GetFirstToken().GetLocation(),
[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.

2 changes: 2 additions & 0 deletions src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ImplementAbstractClass\CSharpImplementAbstractClassCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ImplementInterface\CSharpImplementInterfaceCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ImplementInterface\CSharpImplementInterfaceService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)implementnotimplementedexceptiondiagnostic\CSharpImplementNotImplementedExceptionDiagnosticCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Iterator\CSharpAddYieldCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Iterator\CSharpChangeToIEnumerableCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MakeAnonymousFunctionStatic\CSharpMakeAnonymousFunctionStaticCodeFixProvider.cs" />
Expand Down Expand Up @@ -187,6 +188,7 @@
<ExpectedCompile Include="$(MSBuildThisFileDirectory)**\*$(DefaultLanguageSourceExtension)" />
</ItemGroup>
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)ImplementNotImplementedExceptionDiagnostic\" />
<Folder Include="$(MSBuildThisFileDirectory)SimplifyLinqExpression\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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 System.Collections.Immutable;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.CSharp.Copilot;

[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ReimplementThrowNewNotImplementedException), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed partial class CSharpImplementNotImplementedExceptionCodeFixProvider() : SyntaxEditorBasedCodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds { get; }
= [IDEDiagnosticIds.ImplementNotImplementedExceptionDiagnosticAnalyzer];

public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
RegisterCodeFix(context, CSharpAnalyzersResources.Implement_with_Copilot, nameof(CSharpAnalyzersResources.Implement_with_Copilot));
return Task.CompletedTask;
}

protected override async Task FixAllAsync(
Document document, ImmutableArray<Diagnostic> diagnostics,
SyntaxEditor editor, CancellationToken cancellationToken)
{
foreach (var diagnostic in diagnostics)
await FixOneAsync(editor, diagnostic, cancellationToken);
}

private static async Task FixOneAsync(
SyntaxEditor editor, Diagnostic diagnostic, CancellationToken cancellationToken)
{
// Find the throw statement node
var throwExpressionOrStatement = diagnostic.AdditionalLocations[0].FindNode(getInnermostNodeForTie: true, cancellationToken);

// Create a replacement node (a simple comment in this case)
var commentTrivia = SyntaxFactory.Comment("// TODO: Implement this method");
var commentStatement = SyntaxFactory.ExpressionStatement(SyntaxFactory.IdentifierName(commentTrivia.ToString()));

// Replace the throw statement with the comment
editor.ReplaceNode(throwExpressionOrStatement, commentStatement);
}
}
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 ImplementNotImplementedException = 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
3 changes: 3 additions & 0 deletions src/Analyzers/Core/Analyzers/IDEDiagnosticIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,7 @@ internal static class IDEDiagnosticIds
public const string ConstructorInitializerPlacementDiagnosticId = "IDE2004";
public const string ConditionalExpressionPlacementDiagnosticId = "IDE2005";
public const string ArrowExpressionClausePlacementDiagnosticId = "IDE2006";

// 3000 range for copilot features.
public const string CopilotImplementNotImplementedExceptionDiagnosticId = "IDE3000";
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ internal static class PredefinedCodeFixProviderNames
public const string UseTupleSwap = nameof(UseTupleSwap);
public const string UseUnboundGenericTypeInNameOf = nameof(UseUnboundGenericTypeInNameOf);
public const string UseUtf8StringLiteral = nameof(UseUtf8StringLiteral);
public const string ReimplementThrowNewNotImplementedException = nameof(ReimplementThrowNewNotImplementedException);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.DocumentationComments;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
using Microsoft.VisualStudio.Language.Suggestions;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.DocumentationComments;
Expand All @@ -25,8 +28,10 @@ internal sealed class DocumentationCommentCommandHandler(
IUIThreadOperationExecutor uiThreadOperationExecutor,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
EditorOptionsService editorOptionsService)
: AbstractDocumentationCommentCommandHandler(uiThreadOperationExecutor, undoHistoryRegistry, editorOperationsFactoryService, editorOptionsService)
EditorOptionsService editorOptionsService,
SuggestionServiceBase suggestionServiceBase,
IThreadingContext threadingContext)
: AbstractDocumentationCommentCommandHandler(uiThreadOperationExecutor, undoHistoryRegistry, editorOperationsFactoryService, editorOptionsService, suggestionServiceBase, threadingContext)
{
protected override string ExteriorTriviaText => "///";
}
Loading
Loading