Skip to content

Commit

Permalink
Update Prism requirement to v0.28 (#2017)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Waite <andyw8@users.noreply.github.com>
  • Loading branch information
vinistock and andyw8 committed May 16, 2024
1 parent 9f8390a commit e3c0f20
Show file tree
Hide file tree
Showing 14 changed files with 4,973 additions and 3,992 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ruby: ["3.0", "3.1", "3.2", "3.3"]
ruby: ["3.1", "3.2", "3.3"]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
name: Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
Expand Down Expand Up @@ -86,6 +86,8 @@ jobs:
# We need some Ruby installed for the environment activation tests
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Download shadowenv
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PATH
specs:
ruby-lsp (0.16.7)
language_server-protocol (~> 3.17.0)
prism (>= 0.23.0, < 0.28)
prism (>= 0.28.0, < 0.29)
sorbet-runtime (>= 0.5.10782)

GEM
Expand Down Expand Up @@ -45,14 +45,14 @@ GEM
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
prism (0.27.0)
prism (0.28.0)
psych (5.1.2)
stringio
racc (1.7.3)
rainbow (3.1.1)
rake (13.2.1)
rbi (0.1.12)
prism (>= 0.18.0, < 0.28)
rbi (0.1.13)
prism (>= 0.18.0, < 1.0.0)
sorbet-runtime (>= 0.5.9204)
regexp_parser (2.9.1)
reline (0.5.0)
Expand Down Expand Up @@ -151,4 +151,4 @@ DEPENDENCIES
tapioca (~> 0.13)

BUNDLED WITH
2.5.6
2.5.10
3 changes: 3 additions & 0 deletions lib/core_ext/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def from_path(path:, fragment: nil, scheme: "file")
# On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
escaped_path = if /^[A-Z]:/i.match?(path)
DEFAULT_PARSER.escape("/#{path}")
elsif path.start_with?("//?/")
# Some paths on Windows start with "//?/". This is a special prefix that allows for long file paths
DEFAULT_PARSER.escape(path.delete_prefix("//?"))
else
DEFAULT_PARSER.escape(path)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/listeners/document_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def on_local_variable_read_node_enter(node)
def on_constant_path_node_enter(node)
return unless matches?(node, CONSTANT_PATH_NODES)

add_highlight(Constant::DocumentHighlightKind::READ, node.location)
add_highlight(Constant::DocumentHighlightKind::READ, node.name_loc)
end

sig { params(node: Prism::ConstantReadNode).void }
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/listeners/document_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def gem_paths
lookup[spec.name] = {}
lookup[spec.name][spec.version.to_s] = {}

Dir.glob("**/*.rb", base: "#{spec.full_gem_path}/").each do |path|
Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
end
end
Expand Down
62 changes: 59 additions & 3 deletions lib/ruby_lsp/listeners/semantic_highlighting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def initialize(dispatcher, response_builder, range: nil)
:on_constant_operator_write_node_enter,
:on_constant_or_write_node_enter,
:on_constant_target_node_enter,
:on_constant_path_node_enter,
:on_local_variable_and_write_node_enter,
:on_local_variable_operator_write_node_enter,
:on_local_variable_or_write_node_enter,
Expand Down Expand Up @@ -302,17 +303,64 @@ def on_local_variable_target_node_enter(node)
def on_class_node_enter(node)
return unless visible?(node, @range)

@response_builder.add_token(node.constant_path.location, :class, [:declaration])
constant_path = node.constant_path

if constant_path.is_a?(Prism::ConstantReadNode)
@response_builder.add_token(constant_path.location, :class, [:declaration])
else
each_constant_path_part(constant_path) do |part|
loc = case part
when Prism::ConstantPathNode
part.name_loc
when Prism::ConstantReadNode
part.location
end
next unless loc

@response_builder.add_token(loc, :class, [:declaration])
end
end

superclass = node.superclass
@response_builder.add_token(superclass.location, :class) if superclass

if superclass.is_a?(Prism::ConstantReadNode)
@response_builder.add_token(superclass.location, :class)
elsif superclass
each_constant_path_part(superclass) do |part|
loc = case part
when Prism::ConstantPathNode
part.name_loc
when Prism::ConstantReadNode
part.location
end
next unless loc

@response_builder.add_token(loc, :class)
end
end
end

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

@response_builder.add_token(node.constant_path.location, :namespace, [:declaration])
constant_path = node.constant_path

if constant_path.is_a?(Prism::ConstantReadNode)
@response_builder.add_token(constant_path.location, :namespace, [:declaration])
else
each_constant_path_part(constant_path) do |part|
loc = case part
when Prism::ConstantPathNode
part.name_loc
when Prism::ConstantReadNode
part.location
end
next unless loc

@response_builder.add_token(loc, :namespace, [:declaration])
end
end
end

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

sig { params(node: Prism::ConstantPathNode).void }
def on_constant_path_node_enter(node)
return if @inside_implicit_node
return unless visible?(node, @range)

@response_builder.add_token(node.name_loc, :namespace)
end

private

# Textmate provides highlighting for a subset of these special Ruby-specific methods. We want to utilize that
Expand Down
18 changes: 18 additions & 0 deletions lib/ruby_lsp/requests/support/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ def namespace_constant_name(node)
constant_name(path)
end
end

# Iterates over each part of a constant path, so that we can easily push response items for each section of the
# name. For example, for `Foo::Bar::Baz`, this method will invoke the block with `Foo`, then `Bar` and finally
# `Baz`.
sig do
params(
node: Prism::Node,
block: T.proc.params(part: Prism::Node).void,
).void
end
def each_constant_path_part(node, &block)
current = T.let(node, T.nilable(Prism::Node))

while current.is_a?(Prism::ConstantPathNode)
block.call(current)
current = current.parent
end
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion ruby-lsp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

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

s.required_ruby_version = ">= 3.0"
Expand Down
Loading

0 comments on commit e3c0f20

Please sign in to comment.