Skip to content

Register formatting capabilities dynamically to exclude TOML files - #27332

Merged
ntBre merged 2 commits into
mainfrom
brent/toml-registration
Jul 31, 2026
Merged

Register formatting capabilities dynamically to exclude TOML files#27332
ntBre merged 2 commits into
mainfrom
brent/toml-registration

Conversation

@ntBre

@ntBre ntBre commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses astral-sh/ruff-vscode#1127 (comment), which would
otherwise expose Ruff as a TOML formatter in VS Code. Instead of registering formatting and range
formatting capabilities statically, we now register them dynamically only for Python, Markdown, and
notebook files, excluding TOML files.

We still fall back on static registration if dynamic registration is unavailable.

Test Plan

New e2e tests

Summary
--

Addresses astral-sh/ruff-vscode#1127 (comment), which would
otherwise expose Ruff as a TOML formatter in VS Code. Instead of registering formatting and range
formatting capabilities statically, we now register them dynamically only for Python, Markdown, and
notebook files, excluding TOML files.

We still fall back on static registration if dynamic registration is unavailable.

Test Plan
--

New e2e tests
@ntBre ntBre added the server Related to the LSP server label Jul 30, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
ntBre marked this pull request as ready for review July 30, 2026 20:56
@ntBre
ntBre requested a review from MichaReiser July 30, 2026 20:56

@MichaReiser MichaReiser left a comment

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.

Thank you.

Before merging, please verify that this change doesn't break formatting in VS Code (and maybe neovim?). Does formatting in python documents, markdown files, and notebooks still work? Our E2E tests are great, but it always assumes that our understanding of the LSP specification is correct and matches what clients implement.

Comment on lines +194 to +201
["file", "untitled"].into_iter().map(move |scheme| {
types::TextDocumentFilter::Language(types::TextDocumentFilterLanguage {
language: language.to_string(),
scheme: Some(scheme.to_string()),
pattern: None,
})
.into()
})

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.

Nit. The into_iterator here feels a bit too clever to me. I'd be inclined to simply repeat both selectors.

["file", "untitled"].into_iter().map(move |scheme| {
types::TextDocumentFilter::Language(types::TextDocumentFilterLanguage {
language: language.to_string(),
scheme: Some(scheme.to_string()),

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.

Do we need to set the schema? what about clients with custom schemas?

I think the smallest change here is to omit the schema, which matches our existing behavior

Suggested change
scheme: Some(scheme.to_string()),
scheme: None,

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, yeah this also helped to get rid of all the into_iter stuff.

@ntBre

ntBre commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Formatting in Python and Markdown files worked in neovim, and for Python, Markdown, and notebooks in VS Code:

Screen.Recording.2026-07-31.at.10.00.34.mov

@ntBre
ntBre merged commit 7111e13 into main Jul 31, 2026
47 checks passed
@ntBre
ntBre deleted the brent/toml-registration branch July 31, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants