Skip to content

Commit 5d4464c

Browse files
authored
Use parse_lex instead of parse for Ruby and ERB documents (#3252)
1 parent 79619ee commit 5d4464c

24 files changed

+71
-59
lines changed

lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DeclarationListener
99
#: Array[String]
1010
attr_reader :indexing_errors
1111

12-
#: (Index index, Prism::Dispatcher dispatcher, Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void
12+
#: (Index index, Prism::Dispatcher dispatcher, Prism::ParseLexResult | Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void
1313
def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
1414
@index = index
1515
@uri = uri

lib/ruby_lsp/erb_document.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
module RubyLsp
5-
#: [ParseResultType = Prism::ParseResult]
5+
#: [ParseResultType = Prism::ParseLexResult]
66
class ERBDocument < Document
77
#: String
88
attr_reader :host_language_source
@@ -31,11 +31,16 @@ def parse!
3131
@host_language_source = scanner.host_language
3232
# Use partial script to avoid syntax errors in ERB files where keywords may be used without the full context in
3333
# which they will be evaluated
34-
@parse_result = Prism.parse(scanner.ruby, partial_script: true)
34+
@parse_result = Prism.parse_lex(scanner.ruby, partial_script: true)
3535
@code_units_cache = @parse_result.code_units_cache(@encoding)
3636
true
3737
end
3838

39+
#: -> Prism::ProgramNode
40+
def ast
41+
@parse_result.value.first
42+
end
43+
3944
# @override
4045
#: -> bool
4146
def syntax_error?
@@ -53,7 +58,7 @@ def locate_node(position, node_types: [])
5358
char_position, _ = find_index_by_position(position)
5459

5560
RubyDocument.locate(
56-
@parse_result.value,
61+
ast,
5762
char_position,
5863
code_units_cache: @code_units_cache,
5964
node_types: node_types,

lib/ruby_lsp/requests/code_action_resolve.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def refactor_variable
100100

101101
# Find the closest statements node, so that we place the refactor in a valid position
102102
node_context = RubyDocument
103-
.locate(@document.parse_result.value,
103+
.locate(@document.ast,
104104
start_index,
105105
node_types: [
106106
Prism::StatementsNode,
@@ -207,7 +207,7 @@ def refactor_method
207207

208208
# Find the closest method declaration node, so that we place the refactor in a valid position
209209
node_context = RubyDocument.locate(
210-
@document.parse_result.value,
210+
@document.ast,
211211
start_index,
212212
node_types: [Prism::DefNode],
213213
code_units_cache: @document.code_units_cache,

lib/ruby_lsp/requests/completion.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize(document, global_state, params, sorbet_level, dispatcher)
3333
delegate_request_if_needed!(global_state, document, char_position)
3434

3535
node_context = RubyDocument.locate(
36-
document.parse_result.value,
36+
document.ast,
3737
char_position,
3838
node_types: [
3939
Prism::CallNode,

lib/ruby_lsp/requests/definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(document, global_state, position, dispatcher, sorbet_level)
2020
delegate_request_if_needed!(global_state, document, char_position)
2121

2222
node_context = RubyDocument.locate(
23-
document.parse_result.value,
23+
document.ast,
2424
char_position,
2525
node_types: [
2626
Prism::CallNode,

lib/ruby_lsp/requests/discover_tests.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def perform
4343
addon.create_discover_tests_listener(@response_builder, @dispatcher, @document.uri)
4444
end
4545

46-
@dispatcher.visit(@document.parse_result.value)
46+
@dispatcher.visit(@document.ast)
4747
else
4848
@global_state.synchronize do
4949
RubyIndexer::DeclarationListener.new(
@@ -64,7 +64,7 @@ def perform
6464
# Dispatch the events both for indexing the test file and discovering the tests. The order here is
6565
# important because we need the index to be aware of the existing classes/modules/methods before the test
6666
# listeners can do their work
67-
@dispatcher.visit(@document.parse_result.value)
67+
@dispatcher.visit(@document.ast)
6868
end
6969
end
7070

lib/ruby_lsp/requests/document_highlight.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(global_state, document, position, dispatcher)
2020
delegate_request_if_needed!(global_state, document, char_position)
2121

2222
node_context = RubyDocument.locate(
23-
document.parse_result.value,
23+
document.ast,
2424
char_position,
2525
code_units_cache: document.code_units_cache,
2626
)

lib/ruby_lsp/requests/hover.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(document, global_state, position, dispatcher, sorbet_level)
2424
delegate_request_if_needed!(global_state, document, char_position)
2525

2626
node_context = RubyDocument.locate(
27-
document.parse_result.value,
27+
document.ast,
2828
char_position,
2929
node_types: Listeners::Hover::ALLOWED_TARGETS,
3030
code_units_cache: document.code_units_cache,

lib/ruby_lsp/requests/prepare_rename.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def perform
2222
char_position, _ = @document.find_index_by_position(@position)
2323

2424
node_context = RubyDocument.locate(
25-
@document.parse_result.value,
25+
@document.ast,
2626
char_position,
2727
node_types: [Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode],
2828
code_units_cache: @document.code_units_cache,

lib/ruby_lsp/requests/references.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def perform
2626
char_position, _ = @document.find_index_by_position(position)
2727

2828
node_context = RubyDocument.locate(
29-
@document.parse_result.value,
29+
@document.ast,
3030
char_position,
3131
node_types: [
3232
Prism::ConstantReadNode,

0 commit comments

Comments
 (0)