Repository: zed-industries/zed
File: crates/snippet_provider/src/lib.rs (Rust)

Code before:
    extension_snippet::init(cx);
}

/// Language name, or `None` if the snippet file is global.
type SnippetKind = Option<String>;
fn file_stem_to_key(stem: &str) -> SnippetKind {
    if stem == "snippets" {
        None
    } else {
        Some(stem.to_owned())
    }
}

fn file_to_snippets(file_contents: VsSnippetsFile, source: &Path) -> Vec<Arc<Snippet>> {
    let mut snippets = vec![];
    for (name, snippet) in file_contents.snippets {
        let snippet_name = name.clone();
        let prefixes = snippet
            .prefix
            .map_or_else(move || vec![snippet_name], |prefixes| prefixes.into());
        let description = snippet
            .description
            .map(|description| description.to_string());
        let body = snippet.body.to_string();
        if snippet::Snippet::parse(&body)
            .with_context(|| format!("invalid snippet in {} ({})", source.display(), name))
            .log_err()
            .is_none()
        {
            continue;
        };
        snippets.push(Arc::new(Snippet {
            body,
            prefix: prefixes,
            description,
            name,
        }));
    }
    snippets
}
// Snippet with all of the metadata
#[derive(Debug)]
pub struct Snippet {
    pub prefix: Vec<String>,
    pub body: String,
    pub description: Option<String>,
    pub name: String,
}

async fn process_updates(
    this: WeakEntity<SnippetProvider>,

Review comment (suggestion):
```suggestion
            .with_context(|| format!("invalid snippet '{name}' in {source:?}"))
```

Can we 

* reword the error a bit to make it more obvious where the snippet name is (not sure if single quotes around are good, just proposing)?

* do a 
```rs
if let Err(e) = snippet::Snippet::parse(&body) {
    log::error!("Invalid snippet '{name}' in {source:?}: {e:#}
}
```
-like change instead of `log_err()`?

The latter shows quite a backtrace in the settings, which seems totally unneeded.

Code after:
}

/// Language name, or `None` if the snippet file is global.
type SnippetKind = Option<String>;
fn file_stem_to_key(stem: &str) -> SnippetKind {
    if stem == "snippets" {
        None
    } else {
        Some(stem.to_owned())
    }
}

fn file_to_snippets(file_contents: VsSnippetsFile, source: &Path) -> Vec<Arc<Snippet>> {
    let mut snippets = vec![];
    for (name, snippet) in file_contents.snippets {
        let snippet_name = name.clone();
        let prefixes = snippet
            .prefix
            .map_or_else(move || vec![snippet_name], |prefixes| prefixes.into());
        let description = snippet
            .description
            .map(|description| description.to_string());
        let body = snippet.body.to_string();
        if let Err(e) = snippet::Snippet::parse(&body) {
            log::error!("Invalid snippet name '{name}' in {source:?}: {e:#}");
            continue;
        }
        snippets.push(Arc::new(Snippet {
            body,
            prefix: prefixes,
            description,
            name,
        }));
    }
    snippets
}
// Snippet with all of the metadata
#[derive(Debug)]
pub struct Snippet {
    pub prefix: Vec<String>,
    pub body: String,
    pub description: Option<String>,
    pub name: String,
}

async fn process_updates(
    this: WeakEntity<SnippetProvider>,
    entries: Vec<PathBuf>,
    mut cx: AsyncApp,
) -> Result<()> {
    let fs = this.read_with(&cx, |this, _| this.fs.clone())?;