Skip to content

Emit deprecated tag for deprecated LSP diagnostics#2887

Closed
mvanhorn wants to merge 2 commits intofacebook:mainfrom
mvanhorn:osc/2885-deprecated-diagnostic-tag
Closed

Emit deprecated tag for deprecated LSP diagnostics#2887
mvanhorn wants to merge 2 commits intofacebook:mainfrom
mvanhorn:osc/2885-deprecated-diagnostic-tag

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Emits DiagnosticTag::DEPRECATED on LSP diagnostics for deprecated error codes.

Why this matters

Editors that support LSP diagnostic tags render strikethrough on deprecated names. Pyrefly was missing this tag. Now deprecated functions get the visual cue.

Changes

  • pyrefly/lib/error/error.rs: Added DiagnosticTag import. Changed tags: None to emit DiagnosticTag::DEPRECATED when error_kind() == ErrorKind::Deprecated.

Testing

The change is a 6-line addition to a single file. ErrorKind derives PartialEq so the comparison is sound.

Fixes #2885

This contribution was developed with AI assistance (Claude Code).

When the error kind is Deprecated, emit DiagnosticTag::DEPRECATED
on the LSP diagnostic. Editors that support this tag render a
strikethrough over the deprecated name.

Fixes facebook#2885
@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 24, 2026

Hi @mvanhorn!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@yangdanny97
Copy link
Copy Markdown
Contributor

This should be tested somewhere. Did you verify the diagnostic ranges are correct for all the locations where this error is emitted?

Verifies that diagnostics for deprecated functions include
DiagnosticTag::DEPRECATED (tag value 2), which enables strikethrough
rendering in editors that support LSP diagnostic tags.
@meta-cla meta-cla bot added the cla signed label Mar 25, 2026
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Added an LSP interaction test in 6a21eb5 that opens a file with a @deprecated function call and asserts the diagnostic includes tags: [2] (DEPRECATED).

On range correctness: the tag is applied in to_diagnostic() based on error_kind() == ErrorKind::Deprecated, so it's independent of which call site emits the error. All four sites (expr.rs, call.rs, overload.rs, stmt.rs) produce ErrorKind::Deprecated errors that flow through the same to_diagnostic() path. The range for each comes from the AST node at the call site (call expression, arguments, import statement), which is the same range used for the error message.

@yangdanny97
Copy link
Copy Markdown
Contributor

yangdanny97 commented Mar 25, 2026

To clarify: I'm saying we should emit the Deprecated error at the position of the call expression's subject, not the whole expression. That way, if we have something like deprecated_function(a, b, c) it's rendered as deprecated_function(a, b, c) rather than deprecated_function(a, b, c)

@github-actions
Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Looking at the call paths, freeform_call_infer already passes x.func.range() (the callee range) into as_call_target_or_error, so the deprecated diagnostic should already use just the function name for direct calls. The test shows range 0:12 for old_function() which is only the name, not the full call expression.

Is there a specific case where you're seeing the range cover the arguments?

@yangdanny97
Copy link
Copy Markdown
Contributor

Understood, I'll try to get this merged. thanks

@yangdanny97 yangdanny97 self-assigned this Mar 26, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 26, 2026

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D98246395.

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 26, 2026

@yangdanny97 merged this pull request in 8c5b8f3.

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks for pulling this in, @yangdanny97. Appreciate the back-and-forth on the diagnostic ranges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit deprecated tag for deprecated LSP diagnostics

3 participants