website/versioned_docs/version-0.22/getting-started/editor-setup.mdx
:::important contribute Using a different editor? Feel free to add instructions for your editor of choice. :::
For function components, use the following template.
tag a reasonable default value like "div", with double quotes.#[derive(PartialEq, Properties)]
pub struct $Name$Props {
}
#[component]
pub fn $Name$(props: &$Name$Props) -> Html {
html! {
<$tag$>$END$</$tag$>
}
}
For struct components, you can use the following more complicated template.
struct $NAME$;
enum $NAME$Msg {
}
impl Component for $NAME$ {
type Message = $NAME$Msg;
type Properties = ();
fn create(ctx: &Context<Self>) -> Self {
Self
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
$HTML$
}
}
}
{
"New Yew function component": {
"prefix": "yewfc",
"body": [
"#[derive(PartialEq, Properties)]",
"pub struct ${1:ComponentName}Props {}",
"",
"#[component]",
"pub fn $1(props: &${1}Props) -> Html {",
" let ${1}Props {} = props;",
" html! {",
" <${2:div}>$0</${2}>",
" }",
"}"
],
"description": "Create a minimal Yew function component"
},
"New Yew struct component": {
"prefix": "yewsc",
"body": [
"pub struct ${1:ComponentName};",
"",
"pub enum ${1}Msg {",
"}",
"",
"impl Component for ${1} {",
" type Message = ${1}Msg;",
" type Properties = ();",
"",
" fn create(ctx: &Context<Self>) -> Self {",
" Self",
" }",
"",
" fn view(&self, ctx: &Context<Self>) -> Html {",
" html! {",
" $0",
" }",
" }",
"}"
],
"description": "Create a new Yew component with a message enum"
}
}
html! MacroContribution Welcome!
This is a work in progress, and community maintained project! Please see details and direct related bug reports / issues / questions over to the extension's repository
Rust-Yew extension is available on VSC Marketplace, providing syntax highlight, renames, hover, and more.
Emmet support should work out of the box, if not please fall back to editing the settings.json file:
"emmet.includeLanguages": {
"rust": "html",
}
Below configuration works with LazyVim configuration and lazy.vim plugin, create a file in
lua/plugins/nvim-lspconfig.lua(or update yourlspconfig) with:
return {
{
"neovim/nvim-lspconfig",
init_options = {
userLanguages = {
eelixir = "html-eex",
eruby = "erb",
rust = "html",
},
},
},
}