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

Avoid directly calling version to avoid Sorbet error #2663

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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
11 changes: 10 additions & 1 deletion lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ def process_message(message)
id: message[:id],
response:
Addon.addons.map do |addon|
{ name: addon.name, version: addon.version, errored: addon.error? }
version_method = addon.method(:version)

# If the add-on doesn't define a `version` method, we'd be calling the abstract method defined by
# Sorbet, which would raise an error.
# Therefore, we only call the method if it's defined by the add-on itself
if version_method.owner != Addon
version = addon.version
end

{ name: addon.name, version: version, errored: addon.error? }
end,
),
)
Expand Down
7 changes: 2 additions & 5 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ def test_workspace_addons
refute(addons_info[0][:errored])

assert_equal("Bar", addons_info[1][:name])
assert_equal("0.2.0", addons_info[1][:version])
# It doesn't define a `version` method
assert_nil(addons_info[1][:version])
assert(addons_info[1][:errored])
ensure
RubyLsp::Addon.addons.clear
Expand Down Expand Up @@ -722,10 +723,6 @@ def name
end

def deactivate; end

def version
"0.2.0"
end
end
end

Expand Down
Loading