protected override void Run()

in src/dotnet/PowerToys.CyclomaticComplexity/ComplexityAnalysisElementProblemAnalyzer.cs [51:100]


    protected override void Run(ITreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
    {
      // We get a fresh data for each file, so we can cache some state to make
      // things a bit more efficient
      var state = data.GetOrCreateDataUnderLock(key, () => new State
      {
        ControlFlowBuilder = LanguageManager.Instance.TryGetService<IControlFlowBuilder>(element.Language),
        Threshold = GetThreshold(data, element.Language)
      });

      if (state.ControlFlowBuilder == null || !state.ControlFlowBuilder.CanBuildFrom(element))
        return;

      // We can build control flow information for a JS file section (e.g. inline event handlers, or <src>
      // elements in html) and it would be nice to flag these up as being too complex, but there's nowhere
      // to put the warning - it highlights the whole section. Maybe that's ok for when we're over the threshold,
      // but it's definitely not ok for the info tooltip.
      if (element is IJavaScriptFileSection)
        return;

      var graph = data.GetOrBuildControlFlowGraph(element);
      if (graph == null)
        return;

      var complexity = CalculateCyclomaticComplexity(graph);
      var documentRange = GetDocumentRange(element);

      if (complexity > state.Threshold)
      {
        consumer.AddHighlighting(
          new ComplexityWarningHighlight(
            GetMessage(element, complexity, state.Threshold),
            documentRange));
      }
#if !RIDER
      else
        consumer.AddHighlighting(new ComplexityInfoHighlight(GetMessage(element, complexity, state.Threshold), documentRange));
#else
      if (element is ITypeMemberDeclaration memberDeclaration && memberDeclaration.DeclaredElement != null)
      {
        var percentage = GetPercentage(complexity, state.Threshold);
        consumer.AddHighlighting(new ComplexityCodeInsightsHighlight(
          memberDeclaration,
          complexity,
          percentage,
          _provider,
          _iconHost));
      }
#endif
    }