Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.
Closed
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 @@ -81,6 +81,7 @@ void GetFolderContent (Project project, string folder, out List<ProjectFile> fil
{
string folderPrefix = folder + Path.DirectorySeparatorChar;

var visitedFiles = new HashSet<FilePath> ();
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need a comment on the fact that this hashset is needed as a workaround.

files = new List<ProjectFile> ();
folders = new List<string> ();

Expand All @@ -100,7 +101,8 @@ void GetFolderContent (Project project, string folder, out List<ProjectFile> fil
? project.BaseDirectory.Combine (file.ProjectVirtualPath).ParentDirectory
: file.FilePath.ParentDirectory;

if (dir == folder) {
if (dir == folder && !visitedFiles.Contains (file.FilePath)) {
visitedFiles.Add (file.FilePath);
files.Add (file);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using Mono.Addins;
using MonoDevelop.Core;
using MonoDevelop.Projects;

namespace MonoDevelop.Ide.Projects.FileNesting
Expand Down Expand Up @@ -166,7 +167,7 @@ public ProjectFileNestingInfo (ProjectFile projectFile)
}
}

readonly ConcurrentDictionary<ProjectFile, ProjectFileNestingInfo> projectFiles = new ConcurrentDictionary<ProjectFile, ProjectFileNestingInfo> ();
readonly ConcurrentDictionary<FilePath, ProjectFileNestingInfo> projectFiles = new ConcurrentDictionary<FilePath, ProjectFileNestingInfo> ();
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment that the FilePath is used as a workaround, we should be using ProjectFile.

bool fileNestingEnabled;

public Project Project { get; }
Expand Down Expand Up @@ -195,10 +196,10 @@ void EnsureInitialized ()

ProjectFileNestingInfo AddFile (ProjectFile projectFile)
{
var tmp = projectFiles.GetOrAdd (projectFile, new ProjectFileNestingInfo (projectFile));
var tmp = projectFiles.GetOrAdd (projectFile.FilePath, new ProjectFileNestingInfo (projectFile));
tmp.Parent = FileNestingService.InternalGetParentFile (projectFile);
if (tmp.Parent != null) {
var parent = projectFiles.GetOrAdd (tmp.Parent, new ProjectFileNestingInfo (tmp.Parent));
var parent = projectFiles.GetOrAdd (tmp.Parent.FilePath, new ProjectFileNestingInfo (tmp.Parent));
if (parent.Children == null) {
parent.Children = new ProjectFileCollection ();
}
Expand All @@ -207,19 +208,19 @@ ProjectFileNestingInfo AddFile (ProjectFile projectFile)
}
}

projectFiles [projectFile] = tmp;
projectFiles [projectFile.FilePath] = tmp;
return tmp;
}

ProjectFileNestingInfo RemoveFile (ProjectFile projectFile, List<ProjectFile> originalFilesToRemove = null)
{
bool actuallyRemoveFiles = originalFilesToRemove == null;

projectFiles.TryRemove (projectFile, out var nestingInfo);
projectFiles.TryRemove (projectFile.FilePath, out var nestingInfo);

// Update parent
if (nestingInfo?.Parent != null) {
if (projectFiles.TryGetValue (nestingInfo.Parent, out var tmp)) {
if (projectFiles.TryGetValue (nestingInfo.Parent.FilePath, out var tmp)) {
tmp.Children.Remove (projectFile);
}
}
Expand Down Expand Up @@ -296,7 +297,7 @@ public ProjectFile GetParentForFile (ProjectFile inputFile)
if (!fileNestingEnabled)
return null;

return projectFiles.TryGetValue (inputFile, out var nestingInfo) ? nestingInfo.Parent : null;
return projectFiles.TryGetValue (inputFile.FilePath, out var nestingInfo) ? nestingInfo.Parent : null;
}

public ProjectFileCollection GetChildrenForFile (ProjectFile inputFile)
Expand All @@ -305,7 +306,7 @@ public ProjectFileCollection GetChildrenForFile (ProjectFile inputFile)
if (!fileNestingEnabled)
return null;

return projectFiles.TryGetValue (inputFile, out var nestingInfo) ? nestingInfo.Children : null;
return projectFiles.TryGetValue (inputFile.FilePath, out var nestingInfo) ? nestingInfo.Children : null;
}
Copy link
Member

Choose a reason for hiding this comment

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

@rodrmoya Can you remember why you had to change the FileNestingService here for the duplicate files? Just wondering if the other pull request is enough to fix the problem since that change would only affect the files in the Solution pad window, not the files belonging to the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, so FileNestingService deals with the files in the project, not the solution pad really, so if the files in the project are still duplicated, I guess maybe we need this change after all?

Copy link
Member

Choose a reason for hiding this comment

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

I did not see any duplicate files in the Solution pad. Just wondering what would happen here with the nesting if Project.Files contained duplicate files, but with different conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or well, maybe it's not needed at all, as FileNestingService is called from the node builders, so if those don't get the duplicated files, it should be ok. But not sure, as the service listens to FileAdded/Removed events on the project to keep the data up to date

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 think it might be affected indeed, as files are stored on a dictionary -> https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects.FileNesting/FileNestingService.cs#L198 with the ProjectFile being the key, so maybe it makes sense to get the FileNestingService's changes of this PR, although, as @Therzok mentioned, that adds a big perf hit :/

I'll have a look and see how/if it gets affected


public void Dispose ()
Expand Down