Class: ThemeCheck::LanguageServer::VariableLookupFinder::AssignmentsFinder::NodeHandler
- Inherits:
-
Object
- Object
- ThemeCheck::LanguageServer::VariableLookupFinder::AssignmentsFinder::NodeHandler
- Defined in:
- lib/theme_check/language_server/variable_lookup_finder/assignments_finder/node_handler.rb
Instance Method Summary collapse
- #on_assign(node, scope) ⇒ Object
-
#on_block_body(node, scope) ⇒ Object
Define a new scope every time a new block is created.
-
#on_table_row(node, scope) ⇒ Object
Table row tags do not rely on blocks to define scopes, so we index their value here.
Instance Method Details
#on_assign(node, scope) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/theme_check/language_server/variable_lookup_finder/assignments_finder/node_handler.rb', line 8 def on_assign(node, scope) # When a variable is redefined in a new scope we # no longer can guarantee the type in the global scope # # Example: # ```liquid # {%- liquid # assign var1 = some_value # # if condition # assign var1 = another_value # ^^^^ from here we no longer can guarantee # the type of `var1` in the global scope # -%} # ``` p_scope = scope while (p_scope = p_scope.parent) p_scope.variables.delete(node.value.to) end scope << node scope end |
#on_block_body(node, scope) ⇒ Object
Define a new scope every time a new block is created
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/theme_check/language_server/variable_lookup_finder/assignments_finder/node_handler.rb', line 44 def on_block_body(node, scope) scope = scope.new_child ## # 'for' tags handle blocks flattenly and differently # than the other tags (if, unless, case). # # The scope of 'for' tags exists only in the first # block, as the following one refers to the else # statement of the iteration. parent = node.parent scope << parent if parent.type_name == :for && parent.children.first == node scope end |
#on_table_row(node, scope) ⇒ Object
Table row tags do not rely on blocks to define scopes, so we index their value here
35 36 37 38 39 40 |
# File 'lib/theme_check/language_server/variable_lookup_finder/assignments_finder/node_handler.rb', line 35 def on_table_row(node, scope) scope = scope.new_child scope << node scope end |