-
Notifications
You must be signed in to change notification settings - Fork 208
Adjust some return types to avoid nils #463
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
Conversation
@@ -198,7 +198,7 @@ def formatting(uri) | |||
uri: String, | |||
position: Document::PositionShape, | |||
character: String, | |||
).returns(T.nilable(T::Array[Interface::TextEdit])) | |||
).returns(T::Array[Interface::TextEdit]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the change in lib/ruby_lsp/requests/on_type_formatting.rb
def resolve_version(uri) | ||
version = uri.gem_version | ||
return version unless version.nil? || version.empty? | ||
|
||
return @gem_version unless @gem_version.nil? || @gem_version.empty? | ||
|
||
GEM_TO_VERSION_MAP[uri.gem_name] | ||
GEM_TO_VERSION_MAP.fetch(uri.gem_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we had T.must(resolve_version(uri))
that would mean we always expect to find the key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the mistake was actually the other way around. If the source comment is for a gem that is no longer a part of the bundle, then GEM_TO_VERSION_MAP[uri.gem_name]
will return nil
.
Instead of doing the T.must
, we need to return early in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree with Vini here. nil
in this case is a valid output. We should do an early return on line 95 instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've put it back to how it was previously and created a separate issue:
@@ -21,7 +21,7 @@ def initialize | |||
@runner = T.let(RuboCopRunner.new("-a"), RuboCopRunner) | |||
end | |||
|
|||
sig { params(uri: String, document: Document).returns(T.nilable(String)) } | |||
sig { params(uri: String, document: Document).returns(String) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatted_source
returns a String
.
ffaab27
to
4b16fbe
Compare
Motivation
Follow up from https://github.com/Shopify/ruby-lsp/pull/462/files#r1082948918
Implementation
Automated Tests
Manual Tests