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

Add messages to assertion failures in request_references and request_document_symbols #75

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

jetzhou
Copy link
Contributor

@jetzhou jetzhou commented Mar 4, 2025

When calling the language server, it could return None in cases where the input symbol or document is not found. The assertion statements changed here are mostly will be triggered in those cases. However, these cases could be considered expected, rather than errors, so callers should have the choice of catching them and handling them as desired. Without a message accompanying the assertion failure, it's very hard to do so. This PR adds a consistent message to these kinds of failures and they match the existing value inside request_definition in a similar situation.

This change is fairly minimal and more or less allows me what I would like to accomplish in my project, which is making sure that I return a nice user error in these "expected" error situations, rather than an uncaught server error. However, I do think the most appropriate thing to do here is let all these methods return None in addition to the List/Tuple. This would match the actual language server protocol where null is a possible return type. But the change in return type would imply a breaking change so I'm not sure if that's something worthy of doing without a super compelling reason.

Alternatively, we could also define a new NotFoundError and raise that error explicitly when the language server returns null. If that's a preferred way to handle this situation, I'm happy to take that approach and update this PR.

…o language server

These endpoints could return `None` in case the symbol is one that's not
found. Adding the assertion string can help caller catch these
exceptions and handle the errors as appropriate.
@LakshyAAAgrawal LakshyAAAgrawal merged commit ba749cb into microsoft:main Mar 5, 2025
4 checks passed
@jetzhou jetzhou deleted the not-found-error branch March 5, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants