Skip to content

Commit

Permalink
snippets: Fix snippets not updating while containing comments (#23755)
Browse files Browse the repository at this point in the history
Closes #23699

Release Notes:

- Fixed issue where snippets would not update when a snippets file
contained comments.
  • Loading branch information
loczek authored Jan 28, 2025
1 parent bb59e7f commit b99159c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/snippet_provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions crates/snippet_provider/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use schemars::{
JsonSchema,
};
use serde::Deserialize;
use serde_json::Value;
use serde_json_lenient::Value;

#[derive(Deserialize)]
pub struct VSSnippetsFile {
Expand All @@ -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()
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/snippet_provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion crates/snippet_provider/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit b99159c

Please sign in to comment.