Skip to content

Commit

Permalink
Fix type checking errors after Sorbet upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 15, 2025
1 parent 755d18a commit 3a14ddb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/ruby_lsp/listeners/document_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def initialize(response_builder, target, parent, dispatcher, position)
[target, node_value(target)]
when Prism::ModuleNode, Prism::ClassNode, Prism::SingletonClassNode, Prism::DefNode, Prism::CaseNode,
Prism::WhileNode, Prism::UntilNode, Prism::ForNode, Prism::IfNode, Prism::UnlessNode
target
[target, nil]
end

@target = T.let(highlight_target, T.nilable(Prism::Node))
Expand Down Expand Up @@ -620,7 +620,8 @@ def node_value(node)

sig { params(keyword_loc: T.nilable(Prism::Location), end_loc: T.nilable(Prism::Location)).void }
def add_matching_end_highlights(keyword_loc, end_loc)
return unless keyword_loc && end_loc && end_loc.length.positive?
return unless keyword_loc && end_loc
return unless end_loc.length.positive?
return unless covers_target_position?(keyword_loc) || covers_target_position?(end_loc)

add_highlight(Constant::DocumentHighlightKind::TEXT, keyword_loc)
Expand Down
10 changes: 8 additions & 2 deletions lib/ruby_lsp/listeners/document_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ def extract_document_link(node)
path = uri.path
return unless path

file_path = self.class.gem_paths.dig(uri.gem_name, gem_version, CGI.unescape(path))
gem_name = uri.gem_name
return unless gem_name

file_path = self.class.gem_paths.dig(gem_name, gem_version, CGI.unescape(path))
return if file_path.nil?

@response_builder << Interface::DocumentLink.new(
Expand All @@ -152,7 +155,10 @@ def resolve_version(uri)

return @gem_version unless @gem_version.nil? || @gem_version.empty?

GEM_TO_VERSION_MAP[uri.gem_name]
gem_name = uri.gem_name
return unless gem_name

GEM_TO_VERSION_MAP[gem_name]
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_lsp/load_sorbet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
begin
T::Configuration.default_checked_level = :never
# Suppresses call validation errors
T::Configuration.call_validation_error_handler = ->(*) {}
T::Configuration.call_validation_error_handler = ->(*arg) {}
# Suppresses errors caused by T.cast, T.let, T.must, etc.
T::Configuration.inline_type_error_handler = ->(*) {}
T::Configuration.inline_type_error_handler = ->(*arg) {}
# Suppresses errors caused by incorrect parameter ordering
T::Configuration.sig_validation_error_handler = ->(*) {}
T::Configuration.sig_validation_error_handler = ->(*arg) {}
rescue
# Need this rescue so that if another gem has
# already set the checked level by the time we
Expand Down
4 changes: 2 additions & 2 deletions test/addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def workspace_did_change_watched_files(changes); end
end

Addon.load_addons(@global_state, @outgoing_queue)
assert_equal(1, Addon.file_watcher_addons.length)
assert_instance_of(klass, Addon.file_watcher_addons.first)
addon = Addon.file_watcher_addons.find { |a| a.is_a?(klass) }
refute_nil(addon)
end

def test_get_an_addon_by_name
Expand Down
4 changes: 4 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ def test_shows_error_if_formatter_set_to_rubocop_but_rubocop_not_available
})

@server.global_state.register_formatter("rubocop_internal", RubyLsp::Requests::Support::RuboCopFormatter.new)

# Avoid trying to load add-ons because the RuboCop add-on will crash when the gem is artifically unloaded
@server.expects(:load_addons)

with_uninstalled_rubocop do
@server.process_message({ method: "initialized" })
end
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ suite("Client", () => {
}).timeout(20000);

test("formatting", async () => {
const text = " def foo\n end";
const text = "# frozen_string_literal: true\n def foo\n end";

await client.sendNotification("textDocument/didOpen", {
textDocument: {
Expand Down

0 comments on commit 3a14ddb

Please sign in to comment.