-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Adding new EA api at 'Features' layer for unit testing ot use #78175
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // 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.Generic; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.CodeLens; | ||
|
|
||
| internal static class CodeLensHelpers | ||
| { | ||
| public static DocumentId? GetSourceGeneratorDocumentId(IDictionary<object, object> descriptorProperties) | ||
| { | ||
| // Undocumented contract here:' | ||
| // https://devdiv.visualstudio.com/DevDiv/_git/VS?path=/src/CodeSense/Framework/Roslyn/Roslyn/Editor/CodeElementTag.cs&version=GBmain&_a=contents&line=84&lineStyle=plain&lineEnd=85&lineStartColumn=1&lineEndColumn=96 | ||
| if (TryGetGuid("RoslynDocumentIdGuid", out var documentIdGuid) && | ||
| TryGetGuid("RoslynProjectIdGuid", out var projectIdGuid)) | ||
| { | ||
| var projectId = ProjectId.CreateFromSerialized(projectIdGuid); | ||
| return DocumentId.CreateFromSerialized(projectId, documentIdGuid); | ||
| } | ||
|
|
||
| return null; | ||
|
|
||
| bool TryGetGuid(string key, out Guid guid) | ||
| { | ||
| guid = Guid.Empty; | ||
| return descriptorProperties.TryGetValue(key, out var guidStringUntyped) && | ||
| guidStringUntyped is string guidString && | ||
| Guid.TryParse(guidString, out guid); | ||
| } | ||
| } | ||
| } | ||
| 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.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.CodeLens; | ||
| using Microsoft.CodeAnalysis.Text; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting; | ||
|
|
||
| internal interface IUnitTestingCodeLensContext | ||
| { | ||
| Task<ImmutableArray<ReferenceMethodDescriptor>?> FindReferenceMethodsAsync( | ||
| Guid projectGuid, string filePath, TextSpan span, DocumentId? sourceGeneratedDocumentId, CancellationToken cancellationToken); | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nothing you need to worry about @shyamnamboodiripad This just gives us a strong api signature between this code here and the impl on the vs side. |
||
|
|
||
| internal interface IUnitTestingFeaturesReferencesServiceCallback | ||
| { | ||
| Task<TResult> InvokeAsync<TResult>(string targetName, IReadOnlyList<object?> arguments, CancellationToken cancellationToken); | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shyam you'll provide an impl of this on your side. it will be implemented as: class YourImpl(
IAsyncCodeLensDataPointProvider provider,
ICodeLensCallbackService callbackService) : IUnitTestingFeaturesReferencesServiceCallback
{
public Task<TResult> InvokeAsync<TResult>(string targetName, IReadOnlyList<object?> arguments, CancellationToken cancellationToken) => callbackService.InvokeAsync(targetName, arguments, cancellationToken);
} |
||
|
|
||
| internal static class UnitTestingFeaturesReferencesService | ||
| { | ||
| public static DocumentId? GetSourceGeneratorDocumentId(IDictionary<object, object> descriptorProperties) | ||
| => CodeLensHelpers.GetSourceGeneratorDocumentId(descriptorProperties); | ||
|
|
||
| public static async Task<ImmutableArray<(string MethodFullyQualifedName, string MethodOutputFilePath)>> GetCallerMethodsAsync( | ||
| Guid projectGuid, | ||
| string filePath, | ||
| TextSpan span, | ||
| DocumentId? sourceGeneratedDocumentId, | ||
CyrusNajmabadi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| IUnitTestingFeaturesReferencesServiceCallback callback, | ||
| CancellationToken cancellationToken) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this api is much lower than the prior Editor level api. So it doesn't talk about vs codelens concepts. It just talks about data, and just passes in an abstraction for the call to be made back to VS through the 'callback' parameter which hides all the codelens stuff as well. |
||
| { | ||
| var callerMethods = await callback.InvokeAsync<ImmutableArray<ReferenceMethodDescriptor>?>( | ||
| nameof(IUnitTestingCodeLensContext.FindReferenceMethodsAsync), | ||
| [projectGuid, filePath, span, sourceGeneratedDocumentId], | ||
| cancellationToken).ConfigureAwait(false); | ||
|
|
||
| if (!callerMethods.HasValue || callerMethods.Value.IsEmpty) | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| return callerMethods.Value.SelectAsArray(m => ( | ||
| MethodFullyQualifiedName: m.FullName, | ||
| MethodOutputFilePath: m.OutputFilePath)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved from later code. used by us, and then also exposed through EA for UnitTesting to use.