Skip to content

Commit e3c0f20

Browse files
vinistockandyw8
andauthored
Update Prism requirement to v0.28 (#2017)
Co-authored-by: Andy Waite <[email protected]>
1 parent 9f8390a commit e3c0f20

File tree

14 files changed

+4973
-3992
lines changed

14 files changed

+4973
-3992
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
os: [ubuntu-latest, macos-latest, windows-latest]
31-
ruby: ["3.0", "3.1", "3.2", "3.3"]
31+
ruby: ["3.1", "3.2", "3.3"]
3232
runs-on: ${{ matrix.os }}
3333
timeout-minutes: 30
3434
name: Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
@@ -86,6 +86,8 @@ jobs:
8686
# We need some Ruby installed for the environment activation tests
8787
- name: Set up Ruby
8888
uses: ruby/setup-ruby@v1
89+
with:
90+
bundler-cache: true
8991

9092
- name: Download shadowenv
9193
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PATH
1111
specs:
1212
ruby-lsp (0.16.7)
1313
language_server-protocol (~> 3.17.0)
14-
prism (>= 0.23.0, < 0.28)
14+
prism (>= 0.28.0, < 0.29)
1515
sorbet-runtime (>= 0.5.10782)
1616

1717
GEM
@@ -45,14 +45,14 @@ GEM
4545
ast (~> 2.4.1)
4646
racc
4747
prettier_print (1.2.1)
48-
prism (0.27.0)
48+
prism (0.28.0)
4949
psych (5.1.2)
5050
stringio
5151
racc (1.7.3)
5252
rainbow (3.1.1)
5353
rake (13.2.1)
54-
rbi (0.1.12)
55-
prism (>= 0.18.0, < 0.28)
54+
rbi (0.1.13)
55+
prism (>= 0.18.0, < 1.0.0)
5656
sorbet-runtime (>= 0.5.9204)
5757
regexp_parser (2.9.1)
5858
reline (0.5.0)
@@ -151,4 +151,4 @@ DEPENDENCIES
151151
tapioca (~> 0.13)
152152

153153
BUNDLED WITH
154-
2.5.6
154+
2.5.10

lib/core_ext/uri.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def from_path(path:, fragment: nil, scheme: "file")
1111
# On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
1212
escaped_path = if /^[A-Z]:/i.match?(path)
1313
DEFAULT_PARSER.escape("/#{path}")
14+
elsif path.start_with?("//?/")
15+
# Some paths on Windows start with "//?/". This is a special prefix that allows for long file paths
16+
DEFAULT_PARSER.escape(path.delete_prefix("//?"))
1417
else
1518
DEFAULT_PARSER.escape(path)
1619
end

lib/ruby_lsp/listeners/document_highlight.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def on_local_variable_read_node_enter(node)
271271
def on_constant_path_node_enter(node)
272272
return unless matches?(node, CONSTANT_PATH_NODES)
273273

274-
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
274+
add_highlight(Constant::DocumentHighlightKind::READ, node.name_loc)
275275
end
276276

277277
sig { params(node: Prism::ConstantReadNode).void }

lib/ruby_lsp/listeners/document_link.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def gem_paths
3030
lookup[spec.name] = {}
3131
lookup[spec.name][spec.version.to_s] = {}
3232

33-
Dir.glob("**/*.rb", base: "#{spec.full_gem_path}/").each do |path|
33+
Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
3434
lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
3535
end
3636
end

lib/ruby_lsp/listeners/semantic_highlighting.rb

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def initialize(dispatcher, response_builder, range: nil)
5858
:on_constant_operator_write_node_enter,
5959
:on_constant_or_write_node_enter,
6060
:on_constant_target_node_enter,
61+
:on_constant_path_node_enter,
6162
:on_local_variable_and_write_node_enter,
6263
:on_local_variable_operator_write_node_enter,
6364
:on_local_variable_or_write_node_enter,
@@ -302,17 +303,64 @@ def on_local_variable_target_node_enter(node)
302303
def on_class_node_enter(node)
303304
return unless visible?(node, @range)
304305

305-
@response_builder.add_token(node.constant_path.location, :class, [:declaration])
306+
constant_path = node.constant_path
307+
308+
if constant_path.is_a?(Prism::ConstantReadNode)
309+
@response_builder.add_token(constant_path.location, :class, [:declaration])
310+
else
311+
each_constant_path_part(constant_path) do |part|
312+
loc = case part
313+
when Prism::ConstantPathNode
314+
part.name_loc
315+
when Prism::ConstantReadNode
316+
part.location
317+
end
318+
next unless loc
319+
320+
@response_builder.add_token(loc, :class, [:declaration])
321+
end
322+
end
306323

307324
superclass = node.superclass
308-
@response_builder.add_token(superclass.location, :class) if superclass
325+
326+
if superclass.is_a?(Prism::ConstantReadNode)
327+
@response_builder.add_token(superclass.location, :class)
328+
elsif superclass
329+
each_constant_path_part(superclass) do |part|
330+
loc = case part
331+
when Prism::ConstantPathNode
332+
part.name_loc
333+
when Prism::ConstantReadNode
334+
part.location
335+
end
336+
next unless loc
337+
338+
@response_builder.add_token(loc, :class)
339+
end
340+
end
309341
end
310342

311343
sig { params(node: Prism::ModuleNode).void }
312344
def on_module_node_enter(node)
313345
return unless visible?(node, @range)
314346

315-
@response_builder.add_token(node.constant_path.location, :namespace, [:declaration])
347+
constant_path = node.constant_path
348+
349+
if constant_path.is_a?(Prism::ConstantReadNode)
350+
@response_builder.add_token(constant_path.location, :namespace, [:declaration])
351+
else
352+
each_constant_path_part(constant_path) do |part|
353+
loc = case part
354+
when Prism::ConstantPathNode
355+
part.name_loc
356+
when Prism::ConstantReadNode
357+
part.location
358+
end
359+
next unless loc
360+
361+
@response_builder.add_token(loc, :namespace, [:declaration])
362+
end
363+
end
316364
end
317365

318366
sig { params(node: Prism::ImplicitNode).void }
@@ -327,6 +375,14 @@ def on_implicit_node_leave(node)
327375
@inside_implicit_node = false
328376
end
329377

378+
sig { params(node: Prism::ConstantPathNode).void }
379+
def on_constant_path_node_enter(node)
380+
return if @inside_implicit_node
381+
return unless visible?(node, @range)
382+
383+
@response_builder.add_token(node.name_loc, :namespace)
384+
end
385+
330386
private
331387

332388
# Textmate provides highlighting for a subset of these special Ruby-specific methods. We want to utilize that

lib/ruby_lsp/requests/support/common.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ def namespace_constant_name(node)
167167
constant_name(path)
168168
end
169169
end
170+
171+
# Iterates over each part of a constant path, so that we can easily push response items for each section of the
172+
# name. For example, for `Foo::Bar::Baz`, this method will invoke the block with `Foo`, then `Bar` and finally
173+
# `Baz`.
174+
sig do
175+
params(
176+
node: Prism::Node,
177+
block: T.proc.params(part: Prism::Node).void,
178+
).void
179+
end
180+
def each_constant_path_part(node, &block)
181+
current = T.let(node, T.nilable(Prism::Node))
182+
183+
while current.is_a?(Prism::ConstantPathNode)
184+
block.call(current)
185+
current = current.parent
186+
end
187+
end
170188
end
171189
end
172190
end

ruby-lsp.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
1919
s.require_paths = ["lib"]
2020

2121
s.add_dependency("language_server-protocol", "~> 3.17.0")
22-
s.add_dependency("prism", ">= 0.23.0", "< 0.28")
22+
s.add_dependency("prism", ">= 0.28.0", "< 0.29")
2323
s.add_dependency("sorbet-runtime", ">= 0.5.10782")
2424

2525
s.required_ruby_version = ">= 3.0"

0 commit comments

Comments
 (0)