Skip to content

Commit

Permalink
Merge pull request #58 from sergey-visual-studio/FileBrowserDups
Browse files Browse the repository at this point in the history
Fixed an issue with File Browser showing duplicate files
  • Loading branch information
sergey-visual-studio authored Dec 3, 2023
2 parents 90ca6b0 + 5a69b87 commit 64a7f1b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 16 deletions.
14 changes: 7 additions & 7 deletions DPackRx.Tests/Features/FileBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "ShowFiles", null)).Returns(showFiles).Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "IgnoreFolders", null)).Returns(ignoreFolders).Verifiable();

_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code, true)).Returns(true).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.None, true)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.ImageFile, true)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code)).Returns(true).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.None)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.ImageFile)).Returns(false).Verifiable();

viewModel.OnInitialize(null);

Expand All @@ -170,15 +170,15 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "IgnoreFolders", null), Times.Once);
if (allFiles)
{
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code, true), Times.Never);
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.None, true), Times.Never);
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code), Times.Never);
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.None), Times.Never);
}
else
{
if (expectedCodeFileCount > 0)
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code, true), Times.AtLeast(expectedCodeFileCount));
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code), Times.AtLeast(expectedCodeFileCount));
if (expectedNoneCodeFileCount > 0)
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsNotIn(FileSubType.Code), true), Times.AtLeast(expectedNoneCodeFileCount));
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsNotIn(FileSubType.Code)), Times.AtLeast(expectedNoneCodeFileCount));
}
_searchMatchServiceMock.Verify(s => s.MatchItems(search, It.IsAny<IEnumerable<IMatchItem>>()), Times.Once);
}
Expand Down
6 changes: 3 additions & 3 deletions DPackRx.Tests/Services/SearchMatchServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public int CompareTo(object obj)
public void Setup()
{
_fileTypeResolverMock = new Mock<IFileTypeResolver>();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(It.IsAny<FileSubType>(), true)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code, true)).Returns(true).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(It.IsAny<FileSubType>())).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code)).Returns(true).Verifiable();

_wildcardMatchMock = new Mock<IWildcardMatch>();
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public void MatchItems(string filter, int codeRank, int nonCodeRank, string erro
Assert.That(codeItem.Rank, Is.EqualTo(codeRank), $"Code item: {error}");
Assert.That(nonCodeItem.Rank, Is.EqualTo(nonCodeRank), $"Non-code item: {error}");

_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsAny<FileSubType>(), true), Times.Exactly(items.Count));
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsAny<FileSubType>()), Times.Exactly(items.Count));
}

[TestCase("test", false)]
Expand Down
5 changes: 3 additions & 2 deletions DPackRx/CodeModel/FileTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public FileSubType GetExtensionSubType(object projectItem, LanguageSettings lang
/// <param name="itemSubType">File sub-type.</param>
/// <param name="miscFilesAsCode">Treat miscellaneous files as code ones.</param>
/// <returns>File sub-type status.</returns>
public bool IsCodeSubType(FileSubType itemSubType, bool miscFilesAsCode = true)
public bool IsCodeSubType(FileSubType itemSubType)
{
switch (itemSubType)
{
Expand All @@ -173,8 +173,9 @@ public bool IsCodeSubType(FileSubType itemSubType, bool miscFilesAsCode = true)
return true;
case FileSubType.JScript:
case FileSubType.XmlFile:
return true;
case FileSubType.ConfigFile:
return miscFilesAsCode;
return false;
default:
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions DPackRx/CodeModel/IFileTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public interface IFileTypeResolver
/// Checks whether a given file sub-type is a code one.
/// </summary>
/// <param name="itemSubType">File sub-type.</param>
/// <param name="miscFilesAsCode">Treat miscellaneous files as code ones.</param>
/// <returns>File sub-type status.</returns>
bool IsCodeSubType(FileSubType itemSubType, bool miscFilesAsCode = true);
bool IsCodeSubType(FileSubType itemSubType);

/// <summary>
/// Checks whether a given file sub-type is a web one with both design and code views.
Expand Down
10 changes: 10 additions & 0 deletions DPackRx/CodeModel/ProjectProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ private void ProcessProjectItems(List<FileModel> model, ProcessorFlags flags, Co
add = false;
}

// Check for nested duplicate files
if (add)
{
if ((parentItem != null) &&
(parentItem.FileCount > 0) &&
(projectItem.FileCount > 0) &&
parentItem.FileNames[0].Equals(projectItem.FileNames[0], StringComparison.OrdinalIgnoreCase))
add = false;
}

// Used to collect skipped files here as well... something to keep an eye out out for
if (add)
{
Expand Down
7 changes: 7 additions & 0 deletions DPackRx/CodeModel/SolutionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ private bool ProcessProject(Project project, ICollection<ProjectModel> model, Pr
}
}

// Duplicate project check
if (process)
{
if (model.FirstOrDefault(p => p.FileName.Equals(projectFullName, StringComparison.OrdinalIgnoreCase)) != null)
process = false;
}

if (process)
{
var projectModel = new ProjectModel
Expand Down
2 changes: 1 addition & 1 deletion DPackRx/Package/Beta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DPackRx.Package
/// </summary>
internal static class Beta
{
public static readonly DateTime ExpirationDate = new DateTime(2023, 7, 3).AddHours(12);
public static readonly DateTime ExpirationDate = new DateTime(2023, 12, 31).AddHours(12);
}
#endif
}
5 changes: 5 additions & 0 deletions DPackRx/Package/LanguageConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ public static class LanguageConsts
/// VS Sql project language Guid.
/// </summary>
public const string VS_LANGUAGE_SQL = "{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}";

/// <summary>
/// Solution folder language Guid.
/// </summary>
public const string VS_MISC_FOLDER = "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}";
}
}
2 changes: 1 addition & 1 deletion DPackRx/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="3D22E261-32E5-46CE-A4B0-B884FA49A9A2.2022" Version="4.5.5" Language="en-US" Publisher="Sergey M" />
<Identity Id="3D22E261-32E5-46CE-A4B0-B884FA49A9A2.2022" Version="4.5.6.2" Language="en-US" Publisher="Sergey M" />
<DisplayName>DPack Rx 2022</DisplayName>
<Description xml:space="preserve">FREE tools collection designed to greatly increase developer's productivity, automate repetitive processes and expand upon some of Microsoft Visual Studio features.</Description>
<MoreInfo>https://github.com/sergey-visual-studio/dpack</MoreInfo>
Expand Down

0 comments on commit 64a7f1b

Please sign in to comment.