private async System.Threading.Tasks.Task InitAsync() { try { logger = await this.GetMefServiceAsync <ILogger>(); logger.WriteLine(Resources.Strings.Daemon_Initializing); await DisableRuleCommand.InitializeAsync(this, logger); await CFamilyReproducerCommand.InitializeAsync(this, logger); cFamilyPreCompiledHeadersEventListener = await this.GetMefServiceAsync <IPreCompiledHeadersEventListener>(); daemon = await this.GetMefServiceAsync <ISonarLintDaemon>(); LegacyInstallationCleanup.CleanupDaemonFiles(logger); // Set up the solution tracker so we can shut down the daemon when a solution is closed var solutionTracker = await this.GetMefServiceAsync <IActiveSolutionTracker>(); solutionTracker.ActiveSolutionChanged += HandleActiveSolutionChanged; IDaemonInstaller installer = await this.GetMefServiceAsync <IDaemonInstaller>(); if (!installer.IsInstalled()) { // Set up the status bar download handler in case the user enables // support for additional languages during the VS session var sbService = await this.GetServiceAsync(typeof(IVsStatusbar)) as IVsStatusbar; statusBarDownloadProgressHandler = new StatusBarDownloadProgressHandler(sbService, installer, logger); var settings = await this.GetMefServiceAsync <ISonarLintSettings>(); if (settings.IsActivateMoreEnabled) { // User already agreed to have the daemon installed so directly start download. // No UI interation so we don't need to be on the UI thread. installer.Install(); } } } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { logger?.WriteLine(Resources.Strings.ERROR_InitializingDaemon, ex); } logger?.WriteLine(Resources.Strings.Daemon_InitializationComplete); }
public void GetErrorCode_SingleCppIssue_ErrorCodeReturned() { // Arrange var issueHandle = CreateIssueHandle(111, new Dictionary <string, object> { { StandardTableKeyNames.BuildTool, "SonarLint" }, { StandardTableKeyNames.ErrorCode, "cpp:S123" } }); var mockErrorList = CreateErrorList(issueHandle); // Act bool result = DisableRuleCommand.TryGetErrorCodeSync(mockErrorList, out var errorCode); // Assert result.Should().BeTrue(); errorCode.Should().Be("cpp:S123"); }
public void GetErrorCode_NotSonarLintIssue() { // Arrange var issueHandle = CreateIssueHandle(111, new Dictionary <string, object> { { StandardTableKeyNames.BuildTool, new object() }, { StandardTableKeyNames.ErrorCode, "cpp:S333" } }); var mockErrorList = CreateErrorList(issueHandle); // Act bool result = DisableRuleCommand.TryGetRuleId(mockErrorList, out var errorCode); // Assert result.Should().BeFalse(); errorCode.Should().BeNull(); }
public void GetErrorCode_NonStandardErrorCode_NoException_ErrorCodeNotReturned() { // Arrange var issueHandle = CreateIssueHandle(111, new Dictionary <string, object> { { StandardTableKeyNames.BuildTool, "SonarLint" }, { StandardTableKeyNames.ErrorCode, ":" } // should not happen }); var mockErrorList = CreateErrorList(issueHandle); // Act bool result = DisableRuleCommand.TryGetRuleId(mockErrorList, out var errorCode); // Assert result.Should().BeFalse(); errorCode.Should().BeNull(); }
public void GetErrorCode_SingleSonarIssue_ErrorCodeReturned(string fullRuleKey, string expectedRepo, string expectedRule) { // Arrange var issueHandle = CreateIssueHandle(111, new Dictionary <string, object> { { StandardTableKeyNames.BuildTool, "SonarLint" }, { StandardTableKeyNames.ErrorCode, fullRuleKey } }); var mockErrorList = CreateErrorList(issueHandle); // Act bool result = DisableRuleCommand.TryGetRuleId(mockErrorList, out var ruleId); // Assert result.Should().BeTrue(); ruleId.RepoKey.Should().Be(expectedRepo); ruleId.RuleKey.Should().Be(expectedRule); }
public void GetErrorCode_MultipleItemsSelected_ErrorCodeNotReturned() { var cppIssueHandle = CreateIssueHandle(111, new Dictionary <string, object> { { StandardTableKeyNames.BuildTool, "SonarLint" }, { StandardTableKeyNames.ErrorCode, "cpp:S222" } }); var jsIssueHandle = CreateIssueHandle(222, new Dictionary <string, object> { { StandardTableKeyNames.BuildTool, "SonarLint" }, { StandardTableKeyNames.ErrorCode, "javascript:S222" } }); var mockErrorList = CreateErrorList(cppIssueHandle, jsIssueHandle); // Act bool result = DisableRuleCommand.TryGetRuleId(mockErrorList, out var errorCode); // Assert result.Should().BeFalse(); errorCode.Should().BeNull(); }
private async System.Threading.Tasks.Task InitAsync() { try { logger = await this.GetMefServiceAsync <ILogger>(); logger.WriteLine(Resources.Strings.Daemon_Initializing); await DisableRuleCommand.InitializeAsync(this, logger); await CFamilyReproducerCommand.InitializeAsync(this, logger); cFamilyPreCompiledHeadersEventListener = await this.GetMefServiceAsync <IPreCompiledHeadersEventListener>(); LegacyInstallationCleanup.CleanupDaemonFiles(logger); } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { logger?.WriteLine(Resources.Strings.ERROR_InitializingDaemon, ex); } logger?.WriteLine(Resources.Strings.Daemon_InitializationComplete); }