Skip to content

Commit

Permalink
Implement single-file plugin loading
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Oct 19, 2024
1 parent 9d876a9 commit 2a2a6f6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/biome_plugin_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn AnalyzerPlugin>],
});
}

let manifest_path = plugin_path.join("biome-manifest.jsonc");
if !fs.path_is_file(&manifest_path) {
return Err(PluginDiagnostic::cant_resolve(
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2a2a6f6

Please sign in to comment.