Sha256: 6d924a81fababe1e73aa409f837479b988821decc5ababa436e53ef5198e7a70

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  module LanguageServer
    module VariableLookupFinder
      class AssignmentsFinder
        class ScopeVisitor
          SCOPE_UNAWARE_NODES = %i(range range_lookup variable variable_lookup)

          attr_reader :global_scope, :current_scope

          def initialize
            @node_handler = NodeHandler.new
            @global_scope = Scope.new({})
            @current_scope = Scope.new({})
          end

          def visit_template(template)
            return unless template

            visit(liquid_node(template), global_scope)
          end

          private

          def visit(node, scope)
            return if SCOPE_UNAWARE_NODES.include?(node.type_name)

            method = :"on_#{node.type_name}"
            scope = @node_handler.send(method, node, scope) if @node_handler.respond_to?(method)

            @current_scope = scope

            node.children.each { |child| visit(child, scope) }
          end

          def liquid_node(template)
            LiquidNode.new(template.root, nil, template)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/language_server/variable_lookup_finder/assignments_finder/scope_visitor.rb
theme-check-1.14.0 lib/theme_check/language_server/variable_lookup_finder/assignments_finder/scope_visitor.rb
theme-check-1.13.0 lib/theme_check/language_server/variable_lookup_finder/assignments_finder/scope_visitor.rb
theme-check-1.12.1 lib/theme_check/language_server/variable_lookup_finder/assignments_finder/scope_visitor.rb