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

File types IDE changes #62215

Merged
merged 20 commits into from
Jul 5, 2022
Merged

Conversation

RikkiGibson
Copy link
Contributor

Related to #60819

@dibarbet for review. This gets us to the min-bar for IDE support.

The SymbolKey changes are important here. Without them EnC will not work at all with the feature. With them we can do some simple EnC without crashing in the IDE. It will still fail when files are added or removed during an EnC session but we anticipate solving that after merging the feature to main, before RTM. #61999

@RikkiGibson RikkiGibson requested a review from a team as a code owner June 28, 2022 22:29
@RikkiGibson
Copy link
Contributor Author

Just realized this won't pass CI until #61646 is merged 😅. Should still be reviewable though.

@RikkiGibson RikkiGibson mentioned this pull request Jun 29, 2022
@RikkiGibson RikkiGibson requested a review from a team as a code owner June 30, 2022 22:55
@@ -203,6 +211,7 @@ private enum Modifiers
Volatile = 1 << 14,
Extern = 1 << 15,
Required = 1 << 16,
File = 1 << 17,
Copy link
Member

Choose a reason for hiding this comment

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

Since you added this API, consider fixing up:

Consider also updating

case SyntaxKind.DelegateDeclaration:
return DeclarationModifiers.New | DeclarationModifiers.Unsafe;

private static readonly DeclarationModifiers s_classModifiers =
DeclarationModifiers.Abstract |
DeclarationModifiers.New |
DeclarationModifiers.Partial |
DeclarationModifiers.Sealed |
DeclarationModifiers.Static |
DeclarationModifiers.Unsafe;
private static readonly DeclarationModifiers s_recordModifiers =
DeclarationModifiers.Abstract |
DeclarationModifiers.New |
DeclarationModifiers.Partial |
DeclarationModifiers.Sealed |
DeclarationModifiers.Unsafe;
private static readonly DeclarationModifiers s_structModifiers =
DeclarationModifiers.New |
DeclarationModifiers.Partial |
DeclarationModifiers.ReadOnly |
DeclarationModifiers.Ref |
DeclarationModifiers.Unsafe;
private static readonly DeclarationModifiers s_interfaceModifiers = DeclarationModifiers.New | DeclarationModifiers.Partial | DeclarationModifiers.Unsafe;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually wasn't clear to me whether 'file' should be added to this. I assume if the IDE has need to generate syntax for a file type, it would use this. But I don't know if the use case exists. It would be helpful to know whether I should delete and just stub out a bool IsFIle => false; implementation.

Copy link
Member

@Youssef1313 Youssef1313 Jul 1, 2022

Choose a reason for hiding this comment

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

@RikkiGibson This is a public API. So it's very necessary that 'file' is added here (not necessarily in this PR)

A common SyntaxGenerator usage pattern is generator.WithModifiers(node, generator.GetModifiers(node).WithIsX(true))

If the node with a class declaration for file class C { }, and we called WithIsSealed(true) (for example), I expect the resulting node will drop file if the change is not made.

Copy link
Member

Choose a reason for hiding this comment

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

@Youssef1313 is correct. thanks! :)

/// <summary>
/// Indicates the type is declared in source and is only visible in the file it is declared in.
/// </summary>
bool IsFile { get; }
Copy link
Member

Choose a reason for hiding this comment

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

📝 For the record, the API review for this is tracked by #62254

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass, compiler changes only (iteration 14)

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

lgtm with the changes suggested by @Youssef1313 . thanks!

@RikkiGibson RikkiGibson requested review from CyrusNajmabadi and a team and removed request for CyrusNajmabadi July 1, 2022 20:32
[InlineData("struct", TypeKind.Struct)]
[InlineData("interface", TypeKind.Interface)]
[InlineData("enum", TypeKind.Enum)]
public async Task AddFileType(string kindString, TypeKind typeKind)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to figure out how to properly test 'delegate', 'record', or 'record struct' here.

  • 'delegate' got me a test crash with a stacktrace consisting only of async thunks..
  • I didn't see how to specify 'record' and 'record struct' in here.

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

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

I expect the lack of file being handled here to cause problems with a public API path:

modifiers |= token.Kind() switch
{
SyntaxKind.AbstractKeyword => DeclarationModifiers.Abstract,
SyntaxKind.NewKeyword => DeclarationModifiers.New,
SyntaxKind.OverrideKeyword => DeclarationModifiers.Override,
SyntaxKind.VirtualKeyword => DeclarationModifiers.Virtual,
SyntaxKind.StaticKeyword => DeclarationModifiers.Static,
SyntaxKind.AsyncKeyword => DeclarationModifiers.Async,
SyntaxKind.ConstKeyword => DeclarationModifiers.Const,
SyntaxKind.ReadOnlyKeyword => DeclarationModifiers.ReadOnly,
SyntaxKind.SealedKeyword => DeclarationModifiers.Sealed,
SyntaxKind.UnsafeKeyword => DeclarationModifiers.Unsafe,
SyntaxKind.PartialKeyword => DeclarationModifiers.Partial,
SyntaxKind.RefKeyword => DeclarationModifiers.Ref,
SyntaxKind.VolatileKeyword => DeclarationModifiers.Volatile,
SyntaxKind.ExternKeyword => DeclarationModifiers.Extern,
_ => DeclarationModifiers.None,
};

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Jul 1, 2022

Are you able to identify a specific editor feature/scenario which will behave incorrectly? I may prefer to file an issue
and address it after this PR.

@Youssef1313
Copy link
Member

Are you able to identify a specific editor feature/scenario which will behave incorrectly? I may prefer to file an issue and address it after this PR.

I'll take a look

@RikkiGibson RikkiGibson requested a review from jcouv July 1, 2022 23:48
@jcouv jcouv self-assigned this Jul 5, 2022
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Compiler-side LGTM Thanks (iteration 20)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants