Skip to content

fix visitor related issue in MethodProvider. #7682

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

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

Conversation

haiyuazhang
Copy link

The method parameter name may has been changed by the visitor, so we need to rebuild the xmlDoc for the method as well.

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jun 19, 2025
@haiyuazhang haiyuazhang force-pushed the haiyzhan/fix_in_methodProvider branch from 3493f9b to e748091 Compare June 19, 2025 07:07
@haiyuazhang haiyuazhang marked this pull request as draft June 19, 2025 08:37
@haiyuazhang haiyuazhang force-pushed the haiyzhan/fix_in_methodProvider branch from 82e7725 to d62c5c7 Compare June 19, 2025 09:34
@haiyuazhang haiyuazhang force-pushed the haiyzhan/fix_in_methodProvider branch from d62c5c7 to 2ba76bd Compare June 23, 2025 08:38
@haiyuazhang haiyuazhang marked this pull request as ready for review June 23, 2025 08:40
Copy link
Contributor

No changes needing a change description found.

@@ -20,6 +20,8 @@ public class MethodProvider

public TypeProvider EnclosingType { get; }

private bool _rebuildXmlDocsOnAccept;
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just cache xmlDocProvider?

Copy link
Contributor

Choose a reason for hiding this comment

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

XmlDocs should already be cached.

Copy link
Contributor

Choose a reason for hiding this comment

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

XmlDocs = xmlDocProvider ?? MethodProviderHelpers.BuildXmlDocs(signature);

We can't directly check XmlDocs, because it falls back to Build if the input xmlDocProvider is null, we should check the input xmlDocProvider from user, either from constructor or from update method.
if (xmlDocProvider != null)
{
XmlDocs = xmlDocProvider;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it a problem that XmlDocs falls back to BuildXmlDocs? We just care what XmlDocs is at the time when we are deciding whether to rebuild it or not. It doesn't matter what the history is.

Copy link
Contributor

Choose a reason for hiding this comment

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

As explained in #7682 (comment), we need to check if XmlDocs is null or Empty or InheritDocs, which might be the user input for it, and it might grow.
Basically, we should check if user has set it intentionally, if not we should rebuild it.
So, I think it would be easier to check if the user input is null.

@@ -100,6 +105,10 @@ public void Update(
}

Signature = updated.Signature;
if (_rebuildXmlDocsOnAccept)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should just check if XmlDocs is currently not null.

Copy link
Author

Choose a reason for hiding this comment

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

change the condition to if (XmlDocs is not null) will bring large regen diffs: see here #7709. I found to leave what the current docs in the test projects as what it is ,we should avoid rebuild docs when

  1. xmlDocProvider in constructor is not null
  2. XmlDocs is not explicitly updated by Update method (xmlDocprovider parameter is not null)

Copy link
Contributor

Choose a reason for hiding this comment

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

We should check null or XmlDocProvider.Empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

And it could be xmlDocProvider.InheritDocs, so I think we should check if the user input xmlDocProvider is not null.
If we check XmlDoc, then we need to check if it is null or Empty or InheritDocs, there might be more static values we are going to add in the future.

@@ -100,6 +102,11 @@ public void Update(
}

Signature = updated.Signature;
var updatedParameterNames = Signature.Parameters.Select(p => p.Name).ToList();
if (!originalPartaMeterNames.SequenceEqual(updatedParameterNames) || XmlDocs is null)
Copy link
Author

Choose a reason for hiding this comment

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

adding XmlDocs.IsEmpty into the condition will introduce regen diff

Copy link
Author

Choose a reason for hiding this comment

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

There might be other case that we should rebuild xmlDocs, which can be added later. My primary goal for this PR is to unblock Azure/azure-sdk-for-net#50776.

Copy link
Contributor

@live1206 live1206 Jun 24, 2025

Choose a reason for hiding this comment

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

If we want to reuse XmlDoc.
if (XmlDoc is null || XmlDoc == XmlDocHelper.InheritDocs || XmlDoc == XmlDoc.Empty) should work.

Copy link
Contributor

@live1206 live1206 Jun 24, 2025

Choose a reason for hiding this comment

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

Had an offline discussion with @JoshLove-msft, we can have something like below to unblock this

            if (Signature.Equals(updated.Signature))
            {
                Signature = updated.Signature;
                if (XmlDocs is null && XmlDocs != XmlDocProvider.Empty && XmlDocs != XmlDocProvider.InheritDocs)
                {
                    XmlDocs = MethodProviderHelpers.BuildXmlDocs(Signature);
                }
            }

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be !Signature.Equals(updated.Signature)

Copy link
Contributor

@JoshLove-msft JoshLove-msft Jun 24, 2025

Choose a reason for hiding this comment

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

Also, I think we would need to use the MethodSignatureComparer.Equals

Copy link
Author

Choose a reason for hiding this comment

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

Signature and updated.Signature may point to the same object, we need to find other solution if only Comparing parameter names change is not good engough.
image
image

Copy link
Contributor

@live1206 live1206 Jun 24, 2025

Choose a reason for hiding this comment

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

Since it is always the same instance, which is I think a good thing, we should remove the signature assignment in L104.
And the only option we have is to let the user update signature or rebuild xml docs.

@JoshLove-msft JoshLove-msft self-requested a review June 24, 2025 02:06
@haiyuazhang haiyuazhang marked this pull request as draft June 24, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants