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 handling of nested solution folders with same name. #75

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public void MoveToFolder(SolutionFolderModel? folder)
try
{
this.Parent = folder;

// Reevaulate the id.
if (this.id == this.DefaultId)
{
this.id = null;
}

if (this is SolutionProjectModel thisProject)
{
this.Solution.ValidateProjectName(thisProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ public SolutionFolderModel AddFolder(string path)
string? parentItemRef = lastSlash > 0 ? folderPath.Slice(0, lastSlash + 1).ToString() : null;
StringSpan newName = lastSlash > 0 ? folderPath.Slice(lastSlash + 1) : folderPath.Slice(1);

return this.AddFolder(newName, parentItemRef);
SolutionFolderModel folder = this.AddFolder(newName, parentItemRef);

// Ensure the project type is in the project type table, if it is not already.
this.solutionItemsById[folder.Id] = folder;

return folder;
}

/// <summary>
Expand Down Expand Up @@ -629,8 +634,6 @@ private SolutionFolderModel AddFolder(StringSpan name, string? parentItemRef)
this.solutionFolders.Add(folder);
this.solutionItems.Add(folder);

// Ensure the project type is in the project type table, if it is not already.
this.solutionItemsById[folder.Id] = folder;
return folder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal readonly T[] ToArray()
2 => [this.item0, this.item1],
3 => [this.item0, this.item1, this.item2],
4 => [this.item0, this.item1, this.item2, this.item3],
_ => [this.item0, this.item1, this.item2, this.item3, .. this.items],
_ => [this.item0, this.item1, this.item2, this.item3, .. this.items!],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class RoundTripClassicSln
[Fact]
public Task MissingConfigurationsAsync() => TestRoundTripSerializerAsync(SlnAssets.ClassicSlnMissingConfigurations);

[Fact]
public Task FolderIdAsync() => TestRoundTripSerializerAsync(SlnAssets.LoadResource("FolderId.sln"));

[Theory]
[MemberData(nameof(ClassicSlnFiles))]
public Task AllClassicSolutionAsync(ResourceName sampleFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Foo", "Foo", "{A340195B-735B-34A1-F5D5-445C9F08470D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Foo", "Foo", "{F508AC4D-2574-0F7F-5175-5C248303655F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Foo", "Foo", "{45DA1D9E-8A3F-8D58-BB91-EFD6A5B29A17}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Foo", "Foo", "{6647119C-3B2A-3090-A1B3-560120CC3977}"
EndProject
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F508AC4D-2574-0F7F-5175-5C248303655F} = {A340195B-735B-34A1-F5D5-445C9F08470D}
{45DA1D9E-8A3F-8D58-BB91-EFD6A5B29A17} = {F508AC4D-2574-0F7F-5175-5C248303655F}
{6647119C-3B2A-3090-A1B3-560120CC3977} = {45DA1D9E-8A3F-8D58-BB91-EFD6A5B29A17}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Solution>
<Folder Name="/Foo/" />
<Folder Name="/Foo/Foo/" />
<Folder Name="/Foo/Foo/Foo/" />
<Folder Name="/Foo/Foo/Foo/Foo/" />
</Solution>