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:
parent
b3dad0bfcb
commit
9a6f30fd95
9 changed files with 400 additions and 6 deletions
44
crates/snippet_provider/src/format.rs
Normal file
44
crates/snippet_provider/src/format.rs
Normal 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>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue