From 9e8722feb6137c93cc552957d5feac0febfe2043 Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Sun, 22 Nov 2026 20:18:37 +0900 Subject: [PATCH] feat(lsp): lint and format with Biome (#5200) Adds Biome as a language server (lint diagnostics and code actions) and as a formatter for CSS, GraphQL, JavaScript, TypeScript (and JSX), JSON and JSONC, with a Languages & Frameworks > Biome settings page (path, provider, run on save, enabled languages). Biome formats instead of Prettier and oxfmt below a biome.json / biome.jsonc or a Biome installation, unless the nearest configuration sets formatter.enabled to false, in which case Prettier keeps formatting. Resolved conflicts with the Tailwind CSS language server: both servers are listed in the language definitions, registry tests and docs. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-core/src/settings.rs | 16 +- crates/ide-host/src/formatter.rs | 72 +++++++- crates/ide-language/src/registry.rs | 29 +++ crates/ide-sdk/src/apply.rs | 47 +++++ crates/ide-sdk/src/astro.rs | 7 +- crates/ide-sdk/src/npm.rs | 7 + crates/ide-tools/src/formatter.rs | 55 +++++- crates/ide-tools/src/registry.rs | 14 +- docs/en/guide/editor.mdx | 2 +- docs/en/languages/index.mdx | 174 +++++++++--------- docs/en/languages/javascript.mdx | 10 +- docs/en/reference/settings.mdx | 2 +- docs/zh/guide/editor.mdx | 2 +- docs/zh/languages/index.mdx | 174 +++++++++--------- docs/zh/languages/javascript.mdx | 9 +- docs/zh/reference/settings.mdx | 2 +- fixtures/README.md | 3 +- fixtures/biome-app/biome.json | 27 +++ fixtures/biome-app/package.json | 16 ++ fixtures/biome-app/src/cart.ts | 21 +++ fixtures/biome-app/src/data.json | 2 + fixtures/biome-app/src/index.ts | 9 + fixtures/biome-app/src/theme.css | 6 + languages/css.toml | 11 ++ languages/graphql.toml | 11 ++ languages/javascript.toml | 11 ++ languages/javascriptreact.toml | 11 ++ languages/json.toml | 11 ++ languages/jsonc.toml | 11 ++ languages/typescript.toml | 11 ++ languages/typescriptreact.toml | 11 ++ src/bindings.ts | 7 +- src/editor/lsp/actions.ts | 11 +- src/editor/lsp/format.test.ts | 4 +- src/editor/lsp/format.ts | 3 +- src/editor/lsp/formatErrors.test.tsx | 5 +- .../settings/__tests__/languages.test.ts | 11 ++ .../settings/languages/FormatterPage.tsx | 12 ++ src/features/settings/pages/languages.tsx | 11 ++ src/platform/languageSettings.ts | 11 +- src/platform/locales/text/en.json | 6 + src/platform/locales/text/zh.json | 6 + src/platform/locales/textCatalog.test.ts | 1 + 43 files changed, 670 insertions(+), 212 deletions(-) create mode 100644 fixtures/biome-app/biome.json create mode 100644 fixtures/biome-app/package.json create mode 100644 fixtures/biome-app/src/cart.ts create mode 100644 fixtures/biome-app/src/data.json create mode 100644 fixtures/biome-app/src/index.ts create mode 100644 fixtures/biome-app/src/theme.css diff --git a/crates/ide-core/src/settings.rs b/crates/ide-core/src/settings.rs index cf773d883..7b376babe 100644 --- a/crates/ide-core/src/settings.rs +++ b/crates/ide-core/src/settings.rs @@ -1206,6 +1206,7 @@ pub struct LanguagesSettings { pub typescript: TypeScriptSettings, pub prettier: ExternalFormatterSettings, pub oxfmt: ExternalFormatterSettings, + pub biome: ExternalFormatterSettings, pub ruff: ExternalFormatterSettings, pub java: JavaSettings, pub ruby: RubySettings, @@ -1226,6 +1227,10 @@ impl Default for LanguagesSettings { typescript: TypeScriptSettings::default(), prettier: ExternalFormatterSettings::default(), oxfmt: ExternalFormatterSettings::default(), + biome: ExternalFormatterSettings { + languages: BIOME_LANGUAGES.iter().map(|&l| l.into()).collect(), + ..ExternalFormatterSettings::default() + }, ruff: ExternalFormatterSettings { languages: vec!["python".into()], ..ExternalFormatterSettings::default() @@ -1297,6 +1302,7 @@ impl LanguagesSettings { match tool { ExternalFormatter::Prettier => &self.prettier, ExternalFormatter::Oxfmt => &self.oxfmt, + ExternalFormatter::Biome => &self.biome, ExternalFormatter::Ruff => &self.ruff, } } @@ -1308,6 +1314,7 @@ impl LanguagesSettings { pub enum ExternalFormatter { Prettier, Oxfmt, + Biome, Ruff, } @@ -1317,16 +1324,21 @@ impl ExternalFormatter { match self { Self::Prettier => "prettier", Self::Oxfmt => "oxfmt", + Self::Biome => "biome", Self::Ruff => "ruff", } } } -/// An external formatter (Prettier, oxfmt, Ruff) and the languages it formats. +/// The languages Biome formats (of those Prettier formats). +pub const BIOME_LANGUAGES: [&str; 8] = + ["css", "graphql", "javascript", "javascriptreact", "typescript", "typescriptreact", "json", "jsonc"]; + +/// An external formatter (Prettier, oxfmt, Biome, Ruff) and the languages it formats. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)] #[serde(default, rename_all = "camelCase")] pub struct ExternalFormatterSettings { - /// Empty path: project node_modules (Prettier/oxfmt), managed installation, then PATH. + /// Empty path: project node_modules (Prettier/oxfmt/Biome), managed installation, then PATH. pub path: String, /// Ruff only: directory containing its configuration, or a configuration file. pub configuration_directory: String, diff --git a/crates/ide-host/src/formatter.rs b/crates/ide-host/src/formatter.rs index d61c23b00..8485b6ed7 100644 --- a/crates/ide-host/src/formatter.rs +++ b/crates/ide-host/src/formatter.rs @@ -2,7 +2,7 @@ use crate::Host; use ide_core::event::NotifyLevel; -use ide_core::settings::{ExternalFormatter, LanguagesSettings, Settings}; +use ide_core::settings::{BIOME_LANGUAGES, ExternalFormatter, LanguagesSettings, Settings}; use ide_core::{ChangeSet, DocId, IdeError, IdeEvent, IdeResult, LanguageId, Pos, Range, TextEdit}; use ide_language::{LanguageConfig, PhpAlignment, Syntax}; use ide_lsp::types::FormatOptions; @@ -10,9 +10,28 @@ use ide_tools::{Tools, formatter}; use std::path::Path; const OXFMT_CONFIGS: [&str; 4] = [".oxfmtrc.json", ".oxfmtrc.jsonc", "oxfmt.config.ts", "oxfmt.config.mts"]; +/// A Biome configuration, or Biome installed as a project dependency (it then uses its defaults). +const BIOME_MARKERS: [&str; 3] = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome/package.json"]; + +/// Reformat Code uses Biome below a Biome configuration or installation, unless the nearest +/// configuration turns its formatter off (Biome lints, another tool formats). +fn biome_formats(file: &Path) -> bool { + let config = ["biome.json", "biome.jsonc"] + .iter() + .filter_map(|name| formatter::find_up(file, Path::new(name))) + .max_by_key(|path| path.components().count()); + match config { + Some(config) => !std::fs::read_to_string(&config) + .ok() + .and_then(|text| serde_json::from_str::(&ide_core::jsonc::strip(&text)).ok()) + .is_some_and(|v| v.pointer("/formatter/enabled") == Some(&serde_json::Value::Bool(false))), + None => BIOME_MARKERS.iter().any(|name| formatter::find_up(file, Path::new(name)).is_some()), + } +} fn supports_external_format(language: &LanguageConfig, tool: ExternalFormatter) -> bool { match language.formatter.as_ref().map(|f| f.tool.as_str()) { + Some("prettier") if tool == ExternalFormatter::Biome => BIOME_LANGUAGES.contains(&language.id.as_str()), Some("prettier") => matches!(tool, ExternalFormatter::Prettier | ExternalFormatter::Oxfmt), Some("ruff") => tool == ExternalFormatter::Ruff, _ => false, @@ -20,9 +39,9 @@ fn supports_external_format(language: &LanguageConfig, tool: ExternalFormatter) } /// The external formatter of a file, for a language with an external formatter. -/// `forced` names the tool (Reformat with Prettier, oxfmt, or Ruff). Ruff is -/// the base formatter for Python; oxfmt can replace Prettier for its languages -/// when configured or selected. A tool that cannot format the language is +/// `forced` names the tool (Reformat with Prettier, oxfmt, Biome, or Ruff). Ruff is +/// the base formatter for Python; Biome, then oxfmt, can replace Prettier for their +/// languages when configured or selected. A tool that cannot format the language is /// rejected even when explicitly requested. fn external_tool( forced: Option, @@ -30,7 +49,7 @@ fn external_tool( file: &Path, settings: &LanguagesSettings, ) -> IdeResult> { - use ExternalFormatter::{Oxfmt, Prettier, Ruff}; + use ExternalFormatter::{Biome, Oxfmt, Prettier, Ruff}; let Some(language) = language.filter(|l| l.formatter.is_some()) else { return match forced { Some(tool) => Err(IdeError::invalid(format!( @@ -56,8 +75,11 @@ fn external_tool( if language.formatter.as_ref().is_some_and(|f| f.tool == "ruff") { return Ok(enabled(Ruff).then_some(Ruff)); } - let oxfmt_config = || OXFMT_CONFIGS.iter().any(|name| formatter::find_up(file, Path::new(name)).is_some()); - Ok(if enabled(Oxfmt) && (settings.oxfmt.prefer || oxfmt_config()) { + let found = |names: &[&str]| names.iter().any(|name| formatter::find_up(file, Path::new(name)).is_some()); + let biome = enabled(Biome) && supports_external_format(language, Biome); + Ok(if biome && (settings.biome.prefer || biome_formats(file)) { + Some(Biome) + } else if enabled(Oxfmt) && (settings.oxfmt.prefer || found(&OXFMT_CONFIGS)) { Some(Oxfmt) } else { enabled(Prettier).then_some(Prettier) @@ -385,7 +407,7 @@ async fn provider_edits( #[cfg(test)] mod tests { use super::*; - use ExternalFormatter::{Oxfmt, Prettier, Ruff}; + use ExternalFormatter::{Biome, Oxfmt, Prettier, Ruff}; use ide_core::LanguageId; use ide_language::LanguageRegistry; @@ -428,6 +450,40 @@ mod tests { assert_eq!(prettier.message, "Prettier cannot format Python files"); let oxfmt = tool(Some(Oxfmt), "python", file, &settings).unwrap_err(); assert_eq!(oxfmt.message, "oxfmt cannot format Python files"); + let biome = tool(Some(Biome), "python", file, &settings).unwrap_err(); + assert_eq!(biome.message, "Biome cannot format Python files"); + } + + #[test] + fn biome_config_or_dependency_selects_biome_for_its_languages() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path(); + std::fs::create_dir_all(root.join("web/src")).unwrap(); + let (web, api, readme) = (root.join("web/src/app.ts"), root.join("api/main.ts"), root.join("web/README.md")); + let mut settings = LanguagesSettings::default(); + for marker in BIOME_MARKERS { + let path = root.join("web").join(marker); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(&path, "{}").unwrap(); + assert_eq!(tool(None, "typescript", &web, &settings).unwrap(), Some(Biome), "{marker}"); + assert_eq!(tool(None, "typescript", &api, &settings).unwrap(), Some(Prettier), "{marker}"); + // Biome doesn't format Markdown: Prettier keeps it. + assert_eq!(tool(None, "markdown", &readme, &settings).unwrap(), Some(Prettier), "{marker}"); + std::fs::remove_file(&path).unwrap(); + } + std::fs::write(root.join("web/biome.json"), "{}").unwrap(); + std::fs::write(root.join("web/.oxfmtrc.json"), "{}").unwrap(); + assert_eq!(tool(None, "css", &web, &settings).unwrap(), Some(Biome)); + settings.biome.languages.retain(|l| l != "css"); + assert_eq!(tool(None, "css", &web, &settings).unwrap(), Some(Oxfmt)); + // Biome only lints here: Prettier keeps formatting. + std::fs::remove_file(root.join("web/.oxfmtrc.json")).unwrap(); + std::fs::write(root.join("web/biome.json"), r#"{ "formatter": { "enabled": false } }"#).unwrap(); + assert_eq!(tool(None, "typescript", &web, &settings).unwrap(), Some(Prettier)); + settings.biome.prefer = true; + assert_eq!(tool(None, "typescript", &api, &settings).unwrap(), Some(Biome)); + let markdown = tool(Some(Biome), "markdown", &readme, &settings).unwrap_err(); + assert_eq!(markdown.message, "Biome cannot format Markdown files"); } #[test] diff --git a/crates/ide-language/src/registry.rs b/crates/ide-language/src/registry.rs index 728f504f3..96375900e 100644 --- a/crates/ide-language/src/registry.rs +++ b/crates/ide-language/src/registry.rs @@ -721,6 +721,7 @@ mod tests { "angular-language-server", "oxlint", "eslint", + "biome", "tailwindcss-language-server" ] ); @@ -754,6 +755,34 @@ mod tests { } } + #[test] + fn biome_lints_files_below_its_config_or_installation() { + let reg = reg(); + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + for dir in ["apps/web/src", "apps/admin/node_modules/@biomejs/biome", "apps/api"] { + std::fs::create_dir_all(root.join(dir)).unwrap(); + } + std::fs::write(root.join("apps/web/biome.jsonc"), "{}").unwrap(); + for lang in + ["javascript", "javascriptreact", "typescript", "typescriptreact", "json", "jsonc", "css", "graphql"] + { + let cfg = reg.get(&LanguageId::new(lang)).unwrap(); + let biome = cfg.language_servers.iter().find(|s| s.name == "biome").unwrap(); + assert_eq!( + (biome.command.as_str(), biome.args.as_slice()), + ("biome", ["lsp-proxy".to_string()].as_slice()) + ); + assert!(biome.require_root_marker && !biome.fallback, "{lang}"); + // Reformat Code runs `biome format`: the server's formatting would race the language's own. + assert_eq!(biome.features, ["code-action", "diagnostics"], "{lang}"); + let served = |file: &str| crate::marked_root(Some(root), &root.join(file), &biome.root_markers); + assert_eq!(served("apps/web/src/main.ts"), Some(root.join("apps/web")), "{lang}"); + assert_eq!(served("apps/admin/main.ts"), Some(root.join("apps/admin")), "{lang}"); + assert_eq!(served("apps/api/main.ts"), None, "{lang}"); + } + } + #[test] fn eslint_serves_js_files_only_below_its_config() { let reg = reg(); diff --git a/crates/ide-sdk/src/apply.rs b/crates/ide-sdk/src/apply.rs index f044f8c1f..dee7bacb1 100644 --- a/crates/ide-sdk/src/apply.rs +++ b/crates/ide-sdk/src/apply.rs @@ -1424,6 +1424,14 @@ pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_root if name == astro::SERVER { astro::configure(cfg, root, server_root, s); } + // Biome lints with the project's own version (its configuration follows that version's + // schema); an explicit executable setting still wins. + if name == "biome" + && cfg.command == "biome" + && let Some(bin) = crate::npm::project_bin("biome", root, server_root) + { + cfg.command = bin.to_string_lossy().into_owned(); + } if name == crate::arduino::SERVER { crate::arduino::configure(cfg, root, server_root, s); } @@ -2743,3 +2751,42 @@ mod conda_activation_tests { assert_eq!(conda_activation(&plain.join("bin").join("python"), "bash", Some(conda), None), None); } } + +#[cfg(test)] +mod biome_tests { + use super::*; + + fn binary(dir: &Path) -> PathBuf { + let bin = dir.join(if cfg!(windows) { "biome.cmd" } else { "biome" }); + std::fs::create_dir_all(dir).unwrap(); + std::fs::write(&bin, "").unwrap(); + #[cfg(unix)] + std::fs::set_permissions(&bin, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap(); + bin + } + + #[test] + fn biome_runs_the_projects_own_biome_unless_an_executable_is_set() { + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path().join("project"); + let web = root.join("apps/web"); + let configured = |s: &Settings, server_root: &Path| { + let mut cfg = custom_server("biome", &LanguageServerSettings::default()); + cfg.command = "biome".into(); + configure_server(&mut cfg, &root, server_root, s); + PathBuf::from(cfg.command) + }; + let workspace = binary(&root.join("node_modules/.bin")); + assert_eq!(configured(&Settings::default(), &web), workspace); + let member = binary(&web.join("node_modules/.bin")); + assert_eq!(configured(&Settings::default(), &web), member); + // Outside the project: not the project's installation. + binary(&tmp.path().join("node_modules/.bin")); + assert_eq!(configured(&Settings::default(), &tmp.path().join("other")), PathBuf::from("biome")); + let custom = binary(&tmp.path().join("custom")); + let mut s = Settings::default(); + s.tools + .insert("biome".into(), ide_core::settings::ToolSettings { path: custom.to_string_lossy().into_owned() }); + assert_eq!(configured(&s, &web), custom); + } +} diff --git a/crates/ide-sdk/src/astro.rs b/crates/ide-sdk/src/astro.rs index ecd06e7a0..03acea263 100644 --- a/crates/ide-sdk/src/astro.rs +++ b/crates/ide-sdk/src/astro.rs @@ -1,7 +1,7 @@ //! Astro (Volar) requires a TypeScript language-service library at initialize. use crate::apply::{merge_init_options, setting_path, tsdk}; -use crate::npm::{has_ts_api, own_typescript, package_dir}; +use crate::npm::{has_ts_api, own_typescript, package_dir, project_bin}; use ide_core::settings::Settings; use ide_core::tool_path::{find_command, search_path}; use ide_language::LanguageServerConfig; @@ -20,10 +20,7 @@ pub(crate) fn configure(cfg: &mut LanguageServerConfig, root: &Path, server_root // A project's installation wins over managed / global tools. Explicit // executable settings still win, as they do for other language servers. if cfg.command == SERVER - && let Some(bin) = server_root - .ancestors() - .take_while(|dir| dir.starts_with(root)) - .find_map(|dir| find_command(SERVER, dir.join("node_modules/.bin").as_os_str(), server_root)) + && let Some(bin) = project_bin(SERVER, root, server_root) { cfg.command = bin.to_string_lossy().into_owned(); } diff --git a/crates/ide-sdk/src/npm.rs b/crates/ide-sdk/src/npm.rs index edd087f9f..61a27209c 100644 --- a/crates/ide-sdk/src/npm.rs +++ b/crates/ide-sdk/src/npm.rs @@ -10,6 +10,13 @@ pub(crate) fn has_ts_api(lib: &Path) -> bool { lib.join("typescript.js").is_file() } +/// `command` installed in the project: the nearest `node_modules/.bin` from `server_root` up to `root`. +pub(crate) fn project_bin(command: &str, root: &Path, server_root: &Path) -> Option { + server_root.ancestors().take_while(|dir| dir.starts_with(root)).find_map(|dir| { + ide_core::tool_path::find_command(command, dir.join("node_modules/.bin").as_os_str(), server_root) + }) +} + /// The native executable of TypeScript 7 (`typescript` 7+, whose `tsc` is native, or /// `@typescript/native-preview`'s `tsgo`), from its package directory or its `lib`. /// These packages have no JavaScript API (`lib/typescript.js`); their platform package diff --git a/crates/ide-tools/src/formatter.rs b/crates/ide-tools/src/formatter.rs index 538d48331..944c79459 100644 --- a/crates/ide-tools/src/formatter.rs +++ b/crates/ide-tools/src/formatter.rs @@ -62,13 +62,22 @@ fn package_bin(package: &Path, tool: &str) -> IdeResult { Ok(path) } -/// Prettier and Ruff format ranges for some languages (`config.range`); oxfmt formats whole files only. +/// Prettier and Ruff format ranges for some languages (`config.range`); oxfmt and Biome format whole files only. pub fn supports_range(tool: &str, config: &FormatterConfig) -> bool { matches!(tool, "prettier" | "ruff") && config.range } fn is_formatter(tool: &str) -> bool { - crate::registry::find(tool).is_some_and(|t| t.kind == crate::ToolKind::Formatter || t.name == "ruff") + crate::registry::find(tool) + .is_some_and(|t| t.kind == crate::ToolKind::Formatter || matches!(t.name, "ruff" | "biome")) +} + +/// The npm package that provides `tool`'s CLI. +fn npm_package(tool: &str) -> &str { + match tool { + "biome" => "@biomejs/biome", + _ => tool, + } } impl Tools { @@ -81,7 +90,7 @@ impl Tools { if !is_formatter(tool) { return Err(IdeError::unavailable(format!("Unknown external formatter: {tool}"))); } - let package = Path::new("node_modules").join(tool); + let package = Path::new("node_modules").join(npm_package(tool)); let manifest = package.join("package.json"); let (path, node) = if let Some(custom) = custom.filter(|p| p.is_dir()) { (package_bin(custom, tool)?, true) @@ -108,7 +117,7 @@ impl Tools { } /// Every tool resolves its configuration itself. Prettier's project configuration -/// overrides the editor indentation passed here; oxfmt and Ruff read their own +/// overrides the editor indentation passed here; oxfmt, Biome and Ruff read their own /// configuration files. Ruff also discovers the nearest `pyproject.toml`, /// `ruff.toml`, or `.ruff.toml` from the stdin filename. pub fn arguments( @@ -137,6 +146,12 @@ pub fn arguments( } return args; } + if tool == "biome" { + // Biome finds its `biome.json` and ignore files from the file's path itself. + let mut path = OsString::from("--stdin-file-path="); + path.push(file); + return vec!["format".into(), path]; + } if tool == "prettier" { let parser = if config.parser == "markdown" && file.extension().is_some_and(|s| s == "mdx") { "mdx" @@ -323,6 +338,38 @@ mod tests { assert!(unknown.message.contains("Unknown external formatter"), "{}", unknown.message); } + #[test] + fn biome_runs_the_nearest_biomejs_package_with_the_file_path() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path(); + let package = root.join("node_modules/@biomejs/biome"); + std::fs::create_dir_all(package.join("bin")).unwrap(); + std::fs::write(package.join("package.json"), r#"{"bin":{"biome":"bin/biome"}}"#).unwrap(); + std::fs::write(package.join("bin/biome"), "").unwrap(); + std::fs::write(root.join(".prettierignore"), "dist").unwrap(); + let file = root.join("packages/web/src/app.ts"); + let path = std::env::var_os("PATH").unwrap_or_default(); + let tools = Tools::with_paths(root.join("tools"), path, crate::platform::Platform::current()); + + let command = tools.formatter_command("biome", &file, None).unwrap(); + let program = Path::new(command.get_program()).file_stem().unwrap().to_string_lossy().into_owned(); + assert_eq!(program, "node"); + let script: Vec<_> = command.get_args().collect(); + assert_eq!( + Path::new(&script[0]).components().collect::>(), + package.join("bin/biome").components().collect::>() + ); + + let config = FormatterConfig { tool: "prettier".into(), parser: "typescript".into(), range: true }; + let range = + Some(FormatRange { start_offset: 3, end_offset: 9, start_line: 1, start_col: 1, end_line: 1, end_col: 7 }); + let mut stdin_path = OsString::from("--stdin-file-path="); + stdin_path.push(&file); + // No Prettier ignore files or indentation: Biome reads its own configuration. + assert_eq!(arguments("biome", &config, &file, 4, false, range, None), ["format".into(), stdin_path]); + assert!(!supports_range("biome", &config)); + } + #[test] fn ruff_formats_stdin_and_uses_its_config_and_range_flags() { let config = FormatterConfig { tool: "ruff".into(), parser: "python".into(), range: true }; diff --git a/crates/ide-tools/src/registry.rs b/crates/ide-tools/src/registry.rs index 6456db336..0335493da 100644 --- a/crates/ide-tools/src/registry.rs +++ b/crates/ide-tools/src/registry.rs @@ -201,6 +201,18 @@ pub static TOOLS: &[ToolSpec] = &[ needs: NODE, homepage: "https://oxc.rs/docs/guide/usage/linter", }, + // Linter and formatter: `biome lsp-proxy` lints, and Reformat Code runs `biome format`. + ToolSpec { + name: "biome", + display: "Biome", + kind: LanguageServer, + commands: &["biome"], + method: Method::Npm { packages: &["@biomejs/biome"] }, + fallback: None, + version: ver("biome"), + needs: NODE, + homepage: "https://biomejs.dev", + }, ToolSpec { name: "eslint", display: "ESLint Language Server", @@ -1298,7 +1310,7 @@ mod tests { known.insert((d.adapter.clone(), d.command.clone())); } } - // The host selects the formatter of each file (Prettier or oxfmt) and runs its own CLIs. + // The host selects the formatter of each file (Prettier, oxfmt or Biome) and runs its own CLIs. for t in TOOLS.iter().filter(|t| !matches!(t.kind, Plugin | Formatter | Cli)) { assert!( known.contains(&(t.name.to_string(), t.commands[0].to_string())), diff --git a/docs/en/guide/editor.mdx b/docs/en/guide/editor.mdx index cd6221c0a..58003313a 100644 --- a/docs/en/guide/editor.mdx +++ b/docs/en/guide/editor.mdx @@ -88,7 +88,7 @@ All folding commands are also in **Code › Folding**. Fold regions come from th | **Auto-Indent Lines** | `⌃⌥I` | `Ctrl+Alt+I` | | **Optimize Imports** | `⌃⌥O` | `Ctrl+Alt+O` | -**Reformat Code** formats the selection, or the whole file when nothing is selected, as one undo step. The formatting comes from the file's language server or from the formatter the language is configured with (for example Ruff for Python, Prettier or oxfmt for web languages; find their commands as **Reformat with …** in Find Action). **Reformat File…** also lets you choose the scope and optimize imports. +**Reformat Code** formats the selection, or the whole file when nothing is selected, as one undo step. The formatting comes from the file's language server or from the formatter the language is configured with (for example Ruff for Python, Prettier, oxfmt or Biome for web languages; find their commands as **Reformat with …** in Find Action). **Reformat File…** also lets you choose the scope and optimize imports. Indentation and other style options are under **Settings › Editor › Code Style**, with a page per language. `.editorconfig` files in the project are read too. diff --git a/docs/en/languages/index.mdx b/docs/en/languages/index.mdx index ec13ac0cf..fabc29d01 100644 --- a/docs/en/languages/index.mdx +++ b/docs/en/languages/index.mdx @@ -34,7 +34,7 @@ For a recognized file, support comes in layers: A language can list more than one server: - **Alternatives** (shown as `a → b` in the table below): only the first one that is installed runs. Python, for example, uses basedpyright, and falls back to pyright, ty or pyrefly only when basedpyright is missing. In **Settings › Languages & Frameworks › Language Servers** you can pick one of them or set the choice to **Automatic** (the first one available). -- **Additions** (shown as `+ b`): run next to the main server, usually only in projects that use them. Ruff joins basedpyright in projects with a Ruff configuration; oxlint joins vtsls in projects with an oxlint configuration; the Angular, Laravel and Tailwind CSS servers join in Angular, Laravel and Tailwind CSS projects. +- **Additions** (shown as `+ b`): run next to the main server, usually only in projects that use them. Ruff joins basedpyright in projects with a Ruff configuration; oxlint joins vtsls in projects with an oxlint configuration; Biome joins the JavaScript, TypeScript, JSON, CSS and GraphQL servers in projects with a Biome configuration or installation; the Angular, Laravel and Tailwind CSS servers join in Angular, Laravel and Tailwind CSS projects. ## Installing language servers and debuggers @@ -91,92 +91,92 @@ Selecting a language server on the Language Servers page shows its settings, whi The table lists every built-in language definition. Server and debugger names in **bold** can be installed from the IDE; the others you install yourself (the install hint in the IDE says how). "Highlighting" and "Tree-sitter" mark instant highlighting and the bundled grammar for outline and folding. -| Language | ID | Files | Highlighting | Tree-sitter | Language servers | Debugger | -| ------------------- | ------------------ | ----------------------------------------------------------- | ------------ | ----------- | ------------------------------------------------------------------------------------- | ------------------------ | -| .env | `dotenv` | `.env` | Yes | — | — | — | -| Arduino | `arduino` | `.ino` | Yes | Yes | arduino-language-server | — | -| AsciiDoc | `asciidoc` | `.adoc`, `.asciidoc` | Yes | — | — | — | -| Astro | `astro` | `.astro` | Yes | — | **astro-ls** + **oxlint** | — | -| Batch | `bat` | `.bat`, `.cmd` | Yes | — | — | — | -| C | `c` | `.c`, `.h` | Yes | Yes | **clangd** | lldb-dap | -| C# | `csharp` | `.cs`, `.csx` | Yes | Yes | **csharp-ls** | **netcoredbg** | -| C++ | `cpp` | `.cpp`, `.cc`, `.cxx`, `.c++`, `.hpp`, … | Yes | Yes | **clangd** | lldb-dap | -| Clojure | `clojure` | `.clj`, `.cljs`, `.cljc`, `.cljd`, `.edn`, … | Yes | — | **clojure-lsp** | — | -| CMake | `cmake` | `.cmake` | Yes | Yes | **neocmakelsp** → cmake-language-server | — | -| CSS | `css` | `.css`, `.pcss`, `.postcss` | Yes | Yes | **vscode-css-language-server** | — | -| D | `d` | `.d`, `.di` | Yes | — | serve-d | — | -| Dart | `dart` | `.dart` | Yes | Yes | dart | dart | -| Diff | `diff` | `.diff`, `.patch`, `.rej` | Yes | — | — | — | -| Django Template | `django-html` | `.djhtml`, `templates/*.html`, `*.txt` | Yes | Yes | **vscode-html-language-server**, **djlsp** | — | -| Dockerfile | `dockerfile` | `.dockerfile`, `.containerfile` | Yes | — | **dockerfile-language-server** | — | -| Elixir | `elixir` | `.ex`, `.exs` | Yes | Yes | **elixir-ls** | **elixir-ls-debugger** | -| ERB | `erb` | `.erb`, `.html.erb`, `.rhtml`, `.js.erb`, `.text.erb`, … | Yes | — | — | — | -| Erlang | `erlang` | `.erl`, `.hrl`, `.escript`, `.app.src` | Yes | — | elp | — | -| F# | `fsharp` | `.fs`, `.fsi`, `.fsx` | Yes | — | **fsautocomplete** | **netcoredbg** | -| GDScript | `gdscript` | `.gd` | Yes | Yes | godot | godot | -| Git Attributes | `gitattributes` | `.gitattributes` | — | — | — | — | -| Go | `go` | `.go` | Yes | Yes | **gopls** | **delve** | -| Go Module | `go.mod` | `go.mod` | Yes | — | **gopls** | — | -| Go Workspace | `go.work` | `go.work` | Yes | — | **gopls** | — | -| Godot Resource | `godot-resource` | `.tscn`, `.tres`, `.godot`, `.import` | Yes | — | — | — | -| Godot Shader | `gdshader` | `.gdshader`, `.gdshaderinc` | Yes | — | — | — | -| GraphQL | `graphql` | `.graphql`, `.graphqls`, `.gql` | Yes | Yes | **graphql-lsp** | — | -| Groovy | `groovy` | `.groovy`, `.gradle`, `.gvy`, `.gy`, `.gsh` | Yes | — | groovy-language-server | — | -| Haskell | `haskell` | `.hs`, `.hs-boot`, `.hsig` | Yes | Yes | haskell-language-server | — | -| HCL | `hcl` | `.hcl`, `.nomad`, `.pkr.hcl` | Yes | Yes | — | — | -| HTML | `html` | `.html`, `.htm`, `.xhtml`, `.shtml`, `.html.tmpl` | Yes | Yes | **vscode-html-language-server** + **angular-language-server** | — | -| HTTP Request | `http` | `.http`, `.rest` | Yes | — | — | — | -| Ignore File | `ignore` | `.gitignore`, `.dockerignore` | — | — | — | — | -| INI | `ini` | `.ini`, `.cfg`, `.conf`, `.cnf`, `.inf`, … | Yes | — | — | — | -| Java | `java` | `.java` | Yes | Yes | **jdtls** → **java-analyzer** → **kmp-lsp** | **java-debug** | -| JavaScript | `javascript` | `.js`, `.mjs`, `.cjs` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** | **js-debug** | -| JavaScript JSX | `javascriptreact` | `.jsx` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** | **js-debug** | -| JSON | `json` | `.json`, `.geojson`, `.topojson`, `.webmanifest`, `.har`, … | Yes | Yes | **vscode-json-language-server** | — | -| JSON with Comments | `jsonc` | `.jsonc`, `.code-workspace`, `.code-snippets` | Yes | Yes | **vscode-json-language-server** | — | -| JSP | `jsp` | `.jsp`, `.jspx`, `.jspf`, `.jsph`, `.tag`, … | Yes | — | — | — | -| Julia | `julia` | `.jl` | Yes | — | julia-languageserver | — | -| Kotlin | `kotlin` | `.kt`, `.kts` | Yes | Yes | **kotlin-lsp** → **kotlin-language-server** → **kmp-lsp** | **kotlin-debug-adapter** | -| LaTeX | `latex` | `.tex`, `.ltx`, `.sty`, `.cls`, `.dtx`, … | Yes | — | **texlab** | — | -| Less | `less` | `.less` | Yes | — | **vscode-css-language-server** | — | -| Log | `log` | `.log` | Yes | — | — | — | -| Lua | `lua` | `.lua`, `.luau`, `.rockspec` | Yes | Yes | **lua-language-server** | — | -| Makefile | `makefile` | `.mk`, `.mak`, `.make` | Yes | Yes | — | — | -| Markdown | `markdown` | `.md`, `.markdown`, `.mdown`, `.mkd`, `.mkdn`, … | Yes | Yes | **marksman** | — | -| Nix | `nix` | `.nix` | Yes | Yes | nil → nixd | — | -| Objective-C | `objective-c` | `.m` | Yes | — | **clangd** | lldb-dap | -| Objective-C++ | `objective-cpp` | `.mm` | Yes | — | **clangd** | lldb-dap | -| OCaml | `ocaml` | `.ml`, `.mll`, `.mly` | Yes | Yes | ocamllsp | ocamlearlybird | -| OCaml Interface | `ocaml.interface` | `.mli` | Yes | Yes | ocamllsp | — | -| Perl | `perl` | `.pl`, `.pm`, `.pod`, `.psgi`, `.cgi` | Yes | — | **perlnavigator** | — | -| PHP | `php` | `.php`, `.phtml`, `.php3`, `.php4`, `.php5`, … | Yes | Yes | **intelephense** → phpactor → **phoxite** + **laravel-lsp** | **php-debug** | -| Plain Text | `plaintext` | `.txt`, `.text` | — | — | — | — | -| PowerShell | `powershell` | `.ps1`, `.psm1`, `.psd1`, `.pssc`, `.psrc` | Yes | — | powershell-editor-services | — | -| Prisma | `prisma` | `.prisma` | Yes | Yes | **prisma-language-server** | — | -| Properties | `properties` | `.properties`, `.prefs` | Yes | — | — | — | -| Protocol Buffers | `proto` | `.proto` | Yes | Yes | **buf** | — | -| Python | `python` | `.py`, `.pyi`, `.pyw` | Yes | Yes | **basedpyright** → **pyright** → **ty** → **pyrefly** + **ruff** | **debugpy** | -| R | `r` | `.r`, `.rprofile` | Yes | — | r-languageserver | — | -| reStructuredText | `restructuredtext` | `.rst` | Yes | — | — | — | -| Ruby | `ruby` | `.rb`, `.rake`, `.gemspec`, `.ru`, `.rbi`, … | Yes | Yes | **ruby-lsp** → **solargraph** | rdbg | -| Rust | `rust` | `.rs` | Yes | Yes | **rust-analyzer** | **codelldb** | -| Sass | `sass` | `.sass` | Yes | — | — | — | -| Scala | `scala` | `.scala`, `.sc`, `.sbt`, `.mill` | Yes | Yes | metals | — | -| SCSS | `scss` | `.scss` | Yes | — | **vscode-css-language-server** | — | -| Shell Script | `shellscript` | `.sh`, `.bash`, `.zsh`, `.ksh`, `.ash`, … | Yes | Yes | **bash-language-server** | **bash-debug** | -| Slint | `slint` | `.slint` | Yes | — | **slint-lsp** | — | -| SQL | `sql` | `.sql`, `.ddl`, `.dml`, `.psql`, `.pgsql`, … | Yes | — | **sqls** | — | -| Svelte | `svelte` | `.svelte` | Yes | — | **svelte-language-server** + **oxlint** | — | -| Swift | `swift` | `.swift`, `.swiftinterface` | Yes | Yes | sourcekit-lsp | lldb-dap | -| Terraform | `terraform` | `.tf`, `.tofu`, `.tftest.hcl` | Yes | Yes | **terraform-ls** | — | -| Terraform Variables | `terraform-vars` | `.tfvars` | Yes | Yes | **terraform-ls** | — | -| TOML | `toml` | `.toml` | Yes | Yes | **taplo** | — | -| TypeScript | `typescript` | `.ts`, `.mts`, `.cts` | Yes | Yes | **vtsls** → **typescript-language-server** + **angular-language-server** + **oxlint** | **js-debug** | -| TypeScript JSX | `typescriptreact` | `.tsx` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** | **js-debug** | -| Typst | `typst` | `.typ` | — | — | **tinymist** | — | -| Vue | `vue` | `.vue` | Yes | — | **vue-language-server**, **vtsls** + **oxlint** | — | -| XML | `xml` | `.xml`, `.xsd`, `.xsl`, `.xslt`, `.svg`, … | Yes | Yes | **lemminx** | — | -| YAML | `yaml` | `.yaml`, `.yml` | Yes | Yes | **yaml-language-server** | — | -| Zig | `zig` | `.zig`, `.zon` | Yes | Yes | **zls** | **codelldb** | +| Language | ID | Files | Highlighting | Tree-sitter | Language servers | Debugger | +| ------------------- | ------------------ | ----------------------------------------------------------- | ------------ | ----------- | ------------------------------------------------------------------------------------------------- | ------------------------ | +| .env | `dotenv` | `.env` | Yes | — | — | — | +| Arduino | `arduino` | `.ino` | Yes | Yes | arduino-language-server | — | +| AsciiDoc | `asciidoc` | `.adoc`, `.asciidoc` | Yes | — | — | — | +| Astro | `astro` | `.astro` | Yes | — | **astro-ls** + **oxlint** | — | +| Batch | `bat` | `.bat`, `.cmd` | Yes | — | — | — | +| C | `c` | `.c`, `.h` | Yes | Yes | **clangd** | lldb-dap | +| C# | `csharp` | `.cs`, `.csx` | Yes | Yes | **csharp-ls** | **netcoredbg** | +| C++ | `cpp` | `.cpp`, `.cc`, `.cxx`, `.c++`, `.hpp`, … | Yes | Yes | **clangd** | lldb-dap | +| Clojure | `clojure` | `.clj`, `.cljs`, `.cljc`, `.cljd`, `.edn`, … | Yes | — | **clojure-lsp** | — | +| CMake | `cmake` | `.cmake` | Yes | Yes | **neocmakelsp** → cmake-language-server | — | +| CSS | `css` | `.css`, `.pcss`, `.postcss` | Yes | Yes | **vscode-css-language-server** + **biome** | — | +| D | `d` | `.d`, `.di` | Yes | — | serve-d | — | +| Dart | `dart` | `.dart` | Yes | Yes | dart | dart | +| Diff | `diff` | `.diff`, `.patch`, `.rej` | Yes | — | — | — | +| Django Template | `django-html` | `.djhtml`, `templates/*.html`, `*.txt` | Yes | Yes | **vscode-html-language-server**, **djlsp** | — | +| Dockerfile | `dockerfile` | `.dockerfile`, `.containerfile` | Yes | — | **dockerfile-language-server** | — | +| Elixir | `elixir` | `.ex`, `.exs` | Yes | Yes | **elixir-ls** | **elixir-ls-debugger** | +| ERB | `erb` | `.erb`, `.html.erb`, `.rhtml`, `.js.erb`, `.text.erb`, … | Yes | — | — | — | +| Erlang | `erlang` | `.erl`, `.hrl`, `.escript`, `.app.src` | Yes | — | elp | — | +| F# | `fsharp` | `.fs`, `.fsi`, `.fsx` | Yes | — | **fsautocomplete** | **netcoredbg** | +| GDScript | `gdscript` | `.gd` | Yes | Yes | godot | godot | +| Git Attributes | `gitattributes` | `.gitattributes` | — | — | — | — | +| Go | `go` | `.go` | Yes | Yes | **gopls** | **delve** | +| Go Module | `go.mod` | `go.mod` | Yes | — | **gopls** | — | +| Go Workspace | `go.work` | `go.work` | Yes | — | **gopls** | — | +| Godot Resource | `godot-resource` | `.tscn`, `.tres`, `.godot`, `.import` | Yes | — | — | — | +| Godot Shader | `gdshader` | `.gdshader`, `.gdshaderinc` | Yes | — | — | — | +| GraphQL | `graphql` | `.graphql`, `.graphqls`, `.gql` | Yes | Yes | **graphql-lsp** + **biome** | — | +| Groovy | `groovy` | `.groovy`, `.gradle`, `.gvy`, `.gy`, `.gsh` | Yes | — | groovy-language-server | — | +| Haskell | `haskell` | `.hs`, `.hs-boot`, `.hsig` | Yes | Yes | haskell-language-server | — | +| HCL | `hcl` | `.hcl`, `.nomad`, `.pkr.hcl` | Yes | Yes | — | — | +| HTML | `html` | `.html`, `.htm`, `.xhtml`, `.shtml`, `.html.tmpl` | Yes | Yes | **vscode-html-language-server** + **angular-language-server** | — | +| HTTP Request | `http` | `.http`, `.rest` | Yes | — | — | — | +| Ignore File | `ignore` | `.gitignore`, `.dockerignore` | — | — | — | — | +| INI | `ini` | `.ini`, `.cfg`, `.conf`, `.cnf`, `.inf`, … | Yes | — | — | — | +| Java | `java` | `.java` | Yes | Yes | **jdtls** → **java-analyzer** → **kmp-lsp** | **java-debug** | +| JavaScript | `javascript` | `.js`, `.mjs`, `.cjs` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | +| JavaScript JSX | `javascriptreact` | `.jsx` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | +| JSON | `json` | `.json`, `.geojson`, `.topojson`, `.webmanifest`, `.har`, … | Yes | Yes | **vscode-json-language-server** + **biome** | — | +| JSON with Comments | `jsonc` | `.jsonc`, `.code-workspace`, `.code-snippets` | Yes | Yes | **vscode-json-language-server** + **biome** | — | +| JSP | `jsp` | `.jsp`, `.jspx`, `.jspf`, `.jsph`, `.tag`, … | Yes | — | — | — | +| Julia | `julia` | `.jl` | Yes | — | julia-languageserver | — | +| Kotlin | `kotlin` | `.kt`, `.kts` | Yes | Yes | **kotlin-lsp** → **kotlin-language-server** → **kmp-lsp** | **kotlin-debug-adapter** | +| LaTeX | `latex` | `.tex`, `.ltx`, `.sty`, `.cls`, `.dtx`, … | Yes | — | **texlab** | — | +| Less | `less` | `.less` | Yes | — | **vscode-css-language-server** | — | +| Log | `log` | `.log` | Yes | — | — | — | +| Lua | `lua` | `.lua`, `.luau`, `.rockspec` | Yes | Yes | **lua-language-server** | — | +| Makefile | `makefile` | `.mk`, `.mak`, `.make` | Yes | Yes | — | — | +| Markdown | `markdown` | `.md`, `.markdown`, `.mdown`, `.mkd`, `.mkdn`, … | Yes | Yes | **marksman** | — | +| Nix | `nix` | `.nix` | Yes | Yes | nil → nixd | — | +| Objective-C | `objective-c` | `.m` | Yes | — | **clangd** | lldb-dap | +| Objective-C++ | `objective-cpp` | `.mm` | Yes | — | **clangd** | lldb-dap | +| OCaml | `ocaml` | `.ml`, `.mll`, `.mly` | Yes | Yes | ocamllsp | ocamlearlybird | +| OCaml Interface | `ocaml.interface` | `.mli` | Yes | Yes | ocamllsp | — | +| Perl | `perl` | `.pl`, `.pm`, `.pod`, `.psgi`, `.cgi` | Yes | — | **perlnavigator** | — | +| PHP | `php` | `.php`, `.phtml`, `.php3`, `.php4`, `.php5`, … | Yes | Yes | **intelephense** → phpactor → **phoxite** + **laravel-lsp** | **php-debug** | +| Plain Text | `plaintext` | `.txt`, `.text` | — | — | — | — | +| PowerShell | `powershell` | `.ps1`, `.psm1`, `.psd1`, `.pssc`, `.psrc` | Yes | — | powershell-editor-services | — | +| Prisma | `prisma` | `.prisma` | Yes | Yes | **prisma-language-server** | — | +| Properties | `properties` | `.properties`, `.prefs` | Yes | — | — | — | +| Protocol Buffers | `proto` | `.proto` | Yes | Yes | **buf** | — | +| Python | `python` | `.py`, `.pyi`, `.pyw` | Yes | Yes | **basedpyright** → **pyright** → **ty** → **pyrefly** + **ruff** | **debugpy** | +| R | `r` | `.r`, `.rprofile` | Yes | — | r-languageserver | — | +| reStructuredText | `restructuredtext` | `.rst` | Yes | — | — | — | +| Ruby | `ruby` | `.rb`, `.rake`, `.gemspec`, `.ru`, `.rbi`, … | Yes | Yes | **ruby-lsp** → **solargraph** | rdbg | +| Rust | `rust` | `.rs` | Yes | Yes | **rust-analyzer** | **codelldb** | +| Sass | `sass` | `.sass` | Yes | — | — | — | +| Scala | `scala` | `.scala`, `.sc`, `.sbt`, `.mill` | Yes | Yes | metals | — | +| SCSS | `scss` | `.scss` | Yes | — | **vscode-css-language-server** | — | +| Shell Script | `shellscript` | `.sh`, `.bash`, `.zsh`, `.ksh`, `.ash`, … | Yes | Yes | **bash-language-server** | **bash-debug** | +| Slint | `slint` | `.slint` | Yes | — | **slint-lsp** | — | +| SQL | `sql` | `.sql`, `.ddl`, `.dml`, `.psql`, `.pgsql`, … | Yes | — | **sqls** | — | +| Svelte | `svelte` | `.svelte` | Yes | — | **svelte-language-server** + **oxlint** | — | +| Swift | `swift` | `.swift`, `.swiftinterface` | Yes | Yes | sourcekit-lsp | lldb-dap | +| Terraform | `terraform` | `.tf`, `.tofu`, `.tftest.hcl` | Yes | Yes | **terraform-ls** | — | +| Terraform Variables | `terraform-vars` | `.tfvars` | Yes | Yes | **terraform-ls** | — | +| TOML | `toml` | `.toml` | Yes | Yes | **taplo** | — | +| TypeScript | `typescript` | `.ts`, `.mts`, `.cts` | Yes | Yes | **vtsls** → **typescript-language-server** + **angular-language-server** + **oxlint** + **biome** | **js-debug** | +| TypeScript JSX | `typescriptreact` | `.tsx` | Yes | Yes | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | +| Typst | `typst` | `.typ` | — | — | **tinymist** | — | +| Vue | `vue` | `.vue` | Yes | — | **vue-language-server**, **vtsls** + **oxlint** | — | +| XML | `xml` | `.xml`, `.xsd`, `.xsl`, `.xslt`, `.svg`, … | Yes | Yes | **lemminx** | — | +| YAML | `yaml` | `.yaml`, `.yml` | Yes | Yes | **yaml-language-server** | — | +| Zig | `zig` | `.zig`, `.zon` | Yes | Yes | **zls** | **codelldb** | Notes: diff --git a/docs/en/languages/javascript.mdx b/docs/en/languages/javascript.mdx index d34abfc0d..4947c1744 100644 --- a/docs/en/languages/javascript.mdx +++ b/docs/en/languages/javascript.mdx @@ -17,6 +17,7 @@ OpenIDEA edits JavaScript (`.js`, `.mjs`, `.cjs`, `.jsx`) and TypeScript (`.ts`, | TS and HTML in Angular projects | `angular-language-server` (`ngserver`) | Only below `angular.json` or `node_modules/@angular/core`. | | All of the above | `oxlint` | Only below an `.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts` or `oxlint.config.mts`. | | All of the above | `vscode-eslint-language-server` (ESLint) | Only below an ESLint configuration (`eslint.config.*`, `.eslintrc*` or `eslintConfig` in `package.json`); runs the project's own `eslint`. | +| JS, JSX, TS, TSX, JSON, CSS | `biome lsp-proxy` (Biome) | Only below a `biome.json` / `biome.jsonc` or an installed `@biomejs/biome`; runs the project's own `biome`. | | All of the above, HTML and CSS | `tailwindcss-language-server` (Tailwind CSS) | Only below a `tailwind.config.*` or a `package.json` that depends on `tailwindcss`: class completion, hover with the generated CSS, and class diagnostics. | The TypeScript servers start for a workspace marked by `tsconfig.json`, `jsconfig.json` or `package.json`. Files outside any `tsconfig.json` / `jsconfig.json` are still registered with tsserver, so loose scripts get code insight too. @@ -49,7 +50,7 @@ All servers, debuggers and formatters are listed in **Settings › Languages & F | `vue-language-server`, `svelte-language-server`, `astro-ls`, `angular-language-server` | npm | | `oxlint` | npm | | `tailwindcss-language-server` | npm (`@tailwindcss/language-server`) | -| Prettier, oxfmt | npm | +| Prettier, oxfmt, Biome | npm | | JavaScript Debugger (vscode-js-debug) | GitHub release (`microsoft/vscode-js-debug`) | The Astro and Angular servers also run from the project's own `node_modules/.bin` when it has them. @@ -69,8 +70,13 @@ The Astro and Angular servers also run from the project's own `node_modules/.bin - **Prettier** (**Settings › Languages & Frameworks › Prettier**) formats JavaScript, JSX, TypeScript, TSX, JSON, Vue, HTML, CSS, SCSS, Less, GraphQL, YAML and Markdown by default. The executable is found in the project's `node_modules`, then the managed installation, then `PATH`, unless you set **Prettier path**. - **oxfmt** (**Settings › Languages & Frameworks › oxfmt**) replaces Prettier for an enabled language in files below an oxfmt configuration (`.oxfmtrc.json`, `oxfmt.config.ts`), or when it is the selected provider. +- **Biome** (**Settings › Languages & Frameworks › Biome**) replaces Prettier and oxfmt for JavaScript, JSX, TypeScript, TSX, JSON, CSS and GraphQL in files below a `biome.json` / `biome.jsonc` or an installed `@biomejs/biome` (unless the configuration sets `formatter.enabled` to `false`), or when it is the selected provider. It formats whole files and reads its own configuration. -On both pages, **Formatting provider** chooses between **Automatic (language server first)** and the tool itself, **Run on save** formats on save, and **Enabled languages** limits which languages the tool handles. +On these pages, **Formatting provider** chooses between **Automatic (language server first)** and the tool itself, **Run on save** formats on save, and **Enabled languages** limits which languages the tool handles. + +### Biome lint + +In a Biome project, Biome's diagnostics show in the editor and the Problems tool window, and `⌥⏎` / `Alt+Enter` offers its quick fixes and suppressions. Biome's safe fixes (`source.fixAll.biome`) run with **Code › Code Cleanup** and, when **Settings › Tools › Actions on Save › Run code cleanup** is on, on save. When Biome's formatter is enabled, its fix-all formats the file too. ## Run and test diff --git a/docs/en/reference/settings.mdx b/docs/en/reference/settings.mdx index 0bdee582e..2b78d2f6d 100644 --- a/docs/en/reference/settings.mdx +++ b/docs/en/reference/settings.mdx @@ -55,7 +55,7 @@ exclude = ["**/.git", "**/node_modules", "**/target", "**/dist"] | Plugins | Plugins | | Version Control | Commit; Confirmation; Directory Mappings; Issue Navigation; Log; Shelf; Git; GitHub | | Build, Execution, Deployment | CMake; Gradle; Maven; Console; Debugger (Data Views, Stepping); Python Debugger; Run/Debug; Run Targets; Deployment (Options) | -| Languages & Frameworks | Language Servers; Go (Build Tags, Go Modules); Java; Markdown; Node.js; PHP; Python Interpreter; Prettier; oxfmt; Ruff; Ruby; Rust; TypeScript | +| Languages & Frameworks | Language Servers; Go (Build Tags, Go Modules); Java; Markdown; Node.js; PHP; Python Interpreter; Prettier; oxfmt; Biome; Ruff; Ruby; Rust; TypeScript | | Tools | Agents (Chat); Terminal; Actions on Save; External Tools; SSH Configurations; MCP Server | | Security | Project Trust | diff --git a/docs/zh/guide/editor.mdx b/docs/zh/guide/editor.mdx index 4dbdd3c28..12e5e0466 100644 --- a/docs/zh/guide/editor.mdx +++ b/docs/zh/guide/editor.mdx @@ -88,7 +88,7 @@ description: "多光标与选区、行编辑、剪贴板历史、代码折叠、 | **自动缩进行** | `⌃⌥I` | `Ctrl+Alt+I` | | **优化导入** | `⌃⌥O` | `Ctrl+Alt+O` | -**重新格式化代码** 格式化选区,没有选区时格式化整个文件,整体算一步撤销。格式化由文件的语言服务器或该语言配置的格式化工具完成(例如 Python 用 Ruff,Web 语言用 Prettier 或 oxfmt;在查找操作里搜 **使用 … 重新格式化** 可以指定工具)。**重新格式化文件…** 还能选择范围并顺便优化导入。 +**重新格式化代码** 格式化选区,没有选区时格式化整个文件,整体算一步撤销。格式化由文件的语言服务器或该语言配置的格式化工具完成(例如 Python 用 Ruff,Web 语言用 Prettier、oxfmt 或 Biome;在查找操作里搜 **使用 … 重新格式化** 可以指定工具)。**重新格式化文件…** 还能选择范围并顺便优化导入。 缩进等代码风格选项在 **设置 › 编辑器 › 代码样式** 中,每种语言一个页面。项目里的 `.editorconfig` 也会生效。 diff --git a/docs/zh/languages/index.mdx b/docs/zh/languages/index.mdx index ed6e661e9..3e098b49c 100644 --- a/docs/zh/languages/index.mdx +++ b/docs/zh/languages/index.mdx @@ -32,7 +32,7 @@ OpenIDEA 用一个小的定义文件 `languages/.toml` 描述每种语言: 一种语言可以配置多个服务器: - **备选**(下表中写作 `a → b`):只运行第一个已安装的。例如 Python 默认用 basedpyright,只有它缺失时才退回 pyright、ty 或 pyrefly。在 **设置 › 语言和框架 › 语言服务器** 中可以指定其中一个,或选 **自动**(使用第一个可用的)。 -- **附加**(写作 `+ b`):和主服务器同时运行,通常只在用到它的项目中启用。带 Ruff 配置的项目里 Ruff 与 basedpyright 一起运行;带 oxlint 配置的项目里 oxlint 与 vtsls 一起运行;Angular、Laravel 和 Tailwind CSS 项目里分别加上 Angular、Laravel 和 Tailwind CSS 的服务器。 +- **附加**(写作 `+ b`):和主服务器同时运行,通常只在用到它的项目中启用。带 Ruff 配置的项目里 Ruff 与 basedpyright 一起运行;带 oxlint 配置的项目里 oxlint 与 vtsls 一起运行;带 Biome 配置或安装了 Biome 的项目里 Biome 与 JavaScript、TypeScript、JSON、CSS 和 GraphQL 的服务器一起运行;Angular、Laravel 和 Tailwind CSS 项目里分别加上 Angular、Laravel 和 Tailwind CSS 的服务器。 ## 安装语言服务器和调试器 @@ -86,92 +86,92 @@ IDE 安装工具从不需要 `sudo`。工具装在本地数据目录下 IDE 自 下表列出全部内置语言定义。**加粗** 的服务器和调试器可以在 IDE 中一键安装,其余需要自行安装(IDE 中的安装提示会说明方法)。"高亮"和"Tree-sitter"两列分别表示是否有即时高亮,以及是否有用于大纲和折叠的内置语法。 -| 语言 | ID | 文件 | 高亮 | Tree-sitter | 语言服务器 | 调试器 | -| ------------------- | ------------------ | ----------------------------------------------------------- | ---- | ----------- | ------------------------------------------------------------------------------------- | ------------------------ | -| .env | `dotenv` | `.env` | 是 | — | — | — | -| Arduino | `arduino` | `.ino` | 是 | 是 | arduino-language-server | — | -| AsciiDoc | `asciidoc` | `.adoc`, `.asciidoc` | 是 | — | — | — | -| Astro | `astro` | `.astro` | 是 | — | **astro-ls** + **oxlint** | — | -| Batch | `bat` | `.bat`, `.cmd` | 是 | — | — | — | -| C | `c` | `.c`, `.h` | 是 | 是 | **clangd** | lldb-dap | -| C# | `csharp` | `.cs`, `.csx` | 是 | 是 | **csharp-ls** | **netcoredbg** | -| C++ | `cpp` | `.cpp`, `.cc`, `.cxx`, `.c++`, `.hpp`, … | 是 | 是 | **clangd** | lldb-dap | -| Clojure | `clojure` | `.clj`, `.cljs`, `.cljc`, `.cljd`, `.edn`, … | 是 | — | **clojure-lsp** | — | -| CMake | `cmake` | `.cmake` | 是 | 是 | **neocmakelsp** → cmake-language-server | — | -| CSS | `css` | `.css`, `.pcss`, `.postcss` | 是 | 是 | **vscode-css-language-server** | — | -| D | `d` | `.d`, `.di` | 是 | — | serve-d | — | -| Dart | `dart` | `.dart` | 是 | 是 | dart | dart | -| Diff | `diff` | `.diff`, `.patch`, `.rej` | 是 | — | — | — | -| Django Template | `django-html` | `.djhtml`, `templates/*.html`, `*.txt` | 是 | 是 | **vscode-html-language-server**, **djlsp** | — | -| Dockerfile | `dockerfile` | `.dockerfile`, `.containerfile` | 是 | — | **dockerfile-language-server** | — | -| Elixir | `elixir` | `.ex`, `.exs` | 是 | 是 | **elixir-ls** | **elixir-ls-debugger** | -| ERB | `erb` | `.erb`, `.html.erb`, `.rhtml`, `.js.erb`, `.text.erb`, … | 是 | — | — | — | -| Erlang | `erlang` | `.erl`, `.hrl`, `.escript`, `.app.src` | 是 | — | elp | — | -| F# | `fsharp` | `.fs`, `.fsi`, `.fsx` | 是 | — | **fsautocomplete** | **netcoredbg** | -| GDScript | `gdscript` | `.gd` | 是 | 是 | godot | godot | -| Git Attributes | `gitattributes` | `.gitattributes` | — | — | — | — | -| Go | `go` | `.go` | 是 | 是 | **gopls** | **delve** | -| Go Module | `go.mod` | `go.mod` | 是 | — | **gopls** | — | -| Go Workspace | `go.work` | `go.work` | 是 | — | **gopls** | — | -| Godot Resource | `godot-resource` | `.tscn`, `.tres`, `.godot`, `.import` | 是 | — | — | — | -| Godot Shader | `gdshader` | `.gdshader`, `.gdshaderinc` | 是 | — | — | — | -| GraphQL | `graphql` | `.graphql`, `.graphqls`, `.gql` | 是 | 是 | **graphql-lsp** | — | -| Groovy | `groovy` | `.groovy`, `.gradle`, `.gvy`, `.gy`, `.gsh` | 是 | — | groovy-language-server | — | -| Haskell | `haskell` | `.hs`, `.hs-boot`, `.hsig` | 是 | 是 | haskell-language-server | — | -| HCL | `hcl` | `.hcl`, `.nomad`, `.pkr.hcl` | 是 | 是 | — | — | -| HTML | `html` | `.html`, `.htm`, `.xhtml`, `.shtml`, `.html.tmpl` | 是 | 是 | **vscode-html-language-server** + **angular-language-server** | — | -| HTTP Request | `http` | `.http`, `.rest` | 是 | — | — | — | -| Ignore File | `ignore` | `.gitignore`, `.dockerignore` | — | — | — | — | -| INI | `ini` | `.ini`, `.cfg`, `.conf`, `.cnf`, `.inf`, … | 是 | — | — | — | -| Java | `java` | `.java` | 是 | 是 | **jdtls** → **java-analyzer** → **kmp-lsp** | **java-debug** | -| JavaScript | `javascript` | `.js`, `.mjs`, `.cjs` | 是 | 是 | **vtsls** → **typescript-language-server** + **oxlint** | **js-debug** | -| JavaScript JSX | `javascriptreact` | `.jsx` | 是 | 是 | **vtsls** → **typescript-language-server** + **oxlint** | **js-debug** | -| JSON | `json` | `.json`, `.geojson`, `.topojson`, `.webmanifest`, `.har`, … | 是 | 是 | **vscode-json-language-server** | — | -| JSON with Comments | `jsonc` | `.jsonc`, `.code-workspace`, `.code-snippets` | 是 | 是 | **vscode-json-language-server** | — | -| JSP | `jsp` | `.jsp`, `.jspx`, `.jspf`, `.jsph`, `.tag`, … | 是 | — | — | — | -| Julia | `julia` | `.jl` | 是 | — | julia-languageserver | — | -| Kotlin | `kotlin` | `.kt`, `.kts` | 是 | 是 | **kotlin-lsp** → **kotlin-language-server** → **kmp-lsp** | **kotlin-debug-adapter** | -| LaTeX | `latex` | `.tex`, `.ltx`, `.sty`, `.cls`, `.dtx`, … | 是 | — | **texlab** | — | -| Less | `less` | `.less` | 是 | — | **vscode-css-language-server** | — | -| Log | `log` | `.log` | 是 | — | — | — | -| Lua | `lua` | `.lua`, `.luau`, `.rockspec` | 是 | 是 | **lua-language-server** | — | -| Makefile | `makefile` | `.mk`, `.mak`, `.make` | 是 | 是 | — | — | -| Markdown | `markdown` | `.md`, `.markdown`, `.mdown`, `.mkd`, `.mkdn`, … | 是 | 是 | **marksman** | — | -| Nix | `nix` | `.nix` | 是 | 是 | nil → nixd | — | -| Objective-C | `objective-c` | `.m` | 是 | — | **clangd** | lldb-dap | -| Objective-C++ | `objective-cpp` | `.mm` | 是 | — | **clangd** | lldb-dap | -| OCaml | `ocaml` | `.ml`, `.mll`, `.mly` | 是 | 是 | ocamllsp | ocamlearlybird | -| OCaml Interface | `ocaml.interface` | `.mli` | 是 | 是 | ocamllsp | — | -| Perl | `perl` | `.pl`, `.pm`, `.pod`, `.psgi`, `.cgi` | 是 | — | **perlnavigator** | — | -| PHP | `php` | `.php`, `.phtml`, `.php3`, `.php4`, `.php5`, … | 是 | 是 | **intelephense** → phpactor → **phoxite** + **laravel-lsp** | **php-debug** | -| Plain Text | `plaintext` | `.txt`, `.text` | — | — | — | — | -| PowerShell | `powershell` | `.ps1`, `.psm1`, `.psd1`, `.pssc`, `.psrc` | 是 | — | powershell-editor-services | — | -| Prisma | `prisma` | `.prisma` | 是 | 是 | **prisma-language-server** | — | -| Properties | `properties` | `.properties`, `.prefs` | 是 | — | — | — | -| Protocol Buffers | `proto` | `.proto` | 是 | 是 | **buf** | — | -| Python | `python` | `.py`, `.pyi`, `.pyw` | 是 | 是 | **basedpyright** → **pyright** → **ty** → **pyrefly** + **ruff** | **debugpy** | -| R | `r` | `.r`, `.rprofile` | 是 | — | r-languageserver | — | -| reStructuredText | `restructuredtext` | `.rst` | 是 | — | — | — | -| Ruby | `ruby` | `.rb`, `.rake`, `.gemspec`, `.ru`, `.rbi`, … | 是 | 是 | **ruby-lsp** → **solargraph** | rdbg | -| Rust | `rust` | `.rs` | 是 | 是 | **rust-analyzer** | **codelldb** | -| Sass | `sass` | `.sass` | 是 | — | — | — | -| Scala | `scala` | `.scala`, `.sc`, `.sbt`, `.mill` | 是 | 是 | metals | — | -| SCSS | `scss` | `.scss` | 是 | — | **vscode-css-language-server** | — | -| Shell Script | `shellscript` | `.sh`, `.bash`, `.zsh`, `.ksh`, `.ash`, … | 是 | 是 | **bash-language-server** | **bash-debug** | -| Slint | `slint` | `.slint` | 是 | — | **slint-lsp** | — | -| SQL | `sql` | `.sql`, `.ddl`, `.dml`, `.psql`, `.pgsql`, … | 是 | — | **sqls** | — | -| Svelte | `svelte` | `.svelte` | 是 | — | **svelte-language-server** + **oxlint** | — | -| Swift | `swift` | `.swift`, `.swiftinterface` | 是 | 是 | sourcekit-lsp | lldb-dap | -| Terraform | `terraform` | `.tf`, `.tofu`, `.tftest.hcl` | 是 | 是 | **terraform-ls** | — | -| Terraform Variables | `terraform-vars` | `.tfvars` | 是 | 是 | **terraform-ls** | — | -| TOML | `toml` | `.toml` | 是 | 是 | **taplo** | — | -| TypeScript | `typescript` | `.ts`, `.mts`, `.cts` | 是 | 是 | **vtsls** → **typescript-language-server** + **angular-language-server** + **oxlint** | **js-debug** | -| TypeScript JSX | `typescriptreact` | `.tsx` | 是 | 是 | **vtsls** → **typescript-language-server** + **oxlint** | **js-debug** | -| Typst | `typst` | `.typ` | — | — | **tinymist** | — | -| Vue | `vue` | `.vue` | 是 | — | **vue-language-server**, **vtsls** + **oxlint** | — | -| XML | `xml` | `.xml`, `.xsd`, `.xsl`, `.xslt`, `.svg`, … | 是 | 是 | **lemminx** | — | -| YAML | `yaml` | `.yaml`, `.yml` | 是 | 是 | **yaml-language-server** | — | -| Zig | `zig` | `.zig`, `.zon` | 是 | 是 | **zls** | **codelldb** | +| 语言 | ID | 文件 | 高亮 | Tree-sitter | 语言服务器 | 调试器 | +| ------------------- | ------------------ | ----------------------------------------------------------- | ---- | ----------- | ------------------------------------------------------------------------------------------------- | ------------------------ | +| .env | `dotenv` | `.env` | 是 | — | — | — | +| Arduino | `arduino` | `.ino` | 是 | 是 | arduino-language-server | — | +| AsciiDoc | `asciidoc` | `.adoc`, `.asciidoc` | 是 | — | — | — | +| Astro | `astro` | `.astro` | 是 | — | **astro-ls** + **oxlint** | — | +| Batch | `bat` | `.bat`, `.cmd` | 是 | — | — | — | +| C | `c` | `.c`, `.h` | 是 | 是 | **clangd** | lldb-dap | +| C# | `csharp` | `.cs`, `.csx` | 是 | 是 | **csharp-ls** | **netcoredbg** | +| C++ | `cpp` | `.cpp`, `.cc`, `.cxx`, `.c++`, `.hpp`, … | 是 | 是 | **clangd** | lldb-dap | +| Clojure | `clojure` | `.clj`, `.cljs`, `.cljc`, `.cljd`, `.edn`, … | 是 | — | **clojure-lsp** | — | +| CMake | `cmake` | `.cmake` | 是 | 是 | **neocmakelsp** → cmake-language-server | — | +| CSS | `css` | `.css`, `.pcss`, `.postcss` | 是 | 是 | **vscode-css-language-server** + **biome** | — | +| D | `d` | `.d`, `.di` | 是 | — | serve-d | — | +| Dart | `dart` | `.dart` | 是 | 是 | dart | dart | +| Diff | `diff` | `.diff`, `.patch`, `.rej` | 是 | — | — | — | +| Django Template | `django-html` | `.djhtml`, `templates/*.html`, `*.txt` | 是 | 是 | **vscode-html-language-server**, **djlsp** | — | +| Dockerfile | `dockerfile` | `.dockerfile`, `.containerfile` | 是 | — | **dockerfile-language-server** | — | +| Elixir | `elixir` | `.ex`, `.exs` | 是 | 是 | **elixir-ls** | **elixir-ls-debugger** | +| ERB | `erb` | `.erb`, `.html.erb`, `.rhtml`, `.js.erb`, `.text.erb`, … | 是 | — | — | — | +| Erlang | `erlang` | `.erl`, `.hrl`, `.escript`, `.app.src` | 是 | — | elp | — | +| F# | `fsharp` | `.fs`, `.fsi`, `.fsx` | 是 | — | **fsautocomplete** | **netcoredbg** | +| GDScript | `gdscript` | `.gd` | 是 | 是 | godot | godot | +| Git Attributes | `gitattributes` | `.gitattributes` | — | — | — | — | +| Go | `go` | `.go` | 是 | 是 | **gopls** | **delve** | +| Go Module | `go.mod` | `go.mod` | 是 | — | **gopls** | — | +| Go Workspace | `go.work` | `go.work` | 是 | — | **gopls** | — | +| Godot Resource | `godot-resource` | `.tscn`, `.tres`, `.godot`, `.import` | 是 | — | — | — | +| Godot Shader | `gdshader` | `.gdshader`, `.gdshaderinc` | 是 | — | — | — | +| GraphQL | `graphql` | `.graphql`, `.graphqls`, `.gql` | 是 | 是 | **graphql-lsp** + **biome** | — | +| Groovy | `groovy` | `.groovy`, `.gradle`, `.gvy`, `.gy`, `.gsh` | 是 | — | groovy-language-server | — | +| Haskell | `haskell` | `.hs`, `.hs-boot`, `.hsig` | 是 | 是 | haskell-language-server | — | +| HCL | `hcl` | `.hcl`, `.nomad`, `.pkr.hcl` | 是 | 是 | — | — | +| HTML | `html` | `.html`, `.htm`, `.xhtml`, `.shtml`, `.html.tmpl` | 是 | 是 | **vscode-html-language-server** + **angular-language-server** | — | +| HTTP Request | `http` | `.http`, `.rest` | 是 | — | — | — | +| Ignore File | `ignore` | `.gitignore`, `.dockerignore` | — | — | — | — | +| INI | `ini` | `.ini`, `.cfg`, `.conf`, `.cnf`, `.inf`, … | 是 | — | — | — | +| Java | `java` | `.java` | 是 | 是 | **jdtls** → **java-analyzer** → **kmp-lsp** | **java-debug** | +| JavaScript | `javascript` | `.js`, `.mjs`, `.cjs` | 是 | 是 | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | +| JavaScript JSX | `javascriptreact` | `.jsx` | 是 | 是 | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | +| JSON | `json` | `.json`, `.geojson`, `.topojson`, `.webmanifest`, `.har`, … | 是 | 是 | **vscode-json-language-server** + **biome** | — | +| JSON with Comments | `jsonc` | `.jsonc`, `.code-workspace`, `.code-snippets` | 是 | 是 | **vscode-json-language-server** + **biome** | — | +| JSP | `jsp` | `.jsp`, `.jspx`, `.jspf`, `.jsph`, `.tag`, … | 是 | — | — | — | +| Julia | `julia` | `.jl` | 是 | — | julia-languageserver | — | +| Kotlin | `kotlin` | `.kt`, `.kts` | 是 | 是 | **kotlin-lsp** → **kotlin-language-server** → **kmp-lsp** | **kotlin-debug-adapter** | +| LaTeX | `latex` | `.tex`, `.ltx`, `.sty`, `.cls`, `.dtx`, … | 是 | — | **texlab** | — | +| Less | `less` | `.less` | 是 | — | **vscode-css-language-server** | — | +| Log | `log` | `.log` | 是 | — | — | — | +| Lua | `lua` | `.lua`, `.luau`, `.rockspec` | 是 | 是 | **lua-language-server** | — | +| Makefile | `makefile` | `.mk`, `.mak`, `.make` | 是 | 是 | — | — | +| Markdown | `markdown` | `.md`, `.markdown`, `.mdown`, `.mkd`, `.mkdn`, … | 是 | 是 | **marksman** | — | +| Nix | `nix` | `.nix` | 是 | 是 | nil → nixd | — | +| Objective-C | `objective-c` | `.m` | 是 | — | **clangd** | lldb-dap | +| Objective-C++ | `objective-cpp` | `.mm` | 是 | — | **clangd** | lldb-dap | +| OCaml | `ocaml` | `.ml`, `.mll`, `.mly` | 是 | 是 | ocamllsp | ocamlearlybird | +| OCaml Interface | `ocaml.interface` | `.mli` | 是 | 是 | ocamllsp | — | +| Perl | `perl` | `.pl`, `.pm`, `.pod`, `.psgi`, `.cgi` | 是 | — | **perlnavigator** | — | +| PHP | `php` | `.php`, `.phtml`, `.php3`, `.php4`, `.php5`, … | 是 | 是 | **intelephense** → phpactor → **phoxite** + **laravel-lsp** | **php-debug** | +| Plain Text | `plaintext` | `.txt`, `.text` | — | — | — | — | +| PowerShell | `powershell` | `.ps1`, `.psm1`, `.psd1`, `.pssc`, `.psrc` | 是 | — | powershell-editor-services | — | +| Prisma | `prisma` | `.prisma` | 是 | 是 | **prisma-language-server** | — | +| Properties | `properties` | `.properties`, `.prefs` | 是 | — | — | — | +| Protocol Buffers | `proto` | `.proto` | 是 | 是 | **buf** | — | +| Python | `python` | `.py`, `.pyi`, `.pyw` | 是 | 是 | **basedpyright** → **pyright** → **ty** → **pyrefly** + **ruff** | **debugpy** | +| R | `r` | `.r`, `.rprofile` | 是 | — | r-languageserver | — | +| reStructuredText | `restructuredtext` | `.rst` | 是 | — | — | — | +| Ruby | `ruby` | `.rb`, `.rake`, `.gemspec`, `.ru`, `.rbi`, … | 是 | 是 | **ruby-lsp** → **solargraph** | rdbg | +| Rust | `rust` | `.rs` | 是 | 是 | **rust-analyzer** | **codelldb** | +| Sass | `sass` | `.sass` | 是 | — | — | — | +| Scala | `scala` | `.scala`, `.sc`, `.sbt`, `.mill` | 是 | 是 | metals | — | +| SCSS | `scss` | `.scss` | 是 | — | **vscode-css-language-server** | — | +| Shell Script | `shellscript` | `.sh`, `.bash`, `.zsh`, `.ksh`, `.ash`, … | 是 | 是 | **bash-language-server** | **bash-debug** | +| Slint | `slint` | `.slint` | 是 | — | **slint-lsp** | — | +| SQL | `sql` | `.sql`, `.ddl`, `.dml`, `.psql`, `.pgsql`, … | 是 | — | **sqls** | — | +| Svelte | `svelte` | `.svelte` | 是 | — | **svelte-language-server** + **oxlint** | — | +| Swift | `swift` | `.swift`, `.swiftinterface` | 是 | 是 | sourcekit-lsp | lldb-dap | +| Terraform | `terraform` | `.tf`, `.tofu`, `.tftest.hcl` | 是 | 是 | **terraform-ls** | — | +| Terraform Variables | `terraform-vars` | `.tfvars` | 是 | 是 | **terraform-ls** | — | +| TOML | `toml` | `.toml` | 是 | 是 | **taplo** | — | +| TypeScript | `typescript` | `.ts`, `.mts`, `.cts` | 是 | 是 | **vtsls** → **typescript-language-server** + **angular-language-server** + **oxlint** + **biome** | **js-debug** | +| TypeScript JSX | `typescriptreact` | `.tsx` | 是 | 是 | **vtsls** → **typescript-language-server** + **oxlint** + **biome** | **js-debug** | +| Typst | `typst` | `.typ` | — | — | **tinymist** | — | +| Vue | `vue` | `.vue` | 是 | — | **vue-language-server**, **vtsls** + **oxlint** | — | +| XML | `xml` | `.xml`, `.xsd`, `.xsl`, `.xslt`, `.svg`, … | 是 | 是 | **lemminx** | — | +| YAML | `yaml` | `.yaml`, `.yml` | 是 | 是 | **yaml-language-server** | — | +| Zig | `zig` | `.zig`, `.zon` | 是 | 是 | **zls** | **codelldb** | 说明: diff --git a/docs/zh/languages/javascript.mdx b/docs/zh/languages/javascript.mdx index 2c17247df..c99b3f53c 100644 --- a/docs/zh/languages/javascript.mdx +++ b/docs/zh/languages/javascript.mdx @@ -17,6 +17,7 @@ OpenIDEA 打开 JavaScript(`.js`、`.mjs`、`.cjs`、`.jsx`)和 TypeScript | Angular 项目中的 TS 和 HTML | `angular-language-server`(`ngserver`) | 只在 `angular.json` 或 `node_modules/@angular/core` 所在目录之下启用。 | | 以上全部 | `oxlint` | 只在存在 `.oxlintrc.json`、`.oxlintrc.jsonc`、`oxlint.config.ts` 或 `oxlint.config.mts` 的目录之下启用。 | | 以上全部 | `vscode-eslint-language-server`(ESLint) | 只在 ESLint 配置(`eslint.config.*`、`.eslintrc*` 或 `package.json` 中的 `eslintConfig`)所在目录之下启用,运行项目自己的 `eslint`。 | +| JS、JSX、TS、TSX、JSON、CSS | `biome lsp-proxy`(Biome) | 只在 `biome.json` / `biome.jsonc` 所在目录或安装了 `@biomejs/biome` 的项目之下启用,运行项目自己的 `biome`。 | | 以上全部及 HTML、CSS | `tailwindcss-language-server`(Tailwind CSS) | 只在 `tailwind.config.*` 或依赖了 `tailwindcss` 的 `package.json` 所在目录之下启用:类名补全、悬停显示生成的 CSS、类名诊断。 | TypeScript 服务器以 `tsconfig.json`、`jsconfig.json` 或 `package.json` 所在目录为工作区根。不属于任何 `tsconfig.json` / `jsconfig.json` 的文件也会注册给 tsserver,零散脚本同样有代码智能。 @@ -50,6 +51,7 @@ Vue、Astro 和 Angular 服务器也会使用这里选择的版本。TypeScript | `oxlint` | npm | | `tailwindcss-language-server` | npm(`@tailwindcss/language-server`) | | Prettier、oxfmt | npm | +| Prettier、oxfmt、Biome | npm | | JavaScript 调试器(vscode-js-debug) | GitHub release(`microsoft/vscode-js-debug`) | 如果项目自己的 `node_modules/.bin` 里有 Astro 或 Angular 服务器,会优先使用项目里的。 @@ -69,8 +71,13 @@ Vue、Astro 和 Angular 服务器也会使用这里选择的版本。TypeScript - **Prettier**(**设置 › 语言和框架 › Prettier**)默认处理 JavaScript、JSX、TypeScript、TSX、JSON、Vue、HTML、CSS、SCSS、Less、GraphQL、YAML 和 Markdown。未设置 **Prettier 路径** 时,依次查找项目 `node_modules`、IDE 管理的安装、`PATH`。 - **oxfmt**(**设置 › 语言和框架 › oxfmt**)在 oxfmt 配置文件(`.oxfmtrc.json`、`oxfmt.config.ts`)所在目录之下,或被选为格式化工具时,替代 Prettier 处理已启用的语言。 +- **Biome**(**设置 › 语言和框架 › Biome**)在 `biome.json` / `biome.jsonc` 所在目录或安装了 `@biomejs/biome` 的项目之下(配置里 `formatter.enabled` 为 `false` 时除外),或被选为格式化工具时,替代 Prettier 和 oxfmt 处理 JavaScript、JSX、TypeScript、TSX、JSON、CSS 和 GraphQL。它总是格式化整个文件,并读取自己的配置。 -两个页面上,**格式化工具** 可选 **自动(优先语言服务器)** 或工具本身,**保存时运行** 控制保存时格式化,**启用的语言** 限定工具处理哪些语言。 +这些页面上,**格式化工具** 可选 **自动(优先语言服务器)** 或工具本身,**保存时运行** 控制保存时格式化,**启用的语言** 限定工具处理哪些语言。 + +### Biome 检查 + +在 Biome 项目中,Biome 的诊断显示在编辑器和“问题”工具窗口里,`⌥⏎` / `Alt+Enter` 提供它的快速修复和抑制。Biome 的安全修复(`source.fixAll.biome`)随 **代码 › 代码清理** 运行;开启 **设置 › 工具 › 保存时操作 › 运行代码清理** 后,保存时也会运行。Biome 的格式化器开启时,它的全部修复也会格式化文件。 ## 运行与测试 diff --git a/docs/zh/reference/settings.mdx b/docs/zh/reference/settings.mdx index 513ae0301..c544cb0b7 100644 --- a/docs/zh/reference/settings.mdx +++ b/docs/zh/reference/settings.mdx @@ -55,7 +55,7 @@ exclude = ["**/.git", "**/node_modules", "**/target", "**/dist"] | 插件 | 插件 | | 版本控制 | 提交;确认;目录映射;问题导航;日志;搁置;Git;GitHub | | 构建、执行、部署 | CMake;Gradle;Maven;控制台;调试器(数据视图、单步执行);Python 调试器;运行/调试;运行目标;部署(选项) | -| 语言和框架 | 语言服务器;Go(构建标签、Go 模块);Java;Markdown;Node.js;PHP;Python 解释器;Prettier;oxfmt;Ruff;Ruby;Rust;TypeScript | +| 语言和框架 | 语言服务器;Go(构建标签、Go 模块);Java;Markdown;Node.js;PHP;Python 解释器;Prettier;oxfmt;Biome;Ruff;Ruby;Rust;TypeScript | | 工具 | 智能体(聊天);终端;保存时操作;外部工具;SSH 配置;MCP 服务器 | | 安全 | 项目信任 | diff --git a/fixtures/README.md b/fixtures/README.md index cfb2627a9..d2fc276df 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -21,6 +21,7 @@ something to show. | `django-app/` | Python 3.10+, Django 5.2+ | `python manage.py runserver` | `python manage.py test` | `OPENIDEA_FAIL=1 python manage.py test` | unused import in `shop/views.py` | | `tailwind-app/` | Node 22+, pnpm/npm, Tailwind CSS 4, React | `pnpm dev` | — | — | `flex` conflicting with `block` in `src/App.tsx` | | `zig-app/` | Zig 0.17 | `zig build run` | `zig build test` | — | — | +| `biome-app/` | Node 22+, `@biomejs/biome` (`npm install`) | `npm start` | — | — | `let` never reassigned, `==` and a duplicate CSS `color` (Biome) | | `polyglot/` | Go, TS, Python, C, shell, SQL, TOML/YAML/JSON, proto, Terraform | `make` | `make test` | — | unused variable in `native/hash.c` | The fixtures are standalone: `rust-app` declares its own `[workspace]` and @@ -43,7 +44,7 @@ git init -q && git add -A && git commit -qm "initial" # for the VCS checks ``` Then open the folder with **File › Open…** (`⌘⇧⌥O`) or from the Welcome screen. -For `ts-app` / `playwright-app` / `mocha-app` / `polyglot/web` run `pnpm install` first; for `python-app` create a +For `ts-app` / `playwright-app` / `mocha-app` / `polyglot/web` run `pnpm install` first (`npm install` for `biome-app`); for `python-app` create a venv (`python3 -m venv .venv && .venv/bin/pip install -e '.[dev]'`); for `php-app` run `composer install` (debugging it needs Xdebug in the PHP on `PATH`). diff --git a/fixtures/biome-app/biome.json b/fixtures/biome-app/biome.json new file mode 100644 index 000000000..9b1e4aa56 --- /dev/null +++ b/fixtures/biome-app/biome.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.6.8/schema.json", + "files": { + "includes": ["**", "!node_modules"] + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2, + "lineWidth": 100 + }, + "javascript": { + "formatter": { + "quoteStyle": "single" + } + }, + "linter": { + "enabled": true, + "rules": { + "preset": "recommended", + "style": { + "useConst": "error", + "useTemplate": "warn" + } + } + } +} diff --git a/fixtures/biome-app/package.json b/fixtures/biome-app/package.json new file mode 100644 index 000000000..265711ee1 --- /dev/null +++ b/fixtures/biome-app/package.json @@ -0,0 +1,16 @@ +{ + "name": "openidea-fixture-biome", + "version": "0.1.0", + "private": true, + "description": "OpenIDEA QA fixture: Biome lint diagnostics, fixes and formatting", + "type": "module", + "scripts": { + "start": "node --experimental-strip-types src/index.ts", + "lint": "biome lint", + "format": "biome format --write", + "check": "biome check" + }, + "devDependencies": { + "@biomejs/biome": "2.6.8" + } +} diff --git a/fixtures/biome-app/src/cart.ts b/fixtures/biome-app/src/cart.ts new file mode 100644 index 000000000..946888972 --- /dev/null +++ b/fixtures/biome-app/src/cart.ts @@ -0,0 +1,21 @@ +export interface Item { + name: string + price: number + quantity: number +} + +export function total(items: Item[]): number { + let sum = 0 + for (const item of items) sum += item.price * item.quantity + return sum +} + +// Intentional Biome problems: `let` never reassigned (useConst, safe fix), +// string concatenation (useTemplate) and `==` (noDoubleEquals). +export function describe(items: Item[]): string { + let label = "Cart: " + items.length + " items" + if (items.length == 0) { + return "Cart is empty" + } + return label +} diff --git a/fixtures/biome-app/src/data.json b/fixtures/biome-app/src/data.json new file mode 100644 index 000000000..16c995841 --- /dev/null +++ b/fixtures/biome-app/src/data.json @@ -0,0 +1,2 @@ +{ "currency": "EUR", + "discounts": [ 5, 10,15 ] } diff --git a/fixtures/biome-app/src/index.ts b/fixtures/biome-app/src/index.ts new file mode 100644 index 000000000..d802a35c5 --- /dev/null +++ b/fixtures/biome-app/src/index.ts @@ -0,0 +1,9 @@ +import { describe, total, type Item } from "./cart.ts" + +const items: Item[] = [ + { name: "Notebook", price: 4.5, quantity: 2 }, + { name: "Pen", price: 1.25, quantity: 4 }, +] + +// Set a breakpoint here +console.log(describe(items), "-", total(items).toFixed(2)) diff --git a/fixtures/biome-app/src/theme.css b/fixtures/biome-app/src/theme.css new file mode 100644 index 000000000..03478b772 --- /dev/null +++ b/fixtures/biome-app/src/theme.css @@ -0,0 +1,6 @@ +/* Intentional Biome problem: `color` is declared twice (noDuplicateProperties). */ +.cart { + color: #333; + padding:4px 8px; + color: #444; +} diff --git a/languages/css.toml b/languages/css.toml index 4c81bbde6..114a15205 100644 --- a/languages/css.toml +++ b/languages/css.toml @@ -14,6 +14,17 @@ args = ["--stdio"] initialization-options = { provideFormatter = true, css = {}, scss = {}, less = {} } install-hint = "npm i -g vscode-langservers-extracted" +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" + # Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind # (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, # which answer hover first. diff --git a/languages/graphql.toml b/languages/graphql.toml index 7e1c1f43f..c4e9db1a0 100644 --- a/languages/graphql.toml +++ b/languages/graphql.toml @@ -12,3 +12,14 @@ command = "graphql-lsp" args = ["server", "-m", "stream"] root-markers = [".graphqlrc", ".graphqlrc.yml", ".graphqlrc.yaml", ".graphqlrc.json", "graphql.config.js", "graphql.config.ts", "graphql.config.yml", "graphql.config.yaml", "graphql.config.json"] install-hint = "npm i -g graphql-language-service-cli" + +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" diff --git a/languages/javascript.toml b/languages/javascript.toml index a8b95c397..d41e96570 100644 --- a/languages/javascript.toml +++ b/languages/javascript.toml @@ -106,6 +106,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" + # Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind # (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, # which answer hover first. diff --git a/languages/javascriptreact.toml b/languages/javascriptreact.toml index b744b8139..9dc7cc15e 100644 --- a/languages/javascriptreact.toml +++ b/languages/javascriptreact.toml @@ -109,6 +109,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" + # Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind # (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, # which answer hover first. diff --git a/languages/json.toml b/languages/json.toml index 34403bc0a..94f29d350 100644 --- a/languages/json.toml +++ b/languages/json.toml @@ -58,3 +58,14 @@ url = "https://swc.rs/schema.json" [[language-servers.settings.json.schemas]] fileMatch = ["composer.json"] url = "https://getcomposer.org/schema.json" + +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" diff --git a/languages/jsonc.toml b/languages/jsonc.toml index c32b4a235..bb76a0a37 100644 --- a/languages/jsonc.toml +++ b/languages/jsonc.toml @@ -60,3 +60,14 @@ url = "https://swc.rs/schema.json" [[language-servers.settings.json.schemas]] fileMatch = ["composer.json"] url = "https://getcomposer.org/schema.json" + +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" diff --git a/languages/typescript.toml b/languages/typescript.toml index 08f65b3a1..0d1031bc7 100644 --- a/languages/typescript.toml +++ b/languages/typescript.toml @@ -124,6 +124,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" + # Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind # (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, # which answer hover first. diff --git a/languages/typescriptreact.toml b/languages/typescriptreact.toml index 33b67c090..b829399f5 100644 --- a/languages/typescriptreact.toml +++ b/languages/typescriptreact.toml @@ -110,6 +110,17 @@ codeAction = { disableRuleComment = { enable = true, location = "separateLine" } # No `rules`: an empty list there means no rule gets fixed. codeActionOnSave = { mode = "all" } +# Biome: lint diagnostics, quick fixes and fix-all below a Biome configuration or installation, +# from the project's own biome. Formatting is Reformat Code's (Settings › Biome). +[[language-servers]] +name = "biome" +command = "biome" +args = ["lsp-proxy"] +root-markers = ["biome.json", "biome.jsonc", "node_modules/@biomejs/biome"] +require-root-marker = true +features = ["code-action", "diagnostics"] +install-hint = "npm i -D @biomejs/biome" + # Tailwind CSS: class completion, hover and diagnostics, only in a project that uses Tailwind # (`tailwind.config.*` or `tailwindcss` in package.json). After the language's own servers, # which answer hover first. diff --git a/src/bindings.ts b/src/bindings.ts index fd99cede9..08b0ef752 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -6267,11 +6267,11 @@ export type ExternalDiffSide = { }; /** A formatter that runs outside the language servers, with its own settings group. */ -export type ExternalFormatter = "prettier" | "oxfmt" | "ruff"; +export type ExternalFormatter = "prettier" | "oxfmt" | "biome" | "ruff"; -/** An external formatter (Prettier, oxfmt, Ruff) and the languages it formats. */ +/** An external formatter (Prettier, oxfmt, Biome, Ruff) and the languages it formats. */ export type ExternalFormatterSettings = { - /** Empty path: project node_modules (Prettier/oxfmt), managed installation, then PATH. */ + /** Empty path: project node_modules (Prettier/oxfmt/Biome), managed installation, then PATH. */ path?: string, /** Ruff only: directory containing its configuration, or a configuration file. */ configurationDirectory?: string, @@ -8349,6 +8349,7 @@ export type LanguagesSettings = { typescript?: TypeScriptSettings, prettier?: ExternalFormatterSettings, oxfmt?: ExternalFormatterSettings, + biome?: ExternalFormatterSettings, ruff?: ExternalFormatterSettings, java?: JavaSettings, ruby?: RubySettings, diff --git a/src/editor/lsp/actions.ts b/src/editor/lsp/actions.ts index 7644849a2..891619c27 100644 --- a/src/editor/lsp/actions.ts +++ b/src/editor/lsp/actions.ts @@ -195,10 +195,10 @@ function editorAction( /** Whether saving a `language` file formats it: Format on save, or Run on save of an external formatter. */ export function formatsOnSave(settings: Settings | null, language: string): boolean { - const { prettier, oxfmt, ruff } = validateLanguages(settings?.languages); + const { prettier, oxfmt, biome, ruff } = validateLanguages(settings?.languages); return ( !!settings?.editor?.formatOnSave || - [prettier, oxfmt, ruff].some((formatter) => formatter.runOnSave && formatter.languages.includes(language)) + [prettier, oxfmt, biome, ruff].some((formatter) => formatter.runOnSave && formatter.languages.includes(language)) ); } @@ -275,6 +275,13 @@ export function registerLspActions(): () => void { (v) => formatDocument(v, { explicit: true, tool: "oxfmt" }), { keywords: ["format", "oxfmt", "oxc"] }, ), + editorAction( + "code.reformatWithBiome", + "Reformat with Biome", + "Code", + (v) => formatDocument(v, { explicit: true, tool: "biome" }), + { keywords: ["format", "biome"] }, + ), editorAction( "code.reformatWithRuff", "Reformat with Ruff", diff --git a/src/editor/lsp/format.test.ts b/src/editor/lsp/format.test.ts index d108b5303..c8a4af782 100644 --- a/src/editor/lsp/format.test.ts +++ b/src/editor/lsp/format.test.ts @@ -173,13 +173,15 @@ describe("format on save provider isolation", () => { } }); - it("formats on save for the languages whose Prettier or oxfmt Run on save is on", () => { + it("formats on save for the languages whose Prettier, oxfmt or Biome Run on save is on", () => { const settings = (languages: Settings["languages"], formatOnSave = false) => ({ editor: { formatOnSave }, languages }) as Settings; const oxfmt = settings({ oxfmt: { runOnSave: true, languages: ["typescript"] } }); expect(formatsOnSave(oxfmt, "typescript")).toBe(true); expect(formatsOnSave(oxfmt, "markdown")).toBe(false); expect(formatsOnSave(settings({ prettier: { runOnSave: true } }), "markdown")).toBe(true); + expect(formatsOnSave(settings({ biome: { runOnSave: true } }), "json")).toBe(true); + expect(formatsOnSave(settings({ biome: { runOnSave: true } }), "markdown")).toBe(false); expect(formatsOnSave(settings({ ruff: { runOnSave: true } }), "python")).toBe(true); expect(formatsOnSave(settings({ ruff: { runOnSave: true } }), "typescript")).toBe(false); expect(formatsOnSave(settings({}), "typescript")).toBe(false); diff --git a/src/editor/lsp/format.ts b/src/editor/lsp/format.ts index bb91d16e5..9f4b0cc41 100644 --- a/src/editor/lsp/format.ts +++ b/src/editor/lsp/format.ts @@ -96,7 +96,7 @@ interface FormatDocumentOptions { explicit: boolean; selectionOnly?: boolean; onSave?: boolean; - /** Runs this external formatter whatever the settings select (Reformat with Prettier/oxfmt). */ + /** Runs this external formatter whatever the settings select (Reformat with Prettier/oxfmt/Biome). */ tool?: ExternalFormatter; /** Formats only these ranges, e.g. the text changed since the last commit; an empty list formats nothing. */ ranges?: readonly OffsetRange[]; @@ -176,6 +176,7 @@ async function format(view: EditorView, opts: FormatDocumentOptions): Promise { _resetI18nForTests(); }); -describe.each(["prettier", "oxfmt", "ruff"])("%s formatter errors", (name) => { +describe.each(["prettier", "oxfmt", "biome", "ruff"])("%s formatter errors", (name) => { const tool = { type: "tool", tool: name, missing: false } as const; - const display = name === "prettier" ? "Prettier" : name === "ruff" ? "Ruff" : name; + const display = ({ prettier: "Prettier", biome: "Biome", ruff: "Ruff" } as Record)[name] ?? name; it("uses structured missing-tool information to request the shared install prompt", async () => { const prompt = vi.fn(); const dispose = registerAction({ @@ -130,6 +130,7 @@ describe("Reformat with an external formatter", () => { it.each([ ["code.reformatWithPrettier", "prettier"], ["code.reformatWithOxfmt", "oxfmt"], + ["code.reformatWithBiome", "biome"], ["code.reformatWithRuff", "ruff"], ])("%s asks the backend for %s whatever the settings select", async (id, tool) => { vi.spyOn(lsp, "lspRequest").mockImplementation(async (request) => { diff --git a/src/features/settings/__tests__/languages.test.ts b/src/features/settings/__tests__/languages.test.ts index afb045566..8d639d552 100644 --- a/src/features/settings/__tests__/languages.test.ts +++ b/src/features/settings/__tests__/languages.test.ts @@ -184,6 +184,16 @@ describe("languages settings", () => { expect(v.prettier).toMatchObject({ runOnSave: true, prefer: false, path: "" }); }); + it("gives Biome the opt-in settings for the languages it formats", () => { + expect(validateLanguages({}).biome).toEqual({ + ...DEFAULT_LANGUAGES.prettier, + languages: ["css", "graphql", "javascript", "javascriptreact", "typescript", "typescriptreact", "json", "jsonc"], + }); + const v = validateLanguages({ biome: { languages: ["json"], prefer: true, runOnSave: true } }); + expect(v.biome).toMatchObject({ languages: ["json"], prefer: true, runOnSave: true }); + expect(v.prettier).toMatchObject({ prefer: false, runOnSave: false }); + }); + it("enables Ruff for Python by default and keeps its settings separate", () => { expect(validateLanguages({}).ruff).toMatchObject({ path: "", @@ -370,6 +380,7 @@ describe("language pages", () => { "PHP", "Prettier", "oxfmt", + "Biome", "Ruby", "Rust", "TypeScript", diff --git a/src/features/settings/languages/FormatterPage.tsx b/src/features/settings/languages/FormatterPage.tsx index bc60f350c..8132ef3fb 100644 --- a/src/features/settings/languages/FormatterPage.tsx +++ b/src/features/settings/languages/FormatterPage.tsx @@ -145,6 +145,18 @@ export function OxfmtPage() { ); } +export function BiomePage() { + return ( + + ); +} + export function RuffPage() { return ( import("../languages/FormatterPage").then((m) => m.PrettierPage), ); const OxfmtPage = lazyPage("languages.oxfmt", () => import("../languages/FormatterPage").then((m) => m.OxfmtPage)); +const BiomePage = lazyPage("languages.biome", () => import("../languages/FormatterPage").then((m) => m.BiomePage)); const DocstringsPage = lazyPage("python.docstrings", () => import("../languages/DocstringsPage").then((m) => m.DocstringsPage), ); @@ -201,6 +202,16 @@ export const LANGUAGE_PAGES: PageSpec[] = [ keywords: ["formatter", "oxfmt", "oxc", ".oxfmtrc.json", "format on save", "node_modules"], component: OxfmtPage, }, + { + id: "languages.biome", + projectScope: true, + defaultScope: "project", + title: "Biome", + group: LANGUAGES_GROUP, + order: 403.7, + keywords: ["formatter", "linter", "biome", "biome.json", "format on save", "node_modules"], + component: BiomePage, + }, { id: "python.docstrings", title: "Docstrings", diff --git a/src/platform/languageSettings.ts b/src/platform/languageSettings.ts index c6e8b8d9b..d9efff848 100644 --- a/src/platform/languageSettings.ts +++ b/src/platform/languageSettings.ts @@ -26,7 +26,7 @@ const DEFAULT_GO_BUILD_TAGS: GoBuildTags = { experiments: "", }; -/** An external formatter (Prettier, oxfmt, Ruff) and the languages it formats. */ +/** An external formatter (Prettier, oxfmt, Biome, Ruff) and the languages it formats. */ interface ExternalFormatterValid { path: string; configurationDirectory: string; @@ -58,6 +58,12 @@ const DEFAULT_FORMATTER: ExternalFormatterValid = { runOnSave: false, }; +/** Biome formats these of Prettier's languages (`BIOME_LANGUAGES` in `ide-core`). */ +const DEFAULT_BIOME_FORMATTER: ExternalFormatterValid = { + ...DEFAULT_FORMATTER, + languages: ["css", "graphql", "javascript", "javascriptreact", "typescript", "typescriptreact", "json", "jsonc"], +}; + const DEFAULT_RUFF_FORMATTER: ExternalFormatterValid = { ...DEFAULT_FORMATTER, languages: ["python"], @@ -201,6 +207,7 @@ export interface LanguagesValid { typescript: { version: string }; prettier: ExternalFormatterValid; oxfmt: ExternalFormatterValid; + biome: ExternalFormatterValid; ruff: ExternalFormatterValid; java: { jdk: string; @@ -312,6 +319,7 @@ export const DEFAULT_LANGUAGES: LanguagesValid = { typescript: { version: "bundled" }, prettier: DEFAULT_FORMATTER, oxfmt: DEFAULT_FORMATTER, + biome: DEFAULT_BIOME_FORMATTER, ruff: DEFAULT_RUFF_FORMATTER, java: { jdk: "", @@ -486,6 +494,7 @@ export function validateLanguages(raw: unknown): LanguagesValid { typescript: { version: text(ts.version, d.typescript.version) || d.typescript.version }, prettier: validateFormatter(l.prettier), oxfmt: validateFormatter(l.oxfmt), + biome: validateFormatter(l.biome, DEFAULT_BIOME_FORMATTER), ruff: validateFormatter(l.ruff, DEFAULT_RUFF_FORMATTER), java: { jdk: text(java.jdk, d.java.jdk), diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 32a8993d5..65425a2f6 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,10 @@ { + "Reformat with Biome": "Reformat with Biome", + "Biome path": "Biome path", + "Biome formats an enabled language instead of Prettier and oxfmt below a Biome configuration file (biome.json, biome.jsonc) or installation, or when it is the selected provider.": "Biome formats an enabled language instead of Prettier and oxfmt below a Biome configuration file (biome.json, biome.jsonc) or installation, or when it is the selected provider.", + "Run Biome on save for enabled languages when it is the selected formatting provider.": "Run Biome on save for enabled languages when it is the selected formatting provider.", + "Biome formatting failed": "Biome formatting failed", + "Biome formatting timed out": "Biome formatting timed out", "$ unchanged lines": "$ unchanged lines", "Expand unchanged lines": "Expand unchanged lines", "Matching scope": "Matching scope", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 0b3579618..4b6389493 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1,4 +1,10 @@ { + "Reformat with Biome": "使用 Biome 重新格式化", + "Biome path": "Biome 路径", + "Biome formats an enabled language instead of Prettier and oxfmt below a Biome configuration file (biome.json, biome.jsonc) or installation, or when it is the selected provider.": "在 Biome 配置文件(biome.json、biome.jsonc)或 Biome 安装所在目录及其子目录中,或选择 Biome 作为格式化工具时,Biome 将代替 Prettier 和 oxfmt 格式化已启用的语言。", + "Run Biome on save for enabled languages when it is the selected formatting provider.": "对已启用的语言,在选择 Biome 作为格式化工具时于保存时运行。", + "Biome formatting failed": "Biome 格式化失败", + "Biome formatting timed out": "Biome 格式化超时", "$ unchanged lines": "$ 行未改动", "Expand unchanged lines": "展开未改动的行", "Matching scope": "匹配的代码块", diff --git a/src/platform/locales/textCatalog.test.ts b/src/platform/locales/textCatalog.test.ts index 5e6c12301..2c0f5547f 100644 --- a/src/platform/locales/textCatalog.test.ts +++ b/src/platform/locales/textCatalog.test.ts @@ -96,6 +96,7 @@ const UNTRANSLATED = new Set([ "Flutter", "Prettier", "oxfmt", + "Biome", "Ruff", "IntelliJ IDEA", "GitHub",