In this talk, we discuss static analysis, DSLs and the intersection between the two. We then get into the new Ruby LSP add-on APIs that allow gems to handle different types of DSL from a static analysis perspective.
this listener to handle method defs dispatcher.register(self, :on_def_node_enter) end # Define what happens when we find a method def def on_def_node_enter(node) @response_builder < < node end end
specific class/module @listener.add_method(…) # Register a new class or module # Advances stack so that the context will be inside # that new namespace @listener.add_module(…) @listener.add_class(…) # Pops name stack (leaves the current namespace) @listener.pop_namespace_stack
= node.name return unless name = = :belongs_to first_arg = node.arguments&.arguments&.first unless first_arg.is_a?(Prism : : SymbolNode) return end end end
Factory to register listeners def create_definition_listener( response_builder, uri, node_context, dispatcher) # Hook a new listener to the response builder # and dispatcher MyGem : : DefinitionListener.new( . . . ) end end end
call surrouding this # this symbol a validate call? surrounding_call = @node_context.call_node unless surrounding_call.name = = :validate return end end end end