Public Instance Methods
on_alias_method_node_enter(node)
def on_alias_method_node_enter(node)
new_name_node = node.new_name
return unless new_name_node.is_a?(Prism::SymbolNode)
name = new_name_node.value
return unless name
create_document_symbol(
name: name,
kind: Constant::SymbolKind::METHOD,
range_location: new_name_node.location,
selection_range_location: T.must(new_name_node.value_loc),
)
end
on_call_node_enter(node)
def on_call_node_enter(node)
node_name = node.name
if ATTR_ACCESSORS.include?(node_name)
handle_attr_accessor(node)
elsif node_name == :alias_method
handle_alias_method(node)
elsif node_name == :namespace
handle_rake_namespace(node)
elsif node_name == :task
handle_rake_task(node)
end
end
on_call_node_leave(node)
def on_call_node_leave(node)
return unless rake?
if node.name == :namespace && !node.receiver
@response_builder.pop
end
end
on_class_node_enter(node)
def on_class_node_enter(node)
@response_builder << create_document_symbol(
name: node.constant_path.location.slice,
kind: Constant::SymbolKind::CLASS,
range_location: node.location,
selection_range_location: node.constant_path.location,
)
end
on_class_node_leave(node)
def on_class_node_leave(node)
@response_builder.pop
end
on_class_variable_write_node_enter(node)
def on_class_variable_write_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::VARIABLE,
range_location: node.name_loc,
selection_range_location: node.name_loc,
)
end
on_constant_and_write_node_enter(node)
def on_constant_and_write_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.name_loc,
)
end
on_constant_operator_write_node_enter(node)
def on_constant_operator_write_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.name_loc,
)
end
on_constant_or_write_node_enter(node)
def on_constant_or_write_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.name_loc,
)
end
on_constant_path_and_write_node_enter(node)
def on_constant_path_and_write_node_enter(node)
create_document_symbol(
name: node.target.location.slice,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.target.location,
)
end
on_constant_path_operator_write_node_enter(node)
def on_constant_path_operator_write_node_enter(node)
create_document_symbol(
name: node.target.location.slice,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.target.location,
)
end
on_constant_path_or_write_node_enter(node)
def on_constant_path_or_write_node_enter(node)
create_document_symbol(
name: node.target.location.slice,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.target.location,
)
end
on_constant_path_target_node_enter(node)
def on_constant_path_target_node_enter(node)
create_document_symbol(
name: node.slice,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.location,
)
end
on_constant_path_write_node_enter(node)
def on_constant_path_write_node_enter(node)
create_document_symbol(
name: node.target.location.slice,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.target.location,
)
end
on_constant_target_node_enter(node)
def on_constant_target_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.location,
)
end
on_constant_write_node_enter(node)
def on_constant_write_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::CONSTANT,
range_location: node.location,
selection_range_location: node.name_loc,
)
end
on_def_node_enter(node)
def on_def_node_enter(node)
receiver = node.receiver
previous_symbol = @response_builder.last
if receiver.is_a?(Prism::SelfNode)
name = "self.#{node.name}"
kind = Constant::SymbolKind::FUNCTION
elsif previous_symbol.is_a?(Interface::DocumentSymbol) && previous_symbol.name.start_with?("<<")
name = node.name.to_s
kind = Constant::SymbolKind::FUNCTION
else
name = node.name.to_s
kind = name == "initialize" ? Constant::SymbolKind::CONSTRUCTOR : Constant::SymbolKind::METHOD
end
symbol = create_document_symbol(
name: name,
kind: kind,
range_location: node.location,
selection_range_location: node.name_loc,
)
@response_builder << symbol
end
on_def_node_leave(node)
def on_def_node_leave(node)
@response_builder.pop
end
on_instance_variable_write_node_enter(node)
def on_instance_variable_write_node_enter(node)
create_document_symbol(
name: node.name.to_s,
kind: Constant::SymbolKind::VARIABLE,
range_location: node.name_loc,
selection_range_location: node.name_loc,
)
end
on_module_node_enter(node)
def on_module_node_enter(node)
@response_builder << create_document_symbol(
name: node.constant_path.location.slice,
kind: Constant::SymbolKind::MODULE,
range_location: node.location,
selection_range_location: node.constant_path.location,
)
end
on_module_node_leave(node)
def on_module_node_leave(node)
@response_builder.pop
end
on_singleton_class_node_enter(node)
def on_singleton_class_node_enter(node)
expression = node.expression
@response_builder << create_document_symbol(
name: "<< #{expression.slice}",
kind: Constant::SymbolKind::NAMESPACE,
range_location: node.location,
selection_range_location: expression.location,
)
end
on_singleton_class_node_leave(node)
def on_singleton_class_node_leave(node)
@response_builder.pop
end