diff --git a/crates/ide-host/src/formatter.rs b/crates/ide-host/src/formatter.rs index 6f983d5bf7..dc6139ebc3 100644 --- a/crates/ide-host/src/formatter.rs +++ b/crates/ide-host/src/formatter.rs @@ -261,6 +261,12 @@ fn supports_external_format(language: &LanguageConfig, tool: ExternalFormatter) } } +/// The entry of the formatters' language lists that covers `language`. MDX was part of Markdown +/// and follows its entry, so lists saved before it had its own language keep formatting it. +fn formatter_language(language: &str) -> &str { + if language == "mdx" { "markdown" } else { language } +} + /// The external formatter of a file, for a language with an external formatter. /// `forced` names the tool (Reformat with Prettier, oxfmt, Biome, Ruff, or Black). Ruff is /// the base formatter for Python, replaced by Black when configured or selected; Biome, @@ -295,7 +301,8 @@ fn external_tool( ))) }; } - let enabled = |tool| settings.formatter(tool).languages.iter().any(|l| l == language.id.as_str()); + let id = formatter_language(language.id.as_str()); + let enabled = |tool| settings.formatter(tool).languages.iter().any(|l| l == id); if language.formatter.as_ref().is_some_and(|f| f.tool == "ruff") { return Ok(if enabled(Black) && (settings.black.prefer || black_configured(file)) { Some(Black) @@ -897,6 +904,24 @@ mod tests { external_tool(forced, language.as_ref(), file, settings) } + #[test] + fn mdx_follows_the_markdown_entry_of_saved_language_lists() { + // Saved before MDX had its own language: the whole list, with no `mdx` in it. + let old: ide_core::settings::Settings = serde_json::from_str( + r#"{"languages":{"prettier":{"languages":["markdown","css"]},"oxfmt":{"languages":["css"]}}}"#, + ) + .unwrap(); + let file = Path::new("/project/docs/intro.mdx"); + assert_eq!(tool(None, "mdx", file, &old.languages).unwrap(), Some(Prettier)); + let mut no_markdown = old.languages.clone(); + no_markdown.prettier.languages.retain(|l| l != "markdown"); + assert_eq!(tool(None, "mdx", file, &no_markdown).unwrap(), None); + let mut oxfmt = old.languages.clone(); + oxfmt.oxfmt.languages.push("markdown".into()); + oxfmt.oxfmt.prefer = true; + assert_eq!(tool(None, "mdx", file, &oxfmt).unwrap(), Some(Oxfmt)); + } + #[test] fn default_settings_use_ruff_for_python_and_prettier_for_the_web() { let settings = LanguagesSettings::default(); diff --git a/crates/ide-host/src/ops/doc/commands.rs b/crates/ide-host/src/ops/doc/commands.rs index 532ea88768..008a8bfc3b 100644 --- a/crates/ide-host/src/ops/doc/commands.rs +++ b/crates/ide-host/src/ops/doc/commands.rs @@ -163,7 +163,7 @@ pub async fn doc_outline(host: &Host, window: &str, doc: DocId) -> IdeResult Vec::new(), + None if snap.large && !matches!(snap.language.as_str(), "markdown" | "mdx") => Vec::new(), None => syntax(), }) }) diff --git a/crates/ide-host/src/ops/spell.rs b/crates/ide-host/src/ops/spell.rs index c218ae9199..a317679fbf 100644 --- a/crates/ide-host/src/ops/spell.rs +++ b/crates/ide-host/src/ops/spell.rs @@ -11,7 +11,7 @@ use ide_spell::{Region, RegionKind, SpellScope, Speller, Typo}; use std::path::{Path, PathBuf}; /// Languages checked as prose (all text but code spans). -const PROSE: &[&str] = &["plaintext", "markdown", "restructuredtext", "asciidoc", "latex"]; +const PROSE: &[&str] = &["plaintext", "markdown", "mdx", "restructuredtext", "asciidoc", "latex"]; /// Custom dictionary paths: `~/…` from home, relative ones from the project root. fn dictionary_paths(settings: &SpellingSettings, root: &Path) -> Vec { diff --git a/crates/ide-language/src/registry.rs b/crates/ide-language/src/registry.rs index aef7ec885e..7e545dd23f 100644 --- a/crates/ide-language/src/registry.rs +++ b/crates/ide-language/src/registry.rs @@ -63,6 +63,7 @@ const BUILTIN: &[(&str, &str)] = &[ ("lua", include_str!("../../../languages/lua.toml")), ("makefile", include_str!("../../../languages/makefile.toml")), ("markdown", include_str!("../../../languages/markdown.toml")), + ("mdx", include_str!("../../../languages/mdx.toml")), ("nix", include_str!("../../../languages/nix.toml")), ("objective-c", include_str!("../../../languages/objective-c.toml")), ("objective-cpp", include_str!("../../../languages/objective-cpp.toml")), @@ -1281,6 +1282,7 @@ mod tests { ("Views/MainWindow.axaml", "axaml"), ("MainWindow.xaml", "xml"), ("README.md", "markdown"), + ("Intro.mdx", "mdx"), ("Dockerfile", "dockerfile"), ("Dockerfile.dev", "dockerfile"), ("Makefile", "makefile"), diff --git a/crates/ide-lsp/tests/real_servers.rs b/crates/ide-lsp/tests/real_servers.rs index c29496e905..70ba79a767 100644 --- a/crates/ide-lsp/tests/real_servers.rs +++ b/crates/ide-lsp/tests/real_servers.rs @@ -969,6 +969,79 @@ async fn bundler_path_aliases_resolve_below_tsconfig_paths() { tokio::time::timeout(Duration::from_secs(10), mgr.shutdown_all()).await.unwrap(); } +const MDX_BUTTON: &str = + "export function Button(props: { label: string }) {\n return ;\n}\n"; +const MDX_DOC: &str = "import { Button } from \"./Button\"\n\nexport const count = 2\n\n# Hello\n\n