diff --git a/Cargo.lock b/Cargo.lock index 2f4c7c67f1..6a290a1faa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13330,6 +13330,7 @@ dependencies = [ "fs", "futures 0.3.31", "gpui", + "indoc", "parking_lot", "paths", "schemars", diff --git a/crates/snippet_provider/Cargo.toml b/crates/snippet_provider/Cargo.toml index f523d052e0..3e47c96c66 100644 --- a/crates/snippet_provider/Cargo.toml +++ b/crates/snippet_provider/Cargo.toml @@ -23,3 +23,8 @@ snippet.workspace = true util.workspace = true schemars.workspace = true workspace-hack.workspace = true + +[dev-dependencies] +fs = { workspace = true, features = ["test-support"] } +gpui = { workspace = true, features = ["test-support"] } +indoc.workspace = true diff --git a/crates/snippet_provider/src/lib.rs b/crates/snippet_provider/src/lib.rs index 3058b4ac70..82bae322e4 100644 --- a/crates/snippet_provider/src/lib.rs +++ b/crates/snippet_provider/src/lib.rs @@ -222,15 +222,15 @@ impl SnippetProvider { .lookup_snippets::(language, cx), ); } + + let Some(registry) = SnippetRegistry::try_global(cx) else { + return user_snippets; + }; + + let registry_snippets = registry.get_snippets(language); + user_snippets.extend(registry_snippets); } - let Some(registry) = SnippetRegistry::try_global(cx) else { - return user_snippets; - }; - - let registry_snippets = registry.get_snippets(language); - user_snippets.extend(registry_snippets); - user_snippets } @@ -244,3 +244,38 @@ impl SnippetProvider { requested_snippets } } + +#[cfg(test)] +mod tests { + use super::*; + use fs::FakeFs; + use gpui; + use gpui::TestAppContext; + use indoc::indoc; + + #[gpui::test] + fn test_lookup_snippets_dup_registry_snippets(cx: &mut TestAppContext) { + let fs = FakeFs::new(cx.background_executor.clone()); + cx.update(|cx| { + SnippetRegistry::init_global(cx); + SnippetRegistry::global(cx) + .register_snippets( + "ruby".as_ref(), + indoc! {r#" + { + "Log to console": { + "prefix": "log", + "body": ["console.info(\"Hello, ${1:World}!\")", "$0"], + "description": "Logs to console" + } + } + "#}, + ) + .unwrap(); + let provider = SnippetProvider::new(fs.clone(), Default::default(), cx); + cx.update_entity(&provider, |provider, cx| { + assert_eq!(1, provider.snippets_for(Some("ruby".to_owned()), cx).len()); + }); + }); + } +}