Fix snippets from extensions being listed twice (#28940)

lookup_snippets() merges global snippets and extension snippets, but
global_snippets::lookup_snippets() also returns extension snippets, make
them double

Closes #28661 

Release Notes:

- Fixed a bug where extension provided snippets were being displayed in
duplicate.
This commit is contained in:
redforks 2025-04-17 22:43:49 +08:00 committed by GitHub
parent 022a110f8e
commit bdd0cbb717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 7 deletions

1
Cargo.lock generated
View file

@ -13330,6 +13330,7 @@ dependencies = [
"fs",
"futures 0.3.31",
"gpui",
"indoc",
"parking_lot",
"paths",
"schemars",

View file

@ -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

View file

@ -222,15 +222,15 @@ impl SnippetProvider {
.lookup_snippets::<false>(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());
});
});
}
}