internal async Task ExecuteAnalysis(string filePath, IIssueConsumer consumer, CancellationToken cancellationToken) { telemetryManager.LanguageAnalyzed("js"); // Switch to a background thread await TaskScheduler.Default; analysisStatusNotifier.AnalysisStarted(filePath); try { var stopwatch = Stopwatch.StartNew(); var issues = await eslintBridgeAnalyzer.Analyze(filePath, null, cancellationToken); analysisStatusNotifier.AnalysisFinished(filePath, issues.Count, stopwatch.Elapsed); if (issues.Any()) { consumer.Accept(filePath, issues); } } catch (TaskCanceledException) { analysisStatusNotifier.AnalysisCancelled(filePath); } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { analysisStatusNotifier.AnalysisFailed(filePath, ex); } }
internal async Task ExecuteAnalysis(string filePath, IIssueConsumer consumer, CancellationToken cancellationToken) { telemetryManager.LanguageAnalyzed("ts"); // Switch to a background thread await TaskScheduler.Default; analysisStatusNotifier.AnalysisStarted(filePath); try { var stopwatch = Stopwatch.StartNew(); var tsConfig = await tsConfigProvider.GetConfigForFile(filePath, cancellationToken); if (string.IsNullOrEmpty(tsConfig)) { analysisStatusNotifier.AnalysisFailed(filePath, Resources.ERR_NoTsConfig); return; } logger.WriteLine("[TypescriptAnalyzer] time to find ts config: " + stopwatch.ElapsedMilliseconds); stopwatch.Restart(); var issues = await eslintBridgeAnalyzer.Analyze(filePath, tsConfig, cancellationToken); analysisStatusNotifier.AnalysisFinished(filePath, issues.Count, stopwatch.Elapsed); if (issues.Any()) { consumer.Accept(filePath, issues); } } catch (TaskCanceledException) { analysisStatusNotifier.AnalysisCancelled(filePath); } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { analysisStatusNotifier.AnalysisFailed(filePath, ex); } }
internal /* for testing */ async Task TriggerAnalysisAsync(Request request, IIssueConsumer consumer, IAnalysisStatusNotifier statusNotifier, CancellationToken cancellationToken) { // For notes on VS threading, see https://github.com/microsoft/vs-threading/blob/master/doc/cookbook_vs.md // Note: we support multiple versions of VS which prevents us from using some threading helper methods // that are only available in newer versions of VS e.g. [Import] IThreadHandling. // Switch to a background thread await TaskScheduler.Default; var analysisStartTime = DateTime.Now; statusNotifier?.AnalysisStarted(request.File); int issueCount = 0; var handleMessage = consumer == null ? (Action <Message>)(message => { }) : message => HandleMessage(message, request, consumer, ref issueCount); try { // We're tying up a background thread waiting for out-of-process analysis. We could // change the process runner so it works asynchronously. Alternatively, we could change the // RequestAnalysis method to be asynchronous, rather than fire-and-forget. CallSubProcess(handleMessage, request, settings, logger, cancellationToken); if (cancellationToken.IsCancellationRequested) { statusNotifier?.AnalysisCancelled(request.File); } else { var analysisTime = DateTime.Now - analysisStartTime; statusNotifier?.AnalysisFinished(request.File, issueCount, analysisTime); } } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { statusNotifier?.AnalysisFailed(request.File, ex); } telemetryManager.LanguageAnalyzed(request.CFamilyLanguage); // different keys for C and C++ }
internal async Task ExecuteAnalysis(string filePath, IIssueConsumer consumer, CancellationToken cancellationToken) { telemetryManager.LanguageAnalyzed("js"); // Switch to a background thread await TaskScheduler.Default; analysisStatusNotifier.AnalysisStarted(filePath); try { await EnsureEslintBridgeClientIsInitialized(cancellationToken); var stopwatch = Stopwatch.StartNew(); var analysisResponse = await eslintBridgeClient.AnalyzeJs(filePath, cancellationToken); var numberOfIssues = analysisResponse.Issues?.Count() ?? 0; analysisStatusNotifier.AnalysisFinished(filePath, numberOfIssues, stopwatch.Elapsed); if (analysisResponse.ParsingError != null) { LogParsingError(filePath, analysisResponse.ParsingError); return; } var issues = ConvertIssues(filePath, analysisResponse.Issues); if (issues.Any()) { consumer.Accept(filePath, issues); } } catch (TaskCanceledException) { analysisStatusNotifier.AnalysisCancelled(filePath); } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { analysisStatusNotifier.AnalysisFailed(filePath, ex); } }