Skip to content

Commit

Permalink
Merge pull request #10 from usysware/KeyboardBindingassignment
Browse files Browse the repository at this point in the history
Keyboard binding assignment
  • Loading branch information
Sergey M authored Aug 10, 2020
2 parents 441a91d + aec6fe1 commit d3a0a44
Show file tree
Hide file tree
Showing 46 changed files with 429 additions and 311 deletions.
13 changes: 12 additions & 1 deletion DPackRx.Tests/Features/BookmarksServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ public void GoToBookmark_ErrorHandling()

[TestCase(null)]
[TestCase("")]
[TestCase("bad")]
public void GoToBookmark_NoFile(string fileName)
{
var service = GetService();
Expand Down Expand Up @@ -429,6 +428,18 @@ public void GoToBookmark_InvalidLine()
_shellStatusBarServiceMock.Verify(s => s.SetStatusBarText(It.IsNotNull<string>()));
}

[Test]
public void GoToBookmark_NoFileBookmarks()
{
var service = GetService();

var result = service.GoToBookmark(1);

Assert.That(result, Is.False);
_shellSelectionServiceMock.Verify(s => s.GetActiveFileName());
_shellStatusBarServiceMock.Verify(s => s.SetStatusBarText(It.IsNotNull<string>()));
}

[Test]
public void SetGlobalBookmark()
{
Expand Down
2 changes: 1 addition & 1 deletion DPackRx.Tests/Features/FileBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void OpenFilesCommand_Execute(bool controlKeyDown)
var selection = new List<FileModel>();
viewModel.OpenFilesCommand.Execute(selection);

Assert.That(viewModel.SelectionCode, Is.EqualTo(controlKeyDown ? false : true));
Assert.That(viewModel.SelectionCode, Is.EqualTo(!controlKeyDown));
Assert.That(viewModel.Selection, Is.EqualTo(selection));
Assert.That(viewModel.CloseWindow, Is.True);
_utilsServiceMock.Verify(u => u.ControlKeyDown());
Expand Down
7 changes: 1 addition & 6 deletions DPackRx.Tests/Features/SupportOptionsFirstTimeUseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class SupportOptionsFirstTimeUseTests
{
#region Fields

private Mock<ILog> _logMock;
private Mock<IOptionsService> _optionsServiceMock;
private Mock<IPackageService> _packageServiceMock;
private Mock<IShellHelperService> _shellHelperServiceMock;
Expand All @@ -33,9 +32,6 @@ public class SupportOptionsFirstTimeUseTests
[SetUp]
public void Setup()
{
_logMock = new Mock<ILog>();
_logMock.Setup(l => l.LogMessage(It.IsAny<string>(), It.IsAny<string>())).Verifiable();

_optionsServiceMock = new Mock<IOptionsService>();
_optionsServiceMock.Setup(o => o.GetBoolOption(It.IsAny<KnownFeature>(), It.IsAny<string>(), false)).Returns(false).Verifiable();
_optionsServiceMock.Setup(o => o.SetBoolOption(It.IsAny<KnownFeature>(), It.IsAny<string>(), true)).Verifiable();
Expand All @@ -57,7 +53,6 @@ public void Setup()
[TearDown]
public void TearDown()
{
_logMock = null;
_optionsServiceMock = null;
_packageServiceMock = null;
_shellHelperServiceMock = null;
Expand All @@ -73,7 +68,7 @@ public void TearDown()
/// </summary>
private ISolutionEvents GetFeature()
{
return new SupportOptionsFirstTimeUse(_logMock.Object, _optionsServiceMock.Object,
return new SupportOptionsFirstTimeUse(_optionsServiceMock.Object,
_packageServiceMock.Object, _shellHelperServiceMock.Object, _shellInfoBarServiceMock.Object,
_messageServiceMock.Object);
}
Expand Down
2 changes: 2 additions & 0 deletions DPackRx.Tests/Options/OptionsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ public void Flush()

Assert.That(changed, Is.True);
_optionsPersistenceServiceMock.Verify(o => o.SaveOptions(KnownFeature.SupportOptions, It.IsAny<IDictionary<string, object>>()));
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()));
}

[Test]
Expand Down Expand Up @@ -421,6 +422,7 @@ public void ResetAll()
_optionsPersistenceServiceMock.Verify(o => o.LoadOptions(KnownFeature.SupportOptions), Times.Never);
_optionsPersistenceServiceMock.Verify(o => o.LoadDefaultOptions(KnownFeature.SupportOptions), Times.Once);
_optionsPersistenceServiceMock.Verify(o => o.DeleteOptions(KnownFeature.SupportOptions), Times.Once);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()));
Assert.That(changed, Is.True);
Assert.That(reset, Is.True);
Assert.That(service.GetOption(KnownFeature.SupportOptions, "test"), Is.EqualTo(789));
Expand Down
38 changes: 20 additions & 18 deletions DPackRx.Tests/Services/SearchMatchServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,27 @@ private ISearchMatchService GetService()

private static List<IMatchItem> GetItems(bool matched = false, int rank = 0)
{
var items = new List<IMatchItem>();
items.Add(new TestMatchItem
var items = new List<IMatchItem>
{
ItemSubType = FileSubType.None,
Data = "TestFile1.txt",
PascalCasedData = "TF1",
DataEndingIndex = 9,
Matched = matched,
Rank = rank
});
items.Add(new TestMatchItem
{
ItemSubType = FileSubType.Code,
Data = "TestCodeFile2.cs",
PascalCasedData = "TCF2",
DataEndingIndex = 13,
Matched = matched,
Rank = rank
});
new TestMatchItem
{
ItemSubType = FileSubType.None,
Data = "TestFile1.txt",
PascalCasedData = "TF1",
DataEndingIndex = 9,
Matched = matched,
Rank = rank
},
new TestMatchItem
{
ItemSubType = FileSubType.Code,
Data = "TestCodeFile2.cs",
PascalCasedData = "TCF2",
DataEndingIndex = 13,
Matched = matched,
Rank = rank
}
};
return items;
}

Expand Down
27 changes: 14 additions & 13 deletions DPackRx/CodeModel/FileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class FileProcessor : IFileProcessor
private readonly IShellCodeModelService _shellCodeModelService;
private readonly IFileTypeResolver _fileTypeResolver;

private const string LOG_CATEGORY = "File Processor";
private const string UNNAMED_NAME = "<Unnamed>";
private const string DESTRUCTOR_PREFIX = "~";
private const string DOC_TAG = "doc";
Expand Down Expand Up @@ -155,7 +156,7 @@ public bool IsDocumentValid(object document, out object projectItem)
}

if (!string.IsNullOrEmpty(fileName))
_log.LogMessage($"Collecting file code model: {Path.GetFileName(fileName)}");
_log.LogMessage($"Collecting file code model: {Path.GetFileName(fileName)}", LOG_CATEGORY);

if ((languageSet?.Type == LanguageType.Unknown) || string.IsNullOrEmpty(fileName))
dteItem = null;
Expand Down Expand Up @@ -228,7 +229,7 @@ private void GetMembersInternal(object projectItem, List<MemberCodeModel> model,
if (dteItem == null)
throw new ArgumentNullException(nameof(projectItem));

_log.LogMessage($"Collecting code members for '{dteItem.Name}'");
_log.LogMessage($"Collecting code members for '{dteItem.Name}'", LOG_CATEGORY);

var languageSet = _fileTypeResolver.GetCurrentLanguage(dteItem.ContainingProject, out _);

Expand All @@ -239,13 +240,13 @@ private void GetMembersInternal(object projectItem, List<MemberCodeModel> model,
}
catch (Exception ex)
{
_log.LogMessage($"Error collecting code members for '{dteItem.Name}': {ex.Message}", ex);
_log.LogMessage($"Error collecting code members for '{dteItem.Name}': {ex.Message}", ex, LOG_CATEGORY);
throw;
}

if (elements == null)
{
_log.LogMessage($"Code member information is not available for '{dteItem.Name}'");
_log.LogMessage($"Code member information is not available for '{dteItem.Name}'", LOG_CATEGORY);
return;
}

Expand All @@ -260,11 +261,11 @@ private void GetMembersInternal(object projectItem, List<MemberCodeModel> model,
}
catch (Exception ex)
{
_log.LogMessage("Error refreshing code model for '{dteItem.Name}'", ex);
_log.LogMessage($"Error refreshing code model for '{dteItem.Name}'", ex, LOG_CATEGORY);
return;
}

_log.LogMessage($"Collected {model.Count} '{dteItem.Name}' code members");
_log.LogMessage($"Collected {model.Count} '{dteItem.Name}' code members", LOG_CATEGORY);
}

/// <summary>
Expand Down Expand Up @@ -301,7 +302,7 @@ private void ProcessCodeElement(ProjectItem item, CodeElement element, List<Memb
AddCodeElement(item, null, element, model, flags, languageSet, dteFilter, filter);
}

// Add members that don't reside in the parented member,
// Add members that don't reside in the parented member,
// like class or interface for instance
if (!parented && (
(elementKind == vsCMElement.vsCMElementFunction) ||
Expand Down Expand Up @@ -366,7 +367,7 @@ private void AddCodeElement(ProjectItem item, CodeElement parentElement, CodeEle
string.IsNullOrEmpty(epiFileName) ||
(string.Compare(itemFileName, epiFileName, StringComparison.OrdinalIgnoreCase) != 0))
{
_log.LogMessage($"Project item mismatch: '{item.Name}' expected but '{elementItem.Name}' found instead - {element.Name}");
_log.LogMessage($"Project item mismatch: '{item.Name}' expected but '{elementItem.Name}' found instead - {element.Name}", LOG_CATEGORY);
return;
}
}
Expand Down Expand Up @@ -408,21 +409,21 @@ private void AddCodeElement(ProjectItem item, CodeElement parentElement, CodeEle
(elementKind == vsCMElement.vsCMElementStruct) ||
(elementKind == vsCMElement.vsCMElementEnum) ||
(elementKind == vsCMElement.vsCMElementFunction))
startPoint = element.GetStartPoint(vsCMPart.vsCMPartHeader);
startPoint = element.GetStartPoint(vsCMPart.vsCMPartHeader); // could use vsCMPartBody to jump to code declaration
else
startPoint = element.StartPoint;

if (startPoint == null)
{
_log.LogMessage($"{element.Name} element's of {elementKind} kind StartPoint cannot be determined");
_log.LogMessage($"{element.Name} element's of {elementKind} kind StartPoint cannot be determined", LOG_CATEGORY);
return;
}
}
catch (Exception ex)
{
// Swallow C++ exception as some invalid code model functions raise it sometimes
if (languageSet?.Language != CodeModelLanguageConstants.vsCMLanguageVC)
_log.LogMessage($"Error adding code member: {element.Name}", ex);
_log.LogMessage($"Error adding code member: {element.Name}", ex, LOG_CATEGORY);

return;
}
Expand Down Expand Up @@ -530,7 +531,7 @@ private void AddCodeElement(ProjectItem item, CodeElement parentElement, CodeEle
}
catch (COMException ex)
{
_log.LogMessage($"Ignored COM code model error for {name}", ex);
_log.LogMessage($"Ignored COM code model error for {name}", ex, LOG_CATEGORY);
}
} // if (add)
} // if (memberFilter)
Expand Down Expand Up @@ -878,7 +879,7 @@ private string GetElementReturnTypeName(CodeElement element, vsCMElement element
}
catch (Exception ex)
{
_log.LogMessage($"Error collecting {element.Name} return type", ex);
_log.LogMessage($"Error collecting {element.Name} return type", ex, LOG_CATEGORY);
typeRef = null;
}

Expand Down
16 changes: 9 additions & 7 deletions DPackRx/CodeModel/FileTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class FileTypeResolver : IFileTypeResolver
private readonly ILanguageService _languageService;
private readonly IShellProjectService _shellProjectService;

private const string LOG_CATEGORY = "Resolver";

// DTE "SubType" values:
// "" - miscellaneous file of unknown type
// "Code" - code file
Expand All @@ -31,7 +33,7 @@ public class FileTypeResolver : IFileTypeResolver
// "Designer" - file containing generic designer - not supported
// "Preview" - file containing VC/VB 6 code - not supported
// private const string SUB_TYPE_CODE = "Code"; // .asax for web
private const string SUB_TYPE_FORM = "Form"; // .aspx for web
private const string SUB_TYPE_FORM = "Form"; // .aspx for web
private const string SUB_TYPE_COMPONENT = "Component"; // .asax for web
private const string SUB_TYPE_USER_CONTROL = "UserControl"; // .ascx for web

Expand Down Expand Up @@ -75,9 +77,9 @@ public LanguageSettings GetCurrentLanguage(object project, out bool isWebProject
if (projectName != null)
{
if (!string.IsNullOrEmpty(projectName))
_log.LogMessage($"Check '{projectName}' project language");
_log.LogMessage($"Check '{projectName}' project language", LOG_CATEGORY);
else
_log.LogMessage("Check unnamed project language");
_log.LogMessage("Check unnamed project language", LOG_CATEGORY);
}

var languageSet = LanguageSettings.UnknownLanguage;
Expand All @@ -100,17 +102,17 @@ public LanguageSettings GetCurrentLanguage(object project, out bool isWebProject
}
}

_log.LogMessage($"'{projectName}' project language is {languageSet?.FriendlyName}");
_log.LogMessage($"'{projectName}' project language is {languageSet?.FriendlyName}", LOG_CATEGORY);
return languageSet;
}
catch (NotImplementedException) // This is an acceptable condition
{
_log.LogMessage("Project doesn't implement code model");
_log.LogMessage("Project doesn't implement code model", LOG_CATEGORY);
return LanguageSettings.UnknownLanguage;
}
catch (Exception ex) // But this is a legit problem - raise an exception
{
_log.LogMessage("Failed to check project language", ex);
_log.LogMessage("Failed to check project language", ex, LOG_CATEGORY);
throw;
}
}
Expand Down Expand Up @@ -315,7 +317,7 @@ public bool IsCodeItem(object projectItem, LanguageSettings languageSet, bool is
return false;

var itemSubType = GetSubType(projectItem, languageSet, isWebProject, true);
_log.LogMessage($"'{dteItem.Name}' sub-type is {itemSubType}");
_log.LogMessage($"'{dteItem.Name}' sub-type is {itemSubType}", LOG_CATEGORY);

return IsCodeSubType(itemSubType);
}
Expand Down
1 change: 0 additions & 1 deletion DPackRx/CodeModel/IFileProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace DPackRx.CodeModel
{
Expand Down
9 changes: 5 additions & 4 deletions DPackRx/CodeModel/ProjectProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ProjectProcessor : IProjectProcessor
private readonly IFileTypeResolver _fileTypeResolver;
private readonly IFileProcessor _fileProcessor;

private const string LOG_CATEGORY = "Project Processor";
private const string WEB_APP_CODE = "App_Code";
private const string REFERENCES_NODE = "References";

Expand Down Expand Up @@ -75,7 +76,7 @@ private void GetFilesInternal(object project, List<FileModel> model, ProcessorFl
if (_shellProjectService.IsProjectLoadDeferred(project, out _))
return;

_log.LogMessage($"Collecting '{dteProject.Name}' project files");
_log.LogMessage($"Collecting '{dteProject.Name}' project files", LOG_CATEGORY);

// No need to process project's items if we fail to check its code model
// The exception is made for solution folder *if* that's requested
Expand All @@ -85,14 +86,14 @@ private void GetFilesInternal(object project, List<FileModel> model, ProcessorFl
{
if (flags.HasFlag(ProcessorFlags.IncludeSolutionFolderFiles) && (dteProject.Kind == Constants.vsProjectKindSolutionItems))
{
_log.LogMessage($"Allow '{dteProject.Name}' solution folder processing");
_log.LogMessage($"Allow '{dteProject.Name}' solution folder processing", LOG_CATEGORY);
process = true;
}
}

if (!process && !flags.HasFlag(ProcessorFlags.KnownProjectsOnly) && _shellProjectService.IsProject(project))
{
_log.LogMessage($"Allow '{dteProject.Name}' unknown project type processing");
_log.LogMessage($"Allow '{dteProject.Name}' unknown project type processing", LOG_CATEGORY);
process = true;
}

Expand All @@ -108,7 +109,7 @@ private void GetFilesInternal(object project, List<FileModel> model, ProcessorFl
}
}

_log.LogMessage($"Collected {model.Count} '{dteProject.Name}' project files");
_log.LogMessage($"Collected {model.Count} '{dteProject.Name}' project files", LOG_CATEGORY);
}

/// <summary>
Expand Down
Loading

0 comments on commit d3a0a44

Please sign in to comment.