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

Fix support for "Usings inside namespaces" in various places #55795

Merged
merged 16 commits into from
Aug 26, 2021

Conversation

davidwengier
Copy link
Contributor

@davidwengier davidwengier commented Aug 22, 2021

Fixes #55746
Fixes #39786

This also fixes anything that uses the AddImports service, so they all support using directive placement options, and fixes anything that uses the MemberPuller to respect that, plus the "System Usings First" setting.

Commit-by-commit might make sense because there is a fair bit of plumbing changes, but I commented where the important bits were.

@davidwengier davidwengier requested a review from a team as a code owner August 22, 2021 11:38
@@ -57,7 +57,9 @@ public static async Task<(Document containingDocument, SyntaxAnnotation typeAnno
CancellationToken cancellationToken)
{
var newDocumentId = DocumentId.CreateNewId(projectId, debugName: fileName);
var solutionWithInterfaceDocument = solution.AddDocument(newDocumentId, fileName, text: "", folders: folders);
var newDocumentPath = PathUtilities.CombinePaths(PathUtilities.GetDirectoryName(hintDocument.FilePath), fileName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was needed for the new test framework to be happy ¯\_(ツ)_/¯

Copy link
Member

Choose a reason for hiding this comment

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

This was needed for the new test framework to be happy ¯_(ツ)_/¯

I expect if a test has failed, this most likely indicates a product bug. Does this have any effect to the end-user (ie, bug fix)? If not, I'm curious to know why the test failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to guess by not setting the filepath the new test framework doesn't alter it to have a file path. Old framework might have (I'd have to dig in to see) based on the folders and filename.

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'm curious to know why the test failed.

The new test framework didn't apply options correctly without this, because it applies options by synthesizing an .editorconfig file in the right path, but since the new document didn't have a path, the options didn't apply to it.

Comment on lines +173 to +176
// If there aren't any existing imports then make sure we honour the inside namespace preference
// for using directings if it's set
if (fallbackNode is null && PlaceImportsInsideNamespaces(options))
fallbackNode = contextSpine.OfType<TNamespaceDeclarationSyntax>().FirstOrDefault();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main bit of the fix

@@ -337,7 +337,7 @@ private static ISymbol GetSymbolsToPullUp(MemberAnalysisResult analysisResult)
node.GetCurrentNode(newDestination),
sourceImports,
generator,
options.PlaceSystemNamespaceFirst,
Copy link
Contributor Author

@davidwengier davidwengier Aug 22, 2021

Choose a reason for hiding this comment

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

This is the fix for anything using MembersPuller: Nothing ever wrote to this property (and its removed entirely in a subsequent commit)

@davidwengier davidwengier changed the title Convert tests to new test framework Fix support for "Usings inside namespaces" in various places Aug 22, 2021
@davidwengier davidwengier requested review from CyrusNajmabadi and a team and removed request for a team August 23, 2021 04:03
@davidwengier davidwengier merged commit 7b1cd60 into dotnet:main Aug 26, 2021
@davidwengier davidwengier deleted the ExtractClassBugs branch August 26, 2021 22:53
@ghost ghost added this to the Next milestone Aug 26, 2021
@dibarbet dibarbet modified the milestones: Next, 17.0.P4 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants