Skip to content

Commit 28955f3

Browse files
authored
Migrate to Prism (#1090)
* Migrate to Prism * Update ShowSyntaxTreeTest * Remove obsolete submodule * Remove obsolete overrides
1 parent 71e5cb3 commit 28955f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+22328
-20264
lines changed

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ updates:
1515
- "minor"
1616
- "patch"
1717
exclude-patterns:
18-
- "yarp"
18+
- "prism"
1919
- package-ecosystem: "gitsubmodule"
2020
directory: "/"
2121
schedule:

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "test/fixtures/yarp"]
2-
path = test/fixtures/yarp
3-
url = https://github.com/ruby/yarp.git
1+
[submodule "test/fixtures/prism"]
2+
path = test/fixtures/prism
3+
url = https://github.com/ruby/prism.git

ADDONS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ module RubyLsp
157157

158158
# Listeners must define methods for each event they registered with the emitter. In this case, we have to define
159159
# `on_const` to specify what this listener should do every time we find a constant
160-
sig { params(node: YARP::ConstantReadNode).void }
160+
sig { params(node: Prism::ConstantReadNode).void }
161161
def on_constant_read(node)
162162
# Certain helpers are made available to listeners to build LSP responses. The classes under `RubyLsp::Interface`
163163
# are generally used to build responses and they match exactly what the specification requests.

Gemfile.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ PATH
33
specs:
44
ruby-lsp (0.11.2)
55
language_server-protocol (~> 3.17.0)
6+
prism (>= 0.13, < 0.14)
67
sorbet-runtime (>= 0.5.5685)
7-
yarp (>= 0.12, < 0.13)
88

99
GEM
1010
remote: https://rubygems.org/
@@ -37,6 +37,7 @@ GEM
3737
ast (~> 2.4.1)
3838
racc
3939
prettier_print (1.2.1)
40+
prism (0.13.0)
4041
psych (5.1.0)
4142
stringio
4243
racc (1.7.1)
@@ -106,7 +107,7 @@ GEM
106107
yard-sorbet (0.8.1)
107108
sorbet-runtime (>= 0.5)
108109
yard (>= 0.9)
109-
yarp (0.12.0)
110+
yarp (0.13.0)
110111

111112
PLATFORMS
112113
arm64-darwin

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require "ruby_lsp/check_docs"
88
Rake::TestTask.new(:test) do |t|
99
t.libs << "test"
1010
t.libs << "lib"
11-
t.test_files = FileList["test/**/*_test.rb", "lib/ruby_indexer/test/**/*_test.rb"].exclude("test/fixtures/yarp/**/*")
11+
t.test_files = FileList["test/**/*_test.rb", "lib/ruby_indexer/test/**/*_test.rb"].exclude("test/fixtures/prism/**/*")
1212
end
1313

1414
RDoc::Task.new do |rdoc|

bin/test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
PRISM_FIXTURES_DIR=test/fixtures/yarp/test/prism/fixtures
3+
PRISM_FIXTURES_DIR=test/fixtures/prism/test/prism/fixtures
44

55
if [ ! -d "$PRISM_FIXTURES_DIR" ]; then
66
echo "$PRISM_FIXTURES_DIR does not exist."

lib/ruby_indexer/lib/ruby_indexer/index.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def index_all(indexable_paths: RubyIndexer.configuration.indexables, &block)
179179
sig { params(indexable_path: IndexablePath, source: T.nilable(String)).void }
180180
def index_single(indexable_path, source = nil)
181181
content = source || File.read(indexable_path.full_path)
182-
result = YARP.parse(content)
182+
result = Prism.parse(content)
183183
visitor = IndexVisitor.new(self, result, indexable_path.full_path)
184184
result.value.accept(visitor)
185185

@@ -262,7 +262,7 @@ class Entry
262262
sig { returns(String) }
263263
attr_reader :file_path
264264

265-
sig { returns(YARP::Location) }
265+
sig { returns(Prism::Location) }
266266
attr_reader :location
267267

268268
sig { returns(T::Array[String]) }
@@ -271,7 +271,7 @@ class Entry
271271
sig { returns(Symbol) }
272272
attr_accessor :visibility
273273

274-
sig { params(name: String, file_path: String, location: YARP::Location, comments: T::Array[String]).void }
274+
sig { params(name: String, file_path: String, location: Prism::Location, comments: T::Array[String]).void }
275275
def initialize(name, file_path, location, comments)
276276
@name = name
277277
@file_path = file_path
@@ -326,7 +326,7 @@ class UnresolvedAlias < Entry
326326
nesting: T::Array[String],
327327
name: String,
328328
file_path: String,
329-
location: YARP::Location,
329+
location: Prism::Location,
330330
comments: T::Array[String],
331331
).void
332332
end

lib/ruby_indexer/lib/ruby_indexer/visitor.rb

+45-45
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# frozen_string_literal: true
33

44
module RubyIndexer
5-
class IndexVisitor < YARP::Visitor
5+
class IndexVisitor < Prism::Visitor
66
extend T::Sig
77

8-
sig { params(index: Index, parse_result: YARP::ParseResult, file_path: String).void }
8+
sig { params(index: Index, parse_result: Prism::ParseResult, file_path: String).void }
99
def initialize(index, parse_result, file_path)
1010
@index = index
1111
@file_path = file_path
@@ -14,125 +14,125 @@ def initialize(index, parse_result, file_path)
1414
parse_result.comments.to_h do |c|
1515
[c.location.start_line, c]
1616
end,
17-
T::Hash[Integer, YARP::Comment],
17+
T::Hash[Integer, Prism::Comment],
1818
)
1919

2020
super()
2121
end
2222

23-
sig { override.params(node: YARP::ClassNode).void }
23+
sig { override.params(node: Prism::ClassNode).void }
2424
def visit_class_node(node)
2525
add_index_entry(node, Index::Entry::Class)
2626
end
2727

28-
sig { override.params(node: YARP::ModuleNode).void }
28+
sig { override.params(node: Prism::ModuleNode).void }
2929
def visit_module_node(node)
3030
add_index_entry(node, Index::Entry::Module)
3131
end
3232

33-
sig { override.params(node: YARP::MultiWriteNode).void }
33+
sig { override.params(node: Prism::MultiWriteNode).void }
3434
def visit_multi_write_node(node)
3535
value = node.value
36-
values = value.is_a?(YARP::ArrayNode) && value.opening_loc ? value.elements : []
36+
values = value.is_a?(Prism::ArrayNode) && value.opening_loc ? value.elements : []
3737

3838
node.targets.each_with_index do |target, i|
3939
current_value = values[i]
4040
# The moment we find a splat on the right hand side of the assignment, we can no longer figure out which value
4141
# gets assigned to what
42-
values.clear if current_value.is_a?(YARP::SplatNode)
42+
values.clear if current_value.is_a?(Prism::SplatNode)
4343

4444
case target
45-
when YARP::ConstantTargetNode
45+
when Prism::ConstantTargetNode
4646
add_constant(target, fully_qualify_name(target.name.to_s), current_value)
47-
when YARP::ConstantPathTargetNode
47+
when Prism::ConstantPathTargetNode
4848
add_constant(target, fully_qualify_name(target.slice), current_value)
4949
end
5050
end
5151
end
5252

53-
sig { override.params(node: YARP::ConstantPathWriteNode).void }
53+
sig { override.params(node: Prism::ConstantPathWriteNode).void }
5454
def visit_constant_path_write_node(node)
5555
# ignore variable constants like `var::FOO` or `self.class::FOO`
5656
target = node.target
57-
return unless target.parent.nil? || target.parent.is_a?(YARP::ConstantReadNode)
57+
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
5858

5959
name = fully_qualify_name(target.location.slice)
6060
add_constant(node, name)
6161
end
6262

63-
sig { override.params(node: YARP::ConstantPathOrWriteNode).void }
63+
sig { override.params(node: Prism::ConstantPathOrWriteNode).void }
6464
def visit_constant_path_or_write_node(node)
6565
# ignore variable constants like `var::FOO` or `self.class::FOO`
6666
target = node.target
67-
return unless target.parent.nil? || target.parent.is_a?(YARP::ConstantReadNode)
67+
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
6868

6969
name = fully_qualify_name(target.location.slice)
7070
add_constant(node, name)
7171
end
7272

73-
sig { override.params(node: YARP::ConstantPathOperatorWriteNode).void }
73+
sig { override.params(node: Prism::ConstantPathOperatorWriteNode).void }
7474
def visit_constant_path_operator_write_node(node)
7575
# ignore variable constants like `var::FOO` or `self.class::FOO`
7676
target = node.target
77-
return unless target.parent.nil? || target.parent.is_a?(YARP::ConstantReadNode)
77+
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
7878

7979
name = fully_qualify_name(target.location.slice)
8080
add_constant(node, name)
8181
end
8282

83-
sig { override.params(node: YARP::ConstantPathAndWriteNode).void }
83+
sig { override.params(node: Prism::ConstantPathAndWriteNode).void }
8484
def visit_constant_path_and_write_node(node)
8585
# ignore variable constants like `var::FOO` or `self.class::FOO`
8686
target = node.target
87-
return unless target.parent.nil? || target.parent.is_a?(YARP::ConstantReadNode)
87+
return unless target.parent.nil? || target.parent.is_a?(Prism::ConstantReadNode)
8888

8989
name = fully_qualify_name(target.location.slice)
9090
add_constant(node, name)
9191
end
9292

93-
sig { override.params(node: YARP::ConstantWriteNode).void }
93+
sig { override.params(node: Prism::ConstantWriteNode).void }
9494
def visit_constant_write_node(node)
9595
name = fully_qualify_name(node.name.to_s)
9696
add_constant(node, name)
9797
end
9898

99-
sig { override.params(node: YARP::ConstantOrWriteNode).void }
99+
sig { override.params(node: Prism::ConstantOrWriteNode).void }
100100
def visit_constant_or_write_node(node)
101101
name = fully_qualify_name(node.name.to_s)
102102
add_constant(node, name)
103103
end
104104

105-
sig { override.params(node: YARP::ConstantAndWriteNode).void }
105+
sig { override.params(node: Prism::ConstantAndWriteNode).void }
106106
def visit_constant_and_write_node(node)
107107
name = fully_qualify_name(node.name.to_s)
108108
add_constant(node, name)
109109
end
110110

111-
sig { override.params(node: YARP::ConstantOperatorWriteNode).void }
111+
sig { override.params(node: Prism::ConstantOperatorWriteNode).void }
112112
def visit_constant_operator_write_node(node)
113113
name = fully_qualify_name(node.name.to_s)
114114
add_constant(node, name)
115115
end
116116

117-
sig { override.params(node: YARP::CallNode).void }
117+
sig { override.params(node: Prism::CallNode).void }
118118
def visit_call_node(node)
119119
message = node.message
120120
handle_private_constant(node) if message == "private_constant"
121121
end
122122

123123
private
124124

125-
sig { params(node: YARP::CallNode).void }
125+
sig { params(node: Prism::CallNode).void }
126126
def handle_private_constant(node)
127127
arguments = node.arguments&.arguments
128128
return unless arguments
129129

130130
first_argument = arguments.first
131131

132132
name = case first_argument
133-
when YARP::StringNode
133+
when Prism::StringNode
134134
first_argument.content
135-
when YARP::SymbolNode
135+
when Prism::SymbolNode
136136
first_argument.value
137137
end
138138

@@ -150,37 +150,37 @@ def handle_private_constant(node)
150150
sig do
151151
params(
152152
node: T.any(
153-
YARP::ConstantWriteNode,
154-
YARP::ConstantOrWriteNode,
155-
YARP::ConstantAndWriteNode,
156-
YARP::ConstantOperatorWriteNode,
157-
YARP::ConstantPathWriteNode,
158-
YARP::ConstantPathOrWriteNode,
159-
YARP::ConstantPathOperatorWriteNode,
160-
YARP::ConstantPathAndWriteNode,
161-
YARP::ConstantTargetNode,
162-
YARP::ConstantPathTargetNode,
153+
Prism::ConstantWriteNode,
154+
Prism::ConstantOrWriteNode,
155+
Prism::ConstantAndWriteNode,
156+
Prism::ConstantOperatorWriteNode,
157+
Prism::ConstantPathWriteNode,
158+
Prism::ConstantPathOrWriteNode,
159+
Prism::ConstantPathOperatorWriteNode,
160+
Prism::ConstantPathAndWriteNode,
161+
Prism::ConstantTargetNode,
162+
Prism::ConstantPathTargetNode,
163163
),
164164
name: String,
165-
value: T.nilable(YARP::Node),
165+
value: T.nilable(Prism::Node),
166166
).void
167167
end
168168
def add_constant(node, name, value = nil)
169-
value = node.value unless node.is_a?(YARP::ConstantTargetNode) || node.is_a?(YARP::ConstantPathTargetNode)
169+
value = node.value unless node.is_a?(Prism::ConstantTargetNode) || node.is_a?(Prism::ConstantPathTargetNode)
170170
comments = collect_comments(node)
171171

172172
@index << case value
173-
when YARP::ConstantReadNode, YARP::ConstantPathNode
173+
when Prism::ConstantReadNode, Prism::ConstantPathNode
174174
Index::Entry::UnresolvedAlias.new(value.slice, @stack.dup, name, @file_path, node.location, comments)
175-
when YARP::ConstantWriteNode, YARP::ConstantAndWriteNode, YARP::ConstantOrWriteNode,
176-
YARP::ConstantOperatorWriteNode
175+
when Prism::ConstantWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOrWriteNode,
176+
Prism::ConstantOperatorWriteNode
177177

178178
# If the right hand side is another constant assignment, we need to visit it because that constant has to be
179179
# indexed too
180180
visit(value)
181181
Index::Entry::UnresolvedAlias.new(value.name.to_s, @stack.dup, name, @file_path, node.location, comments)
182-
when YARP::ConstantPathWriteNode, YARP::ConstantPathOrWriteNode, YARP::ConstantPathOperatorWriteNode,
183-
YARP::ConstantPathAndWriteNode
182+
when Prism::ConstantPathWriteNode, Prism::ConstantPathOrWriteNode, Prism::ConstantPathOperatorWriteNode,
183+
Prism::ConstantPathAndWriteNode
184184

185185
visit(value)
186186
Index::Entry::UnresolvedAlias.new(value.target.slice, @stack.dup, name, @file_path, node.location, comments)
@@ -189,7 +189,7 @@ def add_constant(node, name, value = nil)
189189
end
190190
end
191191

192-
sig { params(node: T.any(YARP::ClassNode, YARP::ModuleNode), klass: T.class_of(Index::Entry)).void }
192+
sig { params(node: T.any(Prism::ClassNode, Prism::ModuleNode), klass: T.class_of(Index::Entry)).void }
193193
def add_index_entry(node, klass)
194194
name = node.constant_path.location.slice
195195

@@ -204,7 +204,7 @@ def add_index_entry(node, klass)
204204
@stack.pop
205205
end
206206

207-
sig { params(node: YARP::Node).returns(T::Array[String]) }
207+
sig { params(node: Prism::Node).returns(T::Array[String]) }
208208
def collect_comments(node)
209209
comments = []
210210

0 commit comments

Comments
 (0)