Sha256: 6781b547e8b5f1ccd0fd0eb2c0db4b19aa6eda4d128ba3dc98c4eb7299de7b75

Contents?: true

Size: 1.9 KB

Versions: 4

Compression:

Stored size: 1.9 KB

Contents

module Yoda
  module Evaluation
    # CurrentNodeExplain shows help for the current node.
    class CurrentNodeExplain
      # @return [Store::Registry]
      attr_reader :registry

      # @return [String]
      attr_reader :source

      # @return [Parsing::Location]
      attr_reader :location

      # @param registry [Store::Registry]
      # @param source   [String]
      # @param location [Parsing::Location]
      def initialize(registry, source, location)
        @registry = registry
        @source = source
        @location = location
      end

      # @return [Model::NodeSignature, nil]
      def current_node_signature
        return nil if !valid? || !current_node_trace
        @current_node_signature ||= Model::NodeSignature.new(current_node, current_node_trace)
      end

      # @return [true, false]
      def valid?
        !!(current_node)
      end

      # @return [Array<(String, Integer, Integer)>]
      def defined_files
        return [] if !valid? || !current_node_trace
        case current_node.type
        when :send
          current_node_trace.functions.map { |function| function.primary_source }.compact
        when :const
          current_node_trace.values.map { |value| value.primary_source || value.sources.first }.compact
        else
          []
        end
      end

      private

      # @return [Typing::Traces::Base, nil]
      def current_node_trace
        return nil unless valid?
        @current_node_trace ||= evaluator.calculate_trace(current_node)
      end

      # @return [Parser::AST::Node]
      def current_node
        analyzer.nodes_to_current_location_from_root.last
      end

      # @return [Evaluator]
      def evaluator
        @evaluator ||= Evaluator.from_ast(registry, analyzer.ast, location)
      end

      # @return [SourceAnalyzer]
      def analyzer
        @analyzer ||= Parsing::SourceAnalyzer.from_source(source, location)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.7.2 lib/yoda/evaluation/current_node_explain.rb
yoda-language-server-0.7.1 lib/yoda/evaluation/current_node_explain.rb
yoda-language-server-0.7.0 lib/yoda/evaluation/current_node_explain.rb
yoda-language-server-0.6.2 lib/yoda/evaluation/current_node_explain.rb