From 2a2a6f685100e5fc62868084c1f1e71b5618a231 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Sat, 19 Oct 2024 14:18:38 +0200 Subject: [PATCH] Implement single-file plugin loading --- crates/biome_plugin_loader/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/biome_plugin_loader/src/lib.rs b/crates/biome_plugin_loader/src/lib.rs index 9c1c659d568d..30ae44715f08 100644 --- a/crates/biome_plugin_loader/src/lib.rs +++ b/crates/biome_plugin_loader/src/lib.rs @@ -45,6 +45,19 @@ impl BiomePlugin { .into_path_buf() }; + // If the plugin path references a `.grit` file directly, treat it as + // a single-rule plugin instead of going through the manifest process: + if plugin_path + .as_os_str() + .as_encoded_bytes() + .ends_with(b".grit") + { + let plugin = AnalyzerGritPlugin::load(fs, &plugin_path)?; + return Ok(Self { + analyzer_plugins: vec![Box::new(plugin) as Box], + }); + } + let manifest_path = plugin_path.join("biome-manifest.jsonc"); if !fs.path_is_file(&manifest_path) { return Err(PluginDiagnostic::cant_resolve( @@ -166,4 +179,14 @@ mod test { .expect_err("Plugin loading should've failed"); snap_diagnostic("load_plugin_with_wrong_rule_extension", error.into()); } + + #[test] + fn load_single_rule_plugin() { + let mut fs = MemoryFileSystem::default(); + fs.insert("/my-plugin.grit".into(), r#"`hello`"#); + + let plugin = BiomePlugin::load(&fs, "./my-plugin.grit", Path::new("/"), Path::new("/")) + .expect("Couldn't load plugin"); + assert_eq!(plugin.analyzer_plugins.len(), 1); + } }