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

Complete 'file' support for SyntaxGenerator #62413

Merged
merged 7 commits into from
Jul 7, 2022

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Jul 6, 2022

Part of #62371 (pending required tests and support, will do in a follow-up)
Fixes #62274

Review should be commit-by-commit.

@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jul 6, 2022
@Youssef1313
Copy link
Member Author

Youssef1313 commented Jul 6, 2022

@RikkiGibson @CyrusNajmabadi @sharwell I'm not sure about the expected behavior for some cases. The current behavior aligns with an existing behavior for static constructors, but the behavior is debatable, and I'm unsure if we should just keep consistent with static constructors, or have different behavior, or even change the behavior of static constructors.

Comment on lines 2337 to 2349
[Fact]
public void TestAddFileModifierToPublicClass()
{
var publicClass = (ClassDeclarationSyntax)SyntaxFactory.ParseMemberDeclaration("public class C { }");
var filePublicClass = Generator.WithModifiers(publicClass, Generator.GetModifiers(publicClass).WithIsFile(true));
// bad output. It will be fixed in a later commit.
// This commit just demonstrates the *current* behavior (test is passing currently, while it shouldn't).
// note, behavior changed here in this commit since we supported file, but the most correct behavior is to eliminate public completely.
// note 2, the correct behavior here is actually not very clear given the constructor case and the opposite case of this.
VerifySyntax<ClassDeclarationSyntax>(filePublicClass, @"public file class C
{
}");
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is even more confusing for a case where the class originally didn't have any accessibility or modifiers (ie, a plain class C), and WithModifiers is called with DeclarationModifiers.Public | DeclarationModifiers.File. Yes it's weird that someone do this, but.. it's a public API.

Copy link
Member

Choose a reason for hiding this comment

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

i'm ok with this just throwing away public modifiers in that case. we did similar things with interface members (prior to them supporting accessibility or method bodies).

Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually my bad. There is no DeclarationModifiers.Public 😄

The way to say both public and file will be two calls, one to WithModifiers and one to WithAccessibility. The second call will overwrite the first in this case.

@Youssef1313 Youssef1313 marked this pull request as ready for review July 6, 2022 15:22
@Youssef1313 Youssef1313 requested a review from a team as a code owner July 6, 2022 15:22
@RikkiGibson RikkiGibson self-assigned this Jul 6, 2022
@@ -1628,6 +1628,9 @@ private static SyntaxTokenList AsModifierList(Accessibility accessibility, Decla
break;
}

if (modifiers.IsFile)
list.Add(SyntaxFactory.Token(SyntaxKind.FileKeyword));
Copy link
Member

Choose a reason for hiding this comment

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

if we have .IsFile can we not add any accessibility above? one of the goals of SyntaxGenerator is to add smarts like that to generate the most likely thing wanted.

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi This is ready for another look

@RikkiGibson
Copy link
Contributor

Thanks @Youssef1313!

@RikkiGibson RikkiGibson merged commit 3f8481b into dotnet:main Jul 7, 2022
@ghost ghost added this to the Next milestone Jul 7, 2022
@Youssef1313 Youssef1313 deleted the file-generator branch July 7, 2022 18:23
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 7, 2022
* upstream/main: (62 commits)
  Prevent assert from being hit (dotnet#62366)
  Don't offer '??=' for pointer types (dotnet#62476)
  Integrate generator times into /reportAnalyzer (dotnet#61661)
  Switch to a callback for cleaning up resources instead of passing in an explicit IDisposable. (dotnet#62373)
  Filter trees to only those containing global-usings or attributes prior to analyzing them. (dotnet#62444)
  Update PublishData.json
  Complete 'file' support for `SyntaxGenerator` (dotnet#62413)
  Apply changes directly to text buffer (dotnet#62337)
  Remove LangVer check from extended nameof binding (dotnet#62339)
  Fixed shared project file error (dotnet#62466)
  Handle new error codes
  Use MSBuid generated property for package path
  Exclude BCL libraries from Roslyn vsix
  Bump the integration test timeouts a bit
  Skip the balanced switch dispatch optimization for patterns on floating-point inputs (dotnet#62322)
  Test helpers shouldn't escape quotes by default (dotnet#62321)
  Reuse prior TableEntry values in the increment NodeTable builder if possible. (dotnet#62320)
  Install 3.1 runtime for SBOM tool
  Generate VS SBOM during official build.
  Minor refactoring in 'required' handling for override completion (dotnet#62422)
  ...
@allisonchou allisonchou modified the milestones: Next, 17.4 P1 Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revise SyntaxGenerator for file types
4 participants