Skip to content

Return code action for codeAction/resolve requests that contain no or no valid URL#25365

Merged
MichaReiser merged 5 commits into
astral-sh:mainfrom
fallintoplace:fix-code-action-resolve-invalid-params
May 26, 2026
Merged

Return code action for codeAction/resolve requests that contain no or no valid URL#25365
MichaReiser merged 5 commits into
astral-sh:mainfrom
fallintoplace:fix-code-action-resolve-invalid-params

Conversation

@fallintoplace
Copy link
Copy Markdown
Contributor

@fallintoplace fallintoplace commented May 23, 2026

Closes #25364.

Summary

Handle invalid codeAction/resolve document URIs before scheduling a background request.

This changes the background document request path to extract document URLs fallibly and return an InvalidParams response when the request payload is malformed, instead of panicking while preparing the task. For CodeActionResolve, missing or invalid CodeAction.data is now reported as an invalid document URI.

Test Plan

Added integration tests

@astral-sh-bot astral-sh-bot Bot added the server Related to the LSP server label May 23, 2026
@fallintoplace fallintoplace force-pushed the fix-code-action-resolve-invalid-params branch from dd70a47 to 93632f1 Compare May 23, 2026 20:14
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 23, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser changed the title ruff server: handle invalid codeAction/resolve document URIs handle invalid URLs in codeAction/resolve requests May 24, 2026
@MichaReiser MichaReiser added the bug Something isn't working label May 24, 2026
.data
.clone()
.ok_or_else(|| anyhow::anyhow!("Code action is missing its document URI"))
.with_failure_code(ErrorCode::InvalidParams)?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not entirely sure whether answering here with InvalidParams is correct. Because the parameters for codeAction/resolve are correct. It's just that our background handler can't resolve any code actions without an URL. But this is more a Ruff requirement than a LSP requirement.

In ty_server, we have a BackgroundRequestHandler that does not do the document lookup for you, and, therefore, allows to customize the response when the url field is missing. Could we add something similar to ruff_server?

pub(super) trait BackgroundRequestHandler: RetriableRequestHandler {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes sense. I pushed an update that moves codeAction/resolve off the shared document-request path and gives it its own background preparation step instead, similar to ty_server.

@MichaReiser MichaReiser changed the title handle invalid URLs in codeAction/resolve requests Return code action for codeAction/resolve requests that contain no or no valid URL May 26, 2026
@MichaReiser
Copy link
Copy Markdown
Member

I unified the BackgroundRequestHandler and BackgroundDocumentRequestHandler. This also revealed a bug where the BackgroundDocumentRequestHandler never sent a response for documents that aren't in the index. This is a spec violation. This PR fixes this by moving the missing document handling into the request handlers, so that they can send whatever empty response is the most appropriate

@MichaReiser MichaReiser force-pushed the fix-code-action-resolve-invalid-params branch from 39e5574 to 849351b Compare May 26, 2026 08:12
@MichaReiser MichaReiser enabled auto-merge (squash) May 26, 2026 08:21
@MichaReiser MichaReiser disabled auto-merge May 26, 2026 08:22
@MichaReiser MichaReiser enabled auto-merge (squash) May 26, 2026 08:28
@MichaReiser MichaReiser merged commit 46f4993 into astral-sh:main May 26, 2026
43 of 44 checks passed
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server Related to the LSP server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruff server: codeAction/resolve with missing or malformed data crashes the server

2 participants