Pyrefly: surface secondary annotations as LSP DiagnosticRelatedInformation#4191
Open
anushamukka-dev wants to merge 1 commit into
Open
Pyrefly: surface secondary annotations as LSP DiagnosticRelatedInformation#4191anushamukka-dev wants to merge 1 commit into
anushamukka-dev wants to merge 1 commit into
Conversation
…ation Summary: Pyrefly attaches secondary annotations to type errors (e.g. labeling both operands of an unsupported binary operation with their types), and these already render in the CLI's source snippets. In the language server, however, `Error::to_diagnostic()` dropped them entirely — a lingering TODO noted that mapping them to `DiagnosticRelatedInformation` required constructing a `Url` from the module path, "which may not always succeed." Secondary annotations always live in the same file as the primary error, so we can reuse the error's own module path for their locations. This maps each `SecondaryAnnotation` to a `DiagnosticRelatedInformation` — its label becomes the message and `Module::to_lsp_range` converts the span — and populates `Diagnostic::related_information`. LSP clients can now show the extra context (e.g. "has type `int | str`") alongside the diagnostic and let users jump to each labeled span. `Url::from_file_path` requires an absolute path and can fail; when it does (or when there are no annotations) we leave `related_information` as `None` rather than dropping the diagnostic, so nothing regresses for modules without a materializable on-disk path. Addresses facebook#105 Differential Revision: D111240436
Contributor
|
@anushamukka-dev has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111240436. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Pyrefly attaches secondary annotations to type errors (e.g. labeling both operands of an unsupported binary operation with their types), and these already render in the CLI's source snippets. In the language server, however,
Error::to_diagnostic()dropped them entirely — a lingering TODO noted that mapping them toDiagnosticRelatedInformationrequired constructing aUrlfrom the module path, "which may not always succeed."Secondary annotations always live in the same file as the primary error, so we can reuse the error's own module path for their locations. This maps each
SecondaryAnnotationto aDiagnosticRelatedInformation— its label becomes the message andModule::to_lsp_rangeconverts the span — and populatesDiagnostic::related_information. LSP clients can now show the extra context (e.g. "has typeint | str") alongside the diagnostic and let users jump to each labeled span.Url::from_file_pathrequires an absolute path and can fail; when it does (or when there are no annotations) we leaverelated_informationasNonerather than dropping the diagnostic, so nothing regresses for modules without a materializable on-disk path.Addresses #105
Differential Revision: D111240436