# File lib/ruby_lsp/document.rb, line 75defcache_get(request_name)
@cache[request_name]
end
cache_set(request_name, value)
# File lib/ruby_lsp/document.rb, line 70defcache_set(request_name, value)
@cache[request_name] = valueend
comments()
# File lib/ruby_lsp/document.rb, line 43defcomments@parse_result.commentsend
create_scanner()
# File lib/ruby_lsp/document.rb, line 105defcreate_scannerScanner.new(@source, @encoding)
end
locate(node, char_position, node_types: [])
# File lib/ruby_lsp/document.rb, line 126deflocate(node, char_position, node_types: [])
queue = T.let(node.child_nodes.compact, T::Array[T.nilable(Prism::Node)])
closest = nodeparent = T.let(nil, T.nilable(Prism::Node))
nesting = T.let([], T::Array[T.any(Prism::ClassNode, Prism::ModuleNode)])
untilqueue.empty?candidate = queue.shift# Skip nil child nodesnextifcandidate.nil?# Add the next child_nodes to the queue to be processed. The order here is important! We want to move in the# same order as the visiting mechanism, which means searching the child nodes before moving on to the next# siblingT.unsafe(queue).unshift(*candidate.child_nodes)
# Skip if the current node doesn't cover the desired positionloc = candidate.locationnextunless (loc.start_offset...loc.end_offset).cover?(char_position)
# If the node's start character is already past the position, then we should've found the closest node# alreadybreakifchar_position<loc.start_offset# If the candidate starts after the end of the previous nesting level, then we've exited that nesting level and# need to pop the stackprevious_level = nesting.lastnesting.popifprevious_level&&loc.start_offset>previous_level.location.end_offset# Keep track of the nesting where we found the target. This is used to determine the fully qualified name of the# target when it is a constantifcandidate.is_a?(Prism::ClassNode) ||candidate.is_a?(Prism::ModuleNode)
nesting<<candidateend# If there are node types to filter by, and the current node is not one of those types, then skip itnextifnode_types.any?&&node_types.none? { |type|candidate.class==type }
# If the current node is narrower than or equal to the previous closest node, then it is more preciseclosest_loc = closest.locationifloc.end_offset-loc.start_offset<=closest_loc.end_offset-closest_loc.start_offsetparent = closestclosest = candidateendend
[closest, parent, nesting.map { |n|n.constant_path.location.slice }]
end
locate_node(position, node_types: [])
# File lib/ruby_lsp/document.rb, line 115deflocate_node(position, node_types: [])
locate(@parse_result.value, create_scanner.find_char_position(position), node_types:node_types)
end
parse()
# File lib/ruby_lsp/document.rb, line 97defparse; end