-
Notifications
You must be signed in to change notification settings - Fork 154
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
Return VOID
by default for unhandled requests
#961
Conversation
|
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.
Any way we could have leveraged static typing to avoid this?
I see the return being typed as T.untyped
.
I'm not sure how we'd go about typing in this case. The method returns a different type depending on what request we received, which is why it's currently untyped. case request[:method]
when "textDocument/documentSymbol"
# returns document symbols array
when "textDocument/hover"
# returns hover object
else
# unknown requests, we don't return anything
VOID
end |
A first option would be to use POSSIBLE_RESPONSE_TYPES = T.type_alias { T.any(all the types we handle right now) } A more involved solution would be to create type wrappers with a common ancestor: Do the returned types have a common ancestor we could use?
If not, we could add one ourselves:
```rb
module ResponseType
interface!
end
class ::Interface::SemanticTokens
include ResponseType
end I wonder if we could handle the arrays the same way: class WorkspaceSymbols < Array
include ResponseType
Elem = type_member{{fixed: Interface::WorkspaceSymbol}}
end And interesting case would be to avoid implicit class NilReponse < NilClass
include ResponseType
end So it would force us to use |
There's no common ancestor unfortunately. We could try using the The untyped response is only used when writing it to STDOUT to send it back to the editor here. |
assign testItem from children only if matching child
Motivation
Closes #882
Currently, if we receive a request we don't handle, we are returning
nil
back to the editor. Based on the issue reported, not every editor handles this and some completely stop the execution of the LSP.This is probably happening when the server makes a request to the client to initiate progress. Because this is not a notification, but a request to the client, it actually sends back a response. When we receive that response back, we should not return
nil
back to the editor, since it does not expect anything back.Generally, I don't think the LSP should ever return anything back to the editor for requests we don't handle explicitly.
Implementation
Added an
else
branch to our case statement to always returnVOID
for unhandled requests.Automated Tests
Added a test verifying the new behaviour. Also moved the
private
since there were some helper methods defined outside of that section.