メインコンテンツへスキップ
バージョン: 0.21

エディター設定

貢献

別のエディターを使用していますか?お使いのエディターの手順を追加してください。

コンポーネントを作成するためのテンプレートを追加する

JetBrains IDE

  1. File | Settings | Editor | Live Templates に移動します。
  2. Rustを選択し、+アイコンをクリックして新しいLive Templateを追加します。
  3. 好きな名前と説明を付けます。
  4. 以下のスニペットをTemplate Textセクションに貼り付けます。
  5. 右下の適用範囲を変更し、Rust > Item > Moduleを選択します

関数コンポーネントの場合は、次のテンプレートを使用します。

  • (オプション)Edit Variableをクリックして、tagに "div" のような適切なデフォルト値をダブルクォートで指定します。
#[derive(PartialEq, Properties)]
pub struct $Name$Props {
}

#[function_component]
pub fn $Name$(props: &$Name$Props) -> Html {
html! {
<$tag$>$END$</$tag$>
}
}

構造体コンポーネントの場合は、次のより複雑なテンプレートを使用できます。

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$
}
}
}

VS Code

  1. File > Preferences > User Snippets に移動します。
  2. 言語としてRustを選択します。
  3. スニペットJSONファイルに次のスニペットを追加します
{
"New Yew function component": {
"prefix": "yewfc",
"body": [
"#[derive(PartialEq, Properties)]",
"pub struct ${1:ComponentName}Props {}",
"",
"#[function_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! マクロのサポート

JetBrains IDE

JetBrainsは2021年4月にproc-macro展開の実験的サポートを追加しました。この機能を使用するには、事前に有効にする必要があります。こちらのブログ記事をご覧ください。

これにより、HTMLの自動入力とフォーマットは有効になりませんが、マクロ内のコンポーネント名と属性の変数解決は有効になります。名前の変更、宣言への移動、使用箇所の検索などのユーティリティはマクロ内で機能します。

VS Code

Rust-Yew 拡張機能

これは開発中の、そしてコミュニティが維持しているプロジェクトです!詳細については、拡張機能のリポジトリに直接関連するバグレポート/問題/質問を送信してください

Rust-Yew拡張機能は、VSC Marketplaceで入手でき、構文の強調表示、名前の変更、ホバーなどが提供されます。

Emmetのサポートはすぐに使えるはずです。そうでない場合は、settings.jsonファイルを編集してください。

"emmet.includeLanguages": {
"rust": "html",
}

Neovim

Lazyvim

以下の設定はLazyVimの設定とlazy.vimプラグインで動作します。lua/plugins/nvim-lspconfig.luaにファイルを作成(またはlspconfigを更新)します。

return {
{
"neovim/nvim-lspconfig",
init_options = {
userLanguages = {
eelixir = "html-eex",
eruby = "erb",
rust = "html",
},
},
},
}