-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Share ISyntaxFacts/SyntaxGenerator with CodeStyle layer. #41376
Conversation
Tagging @mavasani . This is the approach i'm talking about. Will continue trying to make this fully fleshed out. |
@CyrusNajmabadi I think you also need to link in the implementation types and the extension methods used by the implementations, which means ensuring that the transitive closure of APIs invoked from syntax facts service or its C# and VB implementations are linked into CodeStyle layer + none of these have any Workspace dependencies, otherwise they will fail at runtime from command line. Btw, I don't like all the explicit linked files in code style projects, and am proposing switching to shared projects in #41363, but we unfortunately did not get to discussing that approach in today's design meeting. For example, if you checkout my branch from that PR, you can just drag and drop ISyntaxFactsService and all its implementations from WorkspacesExtensions.shproj to CompilersExtension.shproj and go from there to move rest of the accessed extensions into CompilersExtension.shproj. |
Yup. It's a WIP. Will be updating as a go along.
That woudl also work for me. How the files come in is a separate concern. I just want to make sure all the code is 'workspace clean'. :) |
if you want, we can also gitter chat. |
/// The annotation the reducer uses to identify sub trees to be reduced. | ||
/// The Expand operations add this annotation to nodes so that the Reduce operations later find them. | ||
/// </summary> | ||
public static SyntaxAnnotation Annotation { get; } = new SyntaxAnnotation(); |
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.
😕 This is a public API. Why are we duplicating it?
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.
WIP. :)
Ok. C# seems done-ish. Working on VB side now. |
/// <summary> | ||
/// The annotation used to mark portions of a syntax tree to be formatted. | ||
/// </summary> | ||
public static SyntaxAnnotation Annotation { get; } = new SyntaxAnnotation(); |
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.
note: i'm taking this approach because we have code that i'm sharing that does thing like add these annotations. I could attempt to eitehr not share that code (which would mean ore shuffling around) or #ifdef it. I chose to do this for expediency as i don't really see any issue with annotations being added.
@@ -333,13 +333,13 @@ public static bool IsStaticallyDeclared(SyntaxToken token) | |||
parentNode = parentNode!.Parent!.Parent; | |||
|
|||
// Check if this is a field constant declaration | |||
if (parentNode.GetModifiers().Any(SyntaxKind.ConstKeyword)) | |||
if (parentNode!.GetModifiers().Any(SyntaxKind.ConstKeyword)) |
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.
GetModifiers moved around nullable contexts. wasn't sure the best thing do to here. However, given the heavy use of !
already, this seemed like an acceptable quickpatch.
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.
specifically, i didn't want to change runtime behavior. so i just suppressed to keep things safe.
private static SyntaxToken FindTokenOnLeftOfNode(SyntaxNode node) | ||
{ | ||
return node.FindTokenOnLeftOfPosition(node.SpanStart); | ||
} |
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.
code was moved without touching semantics.
@@ -88,6 +88,7 @@ public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol) | |||
|
|||
break; | |||
} | |||
#endif |
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.
this is one area i did need to change code. That's beacuse .NullableAnnotation
doesn't seem to be avialable in this layer yet. i assume we would have to wait to be able to reference a more recent compiler version.
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.
if we move forward with this PR we should have a tracking issue to remove these.
public static bool IntersectsWith(this SyntaxToken token, int position) | ||
{ | ||
return token.Span.IntersectsWith(position); | ||
} |
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.
note: i unified this with VB and moved to common layer. there is nothing language specific with this particular extension.
[ImportingConstructor] | ||
public CSharpSyntaxGenerator() | ||
{ | ||
} |
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.
note that this is moved into a separate part. This allows hte data-only portion of this type (i.e. all of it by the mef stuff) to be used as a singleton in the codestyle layer. The workspcae layer then languageservice-izes it so it can be imported from that point upwards.
@@ -0,0 +1,135 @@ | |||
// Licensed to the .NET Foundation under one or more agreements. |
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.
all the files intended to be shared end with the _Shared.cs
suffix. I believe these should all be pure splits into partial types, and pure moves of the code.
@sharwell @mavasani this is ready for re-review. This change moves 99.9% of hte change is purely mechanical moves of code into files that can then be shared between the two layers. There is a tiny amount of changing that is very narrowly scoped to make this possible:
|
I've merged all the latest changes we've all made into this. So this can go in safely into master. Ths change alone will drop #41363 down by a third :) |
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\SyntaxNodeExtensions_SharedWithCodeStyle.cs" Link="Formatting\SyntaxNodeExtensions_SharedWithCodeStyle.cs" /> | ||
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\SyntaxTokenExtensions_SharedWithCodeStyle.cs" Link="Formatting\SyntaxTokenExtensions_SharedWithCodeStyle.cs" /> | ||
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\SyntaxTriviaExtensions.cs" Link="Formatting\SyntaxTriviaExtensions.cs" /> | ||
<Compile Include="..\..\..\Workspaces\CSharp\Portable\CodeGeneration\CSharpFlagsEnumGenerator.cs" Link="CodeGeneration\CSharpFlagsEnumGenerator.cs" /> |
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.
We want all of these now to happen via the newly added shared projects, not with linked files.
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.
Sounds good. Let me figure out how to do that. thanks!
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.
Should we do the split first, the move all the files over into the shared projects? Looking at the projects now, it still looks like they use linked files. Seems like we can two phase this.
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.
benefit of that approach is that the sharedproject pr should have no actual code changes, just project structure changes.
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.
You should be able just create a folder named "Extensions" in the required shared projects under: https://github.com/dotnet/roslyn/tree/master/src/Workspaces/SharedUtilitiesAndExtensions. At this point you don't even need to name the files in shared projects end with _Shared
or _SharedWithCodeStyle
suffix.
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.
My refactoring PR already removes all the linked files from CodeStyle layer projects, so it might be easier if that went in?
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.
Let me update my PR with the latest sources from master, and you can see if it makes sense.
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.
Sure!
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\StatementSyntaxExtensions.cs" Link="Extensions\StatementSyntaxExtensions.cs" /> | ||
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\StringExtensions.cs" Link="Extensions\StringExtensions.cs" /> | ||
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\SyntaxListExtensions.cs" Link="Extensions\SyntaxListExtensions.cs" /> | ||
<Compile Include="..\..\..\Workspaces\CSharp\Portable\Extensions\SyntaxNodeExtensions_SharedWithCodeStyle.cs" Link="Extensions\SyntaxNodeExtensions_SharedWithCodeStyle.cs" /> |
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.
These will certainly clash with my refactoring PR as I have split and moved bunch of these into the shared layer as well. One of us will have to deal with merge conflicts in few of files being added to shared layer now.
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.
Yes. I think that is def the case. But ideally you shouldn't need to split/move these down yourself. the only splitting/moving would be for some extensions that weren't captured in this that are used by some other features?
but in tha tcase, i would argue again that they shouldn't be in that big PR. we should pull them out (like the unnecessary-imports part) so that none of that is in the big PR).
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.
but in tha tcase, i would argue again that they shouldn't be in that big PR. we should pull them out
The refactoring PR is now just doing this exact thing: just splitting and moving down extensions into shared layers. Your PR here is doing so for SyntaxGenerator and SyntaxFacts and my PR is doing so for other features. I think the key is we should avoid these efforts in parallel as there will be overlap that leads to big merge conflicts. I would recommend waiting on this PR till the primary refactoring PR goes in.
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.
Note: it may be hte case that that's what is going on in that PR... but it's also 8k more adds and 3k more deletes. So it's mixed in with a bunch of other stuff. We might want to consider how this could just go in, and then have the remaining stuff be teh final bit we need to review in isolation.
@CyrusNajmabadi Are you planning to continue with this work? Otherwise, I can take this up following the same model that you started with here. |
@mavasani i think trying to merge this would be a bit too painful at this point. I'm ok with you taking this :) |
No description provided.