snippets: Fix snippets not updating while containing comments (#23755)

Closes #23699

Release Notes:

- Fixed issue where snippets would not update when a snippets file
contained comments.
This commit is contained in:
loczek
2025-01-28 10:37:48 +01:00
committed by GitHub
parent bb59e7f217
commit b99159c59b
5 changed files with 8 additions and 6 deletions
Generated
+1 -1
View File
@@ -12077,7 +12077,7 @@ dependencies = [
"paths",
"schemars",
"serde",
"serde_json",
"serde_json_lenient",
"snippet",
"util",
]
+1 -1
View File
@@ -18,7 +18,7 @@ gpui.workspace = true
parking_lot.workspace = true
paths.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_json_lenient.workspace = true
snippet.workspace = true
util.workspace = true
schemars.workspace = true
+2 -2
View File
@@ -5,7 +5,7 @@ use schemars::{
JsonSchema,
};
use serde::Deserialize;
use serde_json::Value;
use serde_json_lenient::Value;
#[derive(Deserialize)]
pub struct VSSnippetsFile {
@@ -20,7 +20,7 @@ impl VSSnippetsFile {
.into_generator()
.into_root_schema_for::<Self>();
serde_json::to_value(schema).unwrap()
serde_json_lenient::to_value(schema).unwrap()
}
}
+2 -1
View File
@@ -98,7 +98,8 @@ async fn process_updates(
let Some(file_contents) = contents else {
return;
};
let Ok(as_json) = serde_json::from_str::<VSSnippetsFile>(&file_contents) else {
let Ok(as_json) = serde_json_lenient::from_str::<VSSnippetsFile>(&file_contents)
else {
return;
};
let snippets = file_to_snippets(as_json);
+2 -1
View File
@@ -37,7 +37,8 @@ impl SnippetRegistry {
}
pub fn register_snippets(&self, file_path: &Path, contents: &str) -> Result<()> {
let snippets_in_file: crate::format::VSSnippetsFile = serde_json::from_str(contents)?;
let snippets_in_file: crate::format::VSSnippetsFile =
serde_json_lenient::from_str(contents)?;
let kind = file_path
.file_stem()
.and_then(|stem| stem.to_str().and_then(file_stem_to_key));