public async Task <IEnumerable <IInspectionResult> > FindIssuesAsync(RubberduckParserState state, CancellationToken token) { if (state == null || !state.AllUserDeclarations.Any()) { return(new IInspectionResult[] { }); } state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting); var config = _configService.LoadConfiguration(); UpdateInspectionSeverity(config); var allIssues = new ConcurrentBag <IInspectionResult>(); // Prepare ParseTreeWalker based inspections var parseTreeWalkResults = GetParseTreeResults(config, state); foreach (var parseTreeInspection in _inspections.OfType <IParseTreeInspection>().Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow)) { parseTreeInspection.SetResults(parseTreeWalkResults); } var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow) .Select(inspection => Task.Run(() => { token.ThrowIfCancellationRequested(); var inspectionResults = inspection.GetInspectionResults(); foreach (var inspectionResult in inspectionResults) { allIssues.Add(inspectionResult); } }, token)).ToList(); try { await Task.WhenAll(inspections); } catch (Exception e) { LogManager.GetCurrentClassLogger().Error(e); } var issuesByType = allIssues.GroupBy(issue => issue.GetType()) .ToDictionary(grouping => grouping.Key, grouping => grouping.ToList()); var results = issuesByType.Where(kv => kv.Value.Count <= AGGREGATION_THRESHOLD) .SelectMany(kv => kv.Value) .Union(issuesByType.Where(kv => kv.Value.Count > AGGREGATION_THRESHOLD) .Select(kv => new AggregateInspectionResult(kv.Value.OrderBy(i => i.QualifiedSelection).First(), kv.Value.Count))) .ToList(); state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status, CultureInfo.CurrentUICulture)); // should be "Ready" return(results); }
public async Task <IList <ICodeInspectionResult> > FindIssuesAsync(RubberduckParserState state, CancellationToken token) { if (state == null || !state.AllUserDeclarations.Any()) { return(new ICodeInspectionResult[] { }); } await Task.Yield(); state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting); UpdateInspectionSeverity(); //OnReset(); var allIssues = new ConcurrentBag <ICodeInspectionResult>(); var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow) .Select(inspection => new Task(() => { token.ThrowIfCancellationRequested(); var inspectionResults = inspection.GetInspectionResults(); var results = inspectionResults as IList <InspectionResultBase> ?? inspectionResults.ToList(); if (results.Any()) { //OnIssuesFound(results); foreach (var inspectionResult in results) { allIssues.Add(inspectionResult); } } })).ToArray(); foreach (var inspection in inspections) { inspection.Start(); } Task.WaitAll(inspections); state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status)); // should be "Ready" return(allIssues.ToList()); }
public async Task <IEnumerable <ICodeInspectionResult> > FindIssuesAsync(RubberduckParserState state, CancellationToken token) { if (state == null || !state.AllUserDeclarations.Any()) { return(new ICodeInspectionResult[] { }); } state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting); UpdateInspectionSeverity(); var allIssues = new ConcurrentBag <ICodeInspectionResult>(); // Prepare ParseTreeWalker based inspections var parseTreeWalkResults = GetParseTreeResults(state); foreach (var parseTreeInspection in _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow && inspection is IParseTreeInspection)) { (parseTreeInspection as IParseTreeInspection).ParseTreeResults = parseTreeWalkResults; } var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow) .Select(inspection => Task.Run(() => { token.ThrowIfCancellationRequested(); var inspectionResults = inspection.GetInspectionResults(); foreach (var inspectionResult in inspectionResults) { allIssues.Add(inspectionResult); } })).ToList(); await Task.WhenAll(inspections); state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status)); // should be "Ready" return(allIssues); }
public List <ICodeInspectionResult> Inspect(RubberduckParserState state) { if (state == null || !state.AllUserDeclarations.Any()) { return(new List <ICodeInspectionResult>()); } state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting); var allIssues = new ConcurrentBag <ICodeInspectionResult>(); // Prepare ParseTreeWalker based inspections var parseTreeWalkResults = GetParseTreeResults(state); foreach (var parseTreeInspection in _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow && inspection is IParseTreeInspection)) { (parseTreeInspection as IParseTreeInspection).ParseTreeResults = parseTreeWalkResults; } var inspections = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow) .Select(inspection => new Task(() => { var inspectionResults = inspection.GetInspectionResults(); foreach (var inspectionResult in inspectionResults) { allIssues.Add(inspectionResult); } })).ToArray(); foreach (var inspection in inspections) { inspection.Start(); } Task.WaitAll(inspections); return(allIssues.ToList()); }
public async Task <IEnumerable <IInspectionResult> > FindIssuesAsync(RubberduckParserState state, CancellationToken token) { if (state == null || !state.AllUserDeclarations.Any()) { return(new IInspectionResult[] { }); } token.ThrowIfCancellationRequested(); state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting); var allIssues = new ConcurrentBag <IInspectionResult>(); token.ThrowIfCancellationRequested(); var config = _configService.Read(); UpdateInspectionSeverity(config); token.ThrowIfCancellationRequested(); var parseTreeInspections = _inspections .Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow) .OfType <IParseTreeInspection>() .ToArray(); token.ThrowIfCancellationRequested(); foreach (var listener in parseTreeInspections.Select(inspection => inspection.Listener)) { listener.ClearContexts(); } // Prepare ParseTreeWalker based inspections var passes = Enum.GetValues(typeof(CodeKind)).Cast <CodeKind>(); foreach (var parsePass in passes) { try { WalkTrees(config, state, parseTreeInspections.Where(i => i.TargetKindOfCode == parsePass), parsePass); } catch (Exception e) { LogManager.GetCurrentClassLogger().Warn(e); } } token.ThrowIfCancellationRequested(); var inspectionsToRun = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow && RequiredLibrariesArePresent(inspection, state) && RequiredHostIsPresent(inspection)); token.ThrowIfCancellationRequested(); try { await Task.Run(() => RunInspectionsInParallel(inspectionsToRun, allIssues, token)); } catch (AggregateException exception) { if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException)) { //This eliminates the stack trace, but for the cancellation, this is irrelevant. throw exception.InnerException ?? exception; } LogManager.GetCurrentClassLogger().Error(exception); } catch (OperationCanceledException) { throw; } catch (Exception e) { LogManager.GetCurrentClassLogger().Error(e); } // should be "Ready" state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status, CultureInfo.CurrentUICulture)); return(allIssues); }
public async Task <IEnumerable <IInspectionResult> > FindIssuesAsync(RubberduckParserState state, CancellationToken token) { if (state == null || !state.AllUserDeclarations.Any()) { return(new IInspectionResult[] { }); } state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting); var allIssues = new ConcurrentBag <IInspectionResult>(); var config = _configService.LoadConfiguration(); UpdateInspectionSeverity(config); var parseTreeInspections = _inspections .Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow) .OfType <IParseTreeInspection>() .ToArray(); foreach (var listener in parseTreeInspections.Select(inspection => inspection.Listener)) { listener.ClearContexts(); } // Prepare ParseTreeWalker based inspections var passes = Enum.GetValues(typeof(ParsePass)).Cast <ParsePass>(); foreach (var parsePass in passes) { try { WalkTrees(config.UserSettings.CodeInspectionSettings, state, parseTreeInspections.Where(i => i.Pass == parsePass), parsePass); } catch (Exception e) { LogManager.GetCurrentClassLogger().Warn(e); } } var inspectionsToRun = _inspections.Where(inspection => inspection.Severity != CodeInspectionSeverity.DoNotShow); try { await Task.Run(() => RunInspectionsInParallel(inspectionsToRun, allIssues, token)); } catch (AggregateException exception) { if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException)) { LogManager.GetCurrentClassLogger().Debug("Inspections got canceled."); } else { LogManager.GetCurrentClassLogger().Error(exception); } } catch (Exception e) { LogManager.GetCurrentClassLogger().Error(e); } var issuesByType = allIssues.GroupBy(issue => issue.Inspection.Name) .ToDictionary(grouping => grouping.Key, grouping => grouping.ToList()); var results = issuesByType.Where(kv => kv.Value.Count <= AGGREGATION_THRESHOLD) .SelectMany(kv => kv.Value) .Union(issuesByType.Where(kv => kv.Value.Count > AGGREGATION_THRESHOLD) .Select(kv => new AggregateInspectionResult(kv.Value.OrderBy(i => i.QualifiedSelection).First(), kv.Value.Count))) .ToList(); state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status, CultureInfo.CurrentUICulture)); // should be "Ready" return(results); }