public void RequestAnalysis(string path, string charset, IList <IContentType> contentTypes) { IssueTagger tracker; if (taggers.TryGetValue(path, out tracker)) { foreach (IContentType type in contentTypes) { if (type.IsOfType("JavaScript")) { daemon.RequestAnalysis(path, charset, "js", null, this); return; } if (type.IsOfType("C/C++")) { string sqLanguage; string json = CFamily.TryGetConfig(logger, tracker.ProjectItem, path, out sqLanguage); if (json != null && sqLanguage != null) { daemon.RequestAnalysis(path, charset, sqLanguage, json, this); } return; } } logger.Write("Unsupported content type for " + path); } }
private void WriteMessageToOutput() { const string message = "*****************************************************************************************\r\n" + "*** Newer versions of SonarLint will not work with this version of Visual Studio. ***\r\n" + "*** Please update to Visual Studio 2015 Update 3 or Visual Studio 2017 to benefit ***\r\n" + "*** from new features. ***\r\n" + "*****************************************************************************************"; sonarLintOutput.Write(message); }
public static string TryGetConfig(ISonarLintOutput logger, EnvDTE.ProjectItem projectItem, string absoluteFilePath, out string sqLanguage) { try { return(FileConfig.TryGet(projectItem, absoluteFilePath).ToJson(absoluteFilePath, out sqLanguage)); } catch (Exception e) { logger.Write("Unable to collect C/C++ configuration: " + e.ToString()); sqLanguage = null; return(null); } }
private async Task SafeServiceCall(Func <Task> call) { try { await call(); } catch (HttpRequestException e) { // For some errors we will get an inner exception which will have a more specific information // that we would like to show i.e.when the host could not be resolved var innerException = e.InnerException as System.Net.WebException; sonarLintOutput.Write(string.Format(Strings.SonarQubeRequestFailed, e.Message, innerException?.Message)); } catch (TaskCanceledException) { // Canceled or timeout sonarLintOutput.Write(Strings.SonarQubeRequestTimeoutOrCancelled); } catch (Exception e) { sonarLintOutput.Write(string.Format(Strings.SonarQubeRequestFailed, e.Message, null)); } }
private async Task <IList <SonarQubeNotification> > GetNotificationEvents() { try { return(await sonarQubeService.GetNotificationEventsAsync(projectKey, lastCheckDate, cancellation.Token)); } catch (Exception ex) { sonarLintOutput.Write($"Failed to fetch notifications : {ex.Message}"); return(null); } }
protected override void OnLoadOptions(string key, Stream stream) { if (key == NotificationDataKey) { try { notificationData = formatter.Deserialize(stream) as NotificationData; } catch (Exception ex) { sonarLintOutput.Write($"Failed to read notification data: {ex.Message}"); } } }
private async Task UpdateEvents(bool isFirstRequest = false) { // Query server even if notifications are disabled, query the server to know // if the icon should be shown (so the notifications can be re-enabled). if (!sonarQubeService.IsConnected || (!Model.AreNotificationsEnabled && Model.IsIconVisible)) { return; } try { var events = await sonarQubeService.GetNotificationEventsAsync(projectKey, lastCheckDate, cancellation.Token); if (events == null) { // Notifications are not supported on SonarQube Stop(); return; } // First request is only to detect if notifications are enabled on the server. // Even if there are notifications, do not show them as it could be easy to miss // (this code is executed on solution load, when a lot of things happen in the UI). if (!isFirstRequest) { if (events.Count > 0) { lastCheckDate = events.Max(ev => ev.Date); } Model.SetNotificationEvents(events); } Model.IsIconVisible = true; } catch (Exception ex) { sonarLintOutput.Write($"Failed to fetch notifications: {ex.Message}"); } }
private void WritelnToPane(string msg) { logger.Write(msg); }