Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use Prism v0.25 #1913

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ group :development do
gem "sorbet-static-and-runtime"
gem "tapioca", "~> 0.13", require: false
end

gem "rbi", github: "Shopify/rbi", branch: "main" # temporary until we fix shipit
end
17 changes: 12 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/Shopify/rbi.git
revision: 08559a942e4888b3d798fd9035a7cede1017b864
branch: main
specs:
rbi (0.1.11)
prism (>= 0.18.0, < 0.26)
sorbet-runtime (>= 0.5.9204)

GIT
remote: https://github.com/Shopify/rdoc.git
revision: 92a6b4fcf8b72dd6776c9aa6714abe6f90d4a99e
Expand All @@ -11,7 +20,7 @@ PATH
specs:
ruby-lsp (0.16.4)
language_server-protocol (~> 3.17.0)
prism (>= 0.22.0, < 0.25)
prism (>= 0.22.0, < 0.26)
sorbet-runtime (>= 0.5.10782)

GEM
Expand Down Expand Up @@ -45,15 +54,12 @@ GEM
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
prism (0.24.0)
prism (0.25.0)
psych (5.1.2)
stringio
racc (1.7.3)
rainbow (3.1.1)
rake (13.2.1)
rbi (0.1.9)
prism (>= 0.18.0, < 0.25)
sorbet-runtime (>= 0.5.9204)
regexp_parser (2.9.0)
reline (0.5.0)
io-console (~> 0.5)
Expand Down Expand Up @@ -135,6 +141,7 @@ DEPENDENCIES
mocha (~> 2.1)
psych (~> 5.1)
rake (~> 13.2)
rbi!
rdoc!
rubocop (~> 1.62)
rubocop-minitest (~> 0.35.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/listeners/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def build_method_completion(entry, node)
Interface::CompletionItem.new(
label: name,
filter_text: name,
text_edit: Interface::TextEdit.new(range: range_from_location(T.must(node.message_loc)), new_text: name),
text_edit: Interface::TextEdit.new(range: range_from_location(node.message_loc), new_text: name),
kind: Constant::CompletionItemKind::METHOD,
label_details: Interface::CompletionItemLabelDetails.new(
detail: "(#{entry.parameters.map(&:decorated_name).join(", ")})",
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 @@ -124,7 +124,7 @@ def extract_document_link(node)
match = comment.location.slice.match(%r{source://.*#\d+$})
return unless match

uri = T.cast(URI(T.must(match[0])), URI::Source)
uri = T.cast(URI(match[0]), URI::Source)
gem_version = resolve_version(uri)
return if gem_version.nil?

Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_lsp/listeners/document_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def on_alias_method_node_enter(node)
name: name,
kind: Constant::SymbolKind::METHOD,
range_location: new_name_node.location,
selection_range_location: T.must(new_name_node.value_loc),
selection_range_location: new_name_node.value_loc,
)
end

Expand Down Expand Up @@ -327,7 +327,7 @@ def handle_attr_accessor(node)
name: name,
kind: Constant::SymbolKind::FIELD,
range_location: argument.location,
selection_range_location: T.must(argument.value_loc),
selection_range_location: argument.value_loc,
)
elsif argument.is_a?(Prism::StringNode)
name = argument.content
Expand Down Expand Up @@ -361,7 +361,7 @@ def handle_alias_method(node)
name: name,
kind: Constant::SymbolKind::METHOD,
range_location: new_name_argument.location,
selection_range_location: T.must(new_name_argument.value_loc),
selection_range_location: new_name_argument.value_loc,
)
elsif new_name_argument.is_a?(Prism::StringNode)
name = new_name_argument.content
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/listeners/folding_ranges.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def add_statements_range(node)
body = statements.body
return if body.empty?

add_lines_range(node.location.start_line, T.must(body.last).location.end_line)
add_lines_range(node.location.start_line, body.last.location.end_line)
end

sig { params(node: Prism::Node).void }
Expand Down
8 changes: 4 additions & 4 deletions lib/ruby_lsp/listeners/semantic_highlighting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def on_call_node_enter(node)
return if special_method?(message)

type = Requests::Support::Sorbet.annotation?(node) ? :type : :method
@response_builder.add_token(T.must(node.message_loc), type)
@response_builder.add_token(node.message_loc, type)
end

sig { params(node: Prism::MatchWriteNode).void }
Expand Down Expand Up @@ -205,7 +205,7 @@ def on_keyword_rest_parameter_node_enter(node)
if name
@current_scope << name.to_sym

@response_builder.add_token(T.must(node.name_loc), :parameter) if visible?(node, @range)
@response_builder.add_token(node.name_loc, :parameter) if visible?(node, @range)
end
end

Expand All @@ -232,7 +232,7 @@ def on_rest_parameter_node_enter(node)
if name
@current_scope << name.to_sym

@response_builder.add_token(T.must(node.name_loc), :parameter) if visible?(node, @range)
@response_builder.add_token(node.name_loc, :parameter) if visible?(node, @range)
end
end

Expand Down Expand Up @@ -349,7 +349,7 @@ def process_regexp_locals(node)
# For each capture name we find in the regexp, look for a local in the current_scope
Regexp.new(content, Regexp::FIXEDENCODING).names.each do |name|
# The +3 is to compensate for the "(?<" part of the capture name
capture_name_offset = T.must(content.index("(?<#{name}>")) + 3
capture_name_offset = content.index("(?<#{name}>") + 3
local_var_loc = loc.copy(start_offset: loc.start_offset + capture_name_offset, length: name.length)

@response_builder.add_token(local_var_loc, @current_scope.type_for(name))
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/requests/code_action_resolve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def perform

# Find the node with the end line closest to the requested position, so that we can place the refactor
# immediately after that closest node
closest_node = T.must(closest_statements.child_nodes.compact.min_by do |node|
closest_node = closest_statements.child_nodes.compact.min_by do |node|
distance = source_range.dig(:start, :line) - (node.location.end_line - 1)
distance <= 0 ? Float::INFINITY : distance
end)
end

return Error::InvalidTargetRange if closest_node.is_a?(Prism::MissingNode)

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.22.0", "< 0.25")
s.add_dependency("prism", ">= 0.22.0", "< 0.26")
s.add_dependency("sorbet-runtime", ">= 0.5.10782")

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