Skip to content

Commit 4538672

Browse files
authored
Update collect_references to use Prism::LexResult (#3590)
Update collect_references to use Prism::LexResult In #3252, `RubyDocument#parse_result` becomes `Prism::ParseLexResult`, which's `value` is an array instead of a single node. And we forgot to update `collect_references` to account for this change because the codepath was not covered in the test. So this commit adds a test for the codepath and updates `collect_references` to use `Prism::LexResult`.
1 parent 95a44a4 commit 4538672

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/ruby_lsp/requests/references.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def perform
6666
# of reading from disk
6767
next if @store.key?(uri)
6868

69-
parse_result = Prism.parse_file(path)
69+
parse_result = Prism.parse_lex_file(path)
7070
collect_references(reference_target, parse_result, uri)
7171
rescue Errno::EISDIR, Errno::ENOENT
7272
# If `path` is a directory, just ignore it and continue. If the file doesn't exist, then we also ignore it.
@@ -111,7 +111,7 @@ def create_reference_target(target_node, node_context)
111111
end
112112
end
113113

114-
#: (RubyIndexer::ReferenceFinder::Target target, Prism::ParseResult parse_result, URI::Generic uri) -> void
114+
#: (RubyIndexer::ReferenceFinder::Target target, Prism::LexResult parse_result, URI::Generic uri) -> void
115115
def collect_references(target, parse_result, uri)
116116
dispatcher = Prism::Dispatcher.new
117117
finder = RubyIndexer::ReferenceFinder.new(
@@ -121,7 +121,7 @@ def collect_references(target, parse_result, uri)
121121
uri,
122122
include_declarations: @params.dig(:context, :includeDeclaration) || true,
123123
)
124-
dispatcher.visit(parse_result.value)
124+
dispatcher.visit(parse_result.value.first)
125125

126126
finder.references.each do |reference|
127127
@locations << Interface::Location.new(

test/requests/references_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def find_references(fixture_path, position)
2828
global_state: global_state,
2929
)
3030

31+
# In addition to glob files from the workspace, we also want to test references collection from the store
32+
store.set(uri: URI::Generic.from_path(path: path), source: source, version: 1, language_id: :ruby)
33+
3134
RubyLsp::Requests::References.new(
3235
global_state,
3336
store,

0 commit comments

Comments
 (0)