Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -410,71 +410,6 @@ public interface IDataService
.RunAsync();
}

[Fact]
public async Task HandleInvalidCode_SuggestsAsComment()
{
await new CustomCompositionCSharpTest
{
CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne,
TestCode = """
using System;

class C
{
void M()
{
{|IDE3000:throw new NotImplementedException();|}
}
}
""",
FixedCode = """
using System;

class C
{
/* The generated implementation isn't a valid method or property:
using System;
class C
{
void M()
{
throw new NotImplementedException();
}
} */
void M()
{
{|IDE3000:throw new NotImplementedException();|}
}
}
""",
FixedState =
{
MarkupHandling = MarkupMode.Allow,
},
LanguageVersion = LanguageVersion.CSharp11,
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
}
.WithMockCopilotService(copilotService =>
{
var replacement = """
using System;
class C
{
void M()
{
throw new NotImplementedException();
}
}
""";
copilotService.PrepareUsingSingleFakeResult = new()
{
ReplacementNode = SyntaxFactory.ParseCompilationUnit(replacement),
Message = $"The generated implementation isn't a valid method or property:{Environment.NewLine}{replacement}",
};
})
.RunAsync();
}

[Fact]
public async Task ReplacementNode_Null_NotifiesWithComment()
{
Expand Down
6 changes: 4 additions & 2 deletions src/Features/Core/Portable/Copilot/ImplementationDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.CSharp.Syntax;
Copy link
Member

Choose a reason for hiding this comment

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

this is not ok. you are referencing C# specific code in a common library. Note: i'm actually surrpised this compiled.


namespace Microsoft.CodeAnalysis.Copilot;

/// <summary>
Expand All @@ -16,7 +18,7 @@ internal sealed class ImplementationDetails
public string? Message { get; init; }

/// <summary>
/// Gets the replacement syntax node. Either this property or <see cref="Message"/> must be set.
/// Gets the replacement node. Either this property or <see cref="Message"/> must be set.
/// </summary>
public SyntaxNode? ReplacementNode { get; init; }
public MemberDeclarationSyntax? ReplacementNode { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation;

/// <summary>
Expand All @@ -18,5 +20,5 @@ internal sealed class ImplementationDetailsWrapper
/// <summary>
/// Gets the replacement syntax node. Either this property or <see cref="Message"/> must be set.
/// </summary>
public SyntaxNode? ReplacementNode { get; init; }
public MemberDeclarationSyntax? ReplacementNode { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.Implementat
Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper.ImplementationDetailsWrapper() -> void
Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper.Message.get -> string?
Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper.Message.init -> void
Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper.ReplacementNode.get -> Microsoft.CodeAnalysis.SyntaxNode?
Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper.ReplacementNode.get -> Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax?
Microsoft.CodeAnalysis.ExternalAccess.Copilot.GenerateImplementation.ImplementationDetailsWrapper.ReplacementNode.init -> void
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysisService
Microsoft.CodeAnalysis.ExternalAccess.Copilot.IExternalCSharpCopilotCodeAnalysisService.AnalyzeDocumentAsync(Microsoft.CodeAnalysis.Document! document, Microsoft.CodeAnalysis.Text.TextSpan? span, string! promptTitle, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostic!>>!
Expand Down
Loading