Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 90f09d7

Browse files
Rodrigo Moyamonojenkins
authored andcommitted
[Core] Avoid showing duplicated files in project tree
There are some cases where, it seems, we don't evaluate conditions as we should, resulting in duplicated items being added to the project and, thus, also shown in the project tree (see dotnet/aspnetcore#17088). Also, by just adding a <None Include="*"/>, duplicated files show also. So, due to this limitation on the project system, work around it on the project tree, by checking for duplicates based on the files' paths. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1005277
1 parent a500692 commit 90f09d7

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/FolderNodeBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void GetFolderContent (Project project, string folder, out List<ProjectFile> fil
8181
{
8282
string folderPrefix = folder + Path.DirectorySeparatorChar;
8383

84+
var visitedFiles = new HashSet<FilePath> ();
8485
files = new List<ProjectFile> ();
8586
folders = new List<string> ();
8687

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

103-
if (dir == folder) {
104+
if (dir == folder && !visitedFiles.Contains (file.FilePath)) {
105+
visitedFiles.Add (file.FilePath);
104106
files.Add (file);
105107
continue;
106108
}

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects.FileNesting/FileNestingService.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using System.Linq;
3232
using System.Runtime.CompilerServices;
3333
using Mono.Addins;
34+
using MonoDevelop.Core;
3435
using MonoDevelop.Projects;
3536

3637
namespace MonoDevelop.Ide.Projects.FileNesting
@@ -166,7 +167,7 @@ public ProjectFileNestingInfo (ProjectFile projectFile)
166167
}
167168
}
168169

169-
readonly ConcurrentDictionary<ProjectFile, ProjectFileNestingInfo> projectFiles = new ConcurrentDictionary<ProjectFile, ProjectFileNestingInfo> ();
170+
readonly ConcurrentDictionary<FilePath, ProjectFileNestingInfo> projectFiles = new ConcurrentDictionary<FilePath, ProjectFileNestingInfo> ();
170171
bool fileNestingEnabled;
171172

172173
public Project Project { get; }
@@ -195,10 +196,10 @@ void EnsureInitialized ()
195196

196197
ProjectFileNestingInfo AddFile (ProjectFile projectFile)
197198
{
198-
var tmp = projectFiles.GetOrAdd (projectFile, new ProjectFileNestingInfo (projectFile));
199+
var tmp = projectFiles.GetOrAdd (projectFile.FilePath, new ProjectFileNestingInfo (projectFile));
199200
tmp.Parent = FileNestingService.InternalGetParentFile (projectFile);
200201
if (tmp.Parent != null) {
201-
var parent = projectFiles.GetOrAdd (tmp.Parent, new ProjectFileNestingInfo (tmp.Parent));
202+
var parent = projectFiles.GetOrAdd (tmp.Parent.FilePath, new ProjectFileNestingInfo (tmp.Parent));
202203
if (parent.Children == null) {
203204
parent.Children = new ProjectFileCollection ();
204205
}
@@ -207,19 +208,19 @@ ProjectFileNestingInfo AddFile (ProjectFile projectFile)
207208
}
208209
}
209210

210-
projectFiles [projectFile] = tmp;
211+
projectFiles [projectFile.FilePath] = tmp;
211212
return tmp;
212213
}
213214

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

218-
projectFiles.TryRemove (projectFile, out var nestingInfo);
219+
projectFiles.TryRemove (projectFile.FilePath, out var nestingInfo);
219220

220221
// Update parent
221222
if (nestingInfo?.Parent != null) {
222-
if (projectFiles.TryGetValue (nestingInfo.Parent, out var tmp)) {
223+
if (projectFiles.TryGetValue (nestingInfo.Parent.FilePath, out var tmp)) {
223224
tmp.Children.Remove (projectFile);
224225
}
225226
}
@@ -296,7 +297,7 @@ public ProjectFile GetParentForFile (ProjectFile inputFile)
296297
if (!fileNestingEnabled)
297298
return null;
298299

299-
return projectFiles.TryGetValue (inputFile, out var nestingInfo) ? nestingInfo.Parent : null;
300+
return projectFiles.TryGetValue (inputFile.FilePath, out var nestingInfo) ? nestingInfo.Parent : null;
300301
}
301302

302303
public ProjectFileCollection GetChildrenForFile (ProjectFile inputFile)
@@ -305,7 +306,7 @@ public ProjectFileCollection GetChildrenForFile (ProjectFile inputFile)
305306
if (!fileNestingEnabled)
306307
return null;
307308

308-
return projectFiles.TryGetValue (inputFile, out var nestingInfo) ? nestingInfo.Children : null;
309+
return projectFiles.TryGetValue (inputFile.FilePath, out var nestingInfo) ? nestingInfo.Children : null;
309310
}
310311

311312
public void Dispose ()

0 commit comments

Comments
 (0)