Skip to content

Don't show noqa hover for non-Python documents#24040

Merged
MichaReiser merged 1 commit intoastral-sh:mainfrom
statxc:fix/no-noqa-hover-in-markdown
Mar 19, 2026
Merged

Don't show noqa hover for non-Python documents#24040
MichaReiser merged 1 commit intoastral-sh:mainfrom
statxc:fix/no-noqa-hover-in-markdown

Conversation

@statxc
Copy link
Contributor

@statxc statxc commented Mar 19, 2026

Summary

Fixes #23860

After PR #23905 fixed code actions appearing in non-Python documents, the noqa hover tooltip still appeared in markdown files. For example, hovering over # noqa: RUF100 in a markdown file would show a tooltip explaining the RUF100 rule, even though # is a heading marker in markdown, not a Python comment.

Added a SourceType::Python guard at the top of the hover() function, following the same pattern used in code_action.rs.

Test Plan

Added two unit tests in hover.rs:

  • no_hover_for_markdown: opens a .md file containing # noqa: RUF100 and verifies hover returns None
  • hover_for_python_noqa: opens a .py file containing # noqa: RUF100 and verifies hover returns a tooltip

To run the tests:

cd /home/ubuntu/Music/ruff
CARGO_PROFILE_DEV_OPT_LEVEL=1 cargo test -p ruff_server -- "hover::tests"

Expected output:

running 2 tests
test server::api::requests::hover::tests::no_hover_for_markdown ... ok
test server::api::requests::hover::tests::hover_for_python_noqa ... ok

test result: ok. 2 passed; 0 failed;

@statxc statxc changed the title fix: Don't show noqa hover tooltip for non-Python documents Don't show noqa hover for non-Python documents Mar 19, 2026
@MichaReiser MichaReiser added preview Related to preview mode features server Related to the LSP server labels Mar 19, 2026
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you

@MichaReiser MichaReiser enabled auto-merge (squash) March 19, 2026 07:41
@MichaReiser MichaReiser merged commit 378fe73 into astral-sh:main Mar 19, 2026
41 checks passed
@statxc statxc deleted the fix/no-noqa-hover-in-markdown branch March 19, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features server Related to the LSP server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

noqa hover shown in markdown file

2 participants