Register formatting capabilities dynamically to exclude TOML files - #27332
Conversation
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
|
There was a problem hiding this comment.
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.
| ["file", "untitled"].into_iter().map(move |scheme| { | ||
| types::TextDocumentFilter::Language(types::TextDocumentFilterLanguage { | ||
| language: language.to_string(), | ||
| scheme: Some(scheme.to_string()), | ||
| pattern: None, | ||
| }) | ||
| .into() | ||
| }) |
There was a problem hiding this comment.
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()), |
There was a problem hiding this comment.
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
| scheme: Some(scheme.to_string()), | |
| scheme: None, |
There was a problem hiding this comment.
Thanks, yeah this also helped to get rid of all the into_iter stuff.
|
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 |
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