Snippets: Move snippets into the core of editor (#13937)

Release Notes:

- Move snippet support into core editor experience, marking the official
extension as deprecated. Snippets now show up in any buffer (including
plain text buffers).
This commit is contained in:
Piotr Osiewicz 2024-07-09 14:02:36 +02:00 committed by GitHub
parent b3dad0bfcb
commit 9a6f30fd95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 400 additions and 6 deletions

View file

@ -0,0 +1,44 @@
use collections::HashMap;
use serde::Deserialize;
#[derive(Deserialize)]
pub(crate) struct VSSnippetsFile {
#[serde(flatten)]
pub(crate) snippets: HashMap<String, VSCodeSnippet>,
}
#[derive(Deserialize)]
#[serde(untagged)]
pub(crate) enum ListOrDirect {
Single(String),
List(Vec<String>),
}
impl From<ListOrDirect> for Vec<String> {
fn from(list: ListOrDirect) -> Self {
match list {
ListOrDirect::Single(entry) => vec![entry],
ListOrDirect::List(entries) => entries,
}
}
}
impl std::fmt::Display for ListOrDirect {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Single(v) => v.to_owned(),
Self::List(v) => v.join("\n"),
}
)
}
}
#[derive(Deserialize)]
pub(crate) struct VSCodeSnippet {
pub(crate) prefix: Option<ListOrDirect>,
pub(crate) body: ListOrDirect,
pub(crate) description: Option<ListOrDirect>,
}