コードスニペット
IDEが提供するコードスニペットよりも強力な機能を提供。頻繁に入力されるコードセグメントの展開をサポートします。現在のコンテキストからのシンボル、ユーザー入力プロンプト、カスタムエディターによるスニペット編集などの強力な機能が用意されています。
VAスニペット
IDEが提供するコードスニペットよりも強力な機能を搭載したVAスニペットを使用してコードの共通スニペットを挿入
VAスニペットを使用すれば、コードの断片の挿入や、選択したコードを囲んでの追加が可能になります。IDEのコードスニペット機能とは異なり、Visual AssistはVAスニペット要素の変更と同期したままなので、連続的な編集とテストが可能です。また、すべてのMicrosoft IDEで共通のVAスニペットを保存できる点も異なります。
Visual Assistに搭載されているカスタムエディターを使用すれば、VAスニペットを容易に作成、修正、使用できます。
![x](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/vaSnippets.png)
リファクタリング機能用のVAスニペット
特別なVAスニペットを使用してリファクタリングコードのフォーマットを定義
Visual Assistのリファクタリング機能やコード生成コマンドに結びつけられた多数のVAスニペットを編集可能。新しいコードを、お好みのフォーマットに適合させることができます。
指定可能な項目の例 :
- 「フィールドのカプセル化」および「メソッドの抽出」によって生成されたメソッド用のパラメーターレイアウト
- 「ファイルの作成」用のヘッダーファイルおよびソースファイルのデフォルトコンテンツ
- 「使用箇所からの作成」用のメソッドおよびクラスのフォーマット
- 「メソッドのドキュメント生成」用のDoxygen スタイルのコメント
![Define the format of refactored code with special VA Snippets](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/snippetsForRefactoring.png)
「スマート提案」で使うVAスニペット
高度なコンテキスト対応提案の表示を定義
組み込み型やユーザー定義型に値を割り当てるときや、クラス、ループ、スイッチといったコンストラクト作成時に表示する、スピード入力・精度改善提案を定義します。
![Define suggestions to appear in highly context-aware suggestions](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/smartSuggestions.png)
「カスタムテキストで囲む」で使うVAスニペット
共通のコンストラクトやステートメントを選択したコードブロックの周囲に追加
コードの複数行、または一行の一部を選択した際に、予約文字列 $selected$ を含むVAスニペットでコードをラップします。このタイプのVAスニペットは、キーボードまたはマウス操作でアクセスしたメニューから呼び出します。
![Quickly surround selections of code with common constructs and statements](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/surroundWith.png)
![Quickly surround selections of code with common constructs and statements](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/surroundWith2.png)
VAスニペットでは、コピーした内容で選択箇所を囲む場合は、$selected$の代わりに$clipboard$を使用します。
ショートカットを用いたVAスニペット
ショートカットを使用して頻繁に入力される共通した名前やコンストラクトを展開
複数のVAスニペットに同一のショートカットを定義し、コンテキストに合わせて展開する内容を選択できます。
![Expand commonly typed names and constructs using shortcuts](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/snippetsWithShortcuts.png)
VAスニペットは、コード入力時に表示されるリストボックスから便利にアクセスできます。
![Expand commonly typed names and constructs using shortcuts](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/snippetsWithShortcuts2.png)
展開されたVAスニペットはショートカットを置き換えます。
![Expand commonly typed names and constructs using shortcuts](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/snippetsWithShortcuts3.png)
選択箇所からの作成
頻繁に使用されるコードのブロックからコードライブラリを構築
コードの複数行、または一行の一部を選択し、すぐ使用できるVAスニペットを作成できます。拡張先のコンテキストからのメソッドやシンボルの名前に応じて適宜VAスニペットを変更します。長期間使用するVAスニペットは保存し、その他は変更パターンに関する短期間のタスク用にキープできます。
![Build a code library from blocks of frequently used code](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/createFromSelection.png)
![Build a code library from blocks of frequently used code](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/createFromSelection2.png)
![Build a code library from blocks of frequently used code](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/createFromSelection3.png)
環境変数プレースホルダー
ユーザー固有の値で環境変数を展開
複数ユーザーで共通して使用するVAスニペットに、環境変数を追加できます。
例:%USERNAME%
.
![Add environment variables to VA Snippets](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/environmentVar.png)
環境変数の値は、展開時にVAスニペットに表示されます。
![Values from the environment appear in VA Snippets](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/environmentVar2.png)
インプットプレースホルダー
展開前にユーザー入力用プロンプトを表示するVAスニペットを作成
$string$ を埋め込むことで、VAスニペットに値入力用プロントを表示させます。
![Create VA Snippets that prompt for input before expansion](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/prompt.png)
VAスニペットのデフォルト値は、プロンプトに表示されます。
![Default values in the prompt dialog come from the VA Snippet](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/prompt2.png)
VAスニペットを受け入れ、展開します。
![Accept or change defaults before expanding the VA Snippet](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/prompt3.png)
予約文字列
VAスニペットを呼び出すコンテキストから取得したファイル名やシンボル名を展開
VAスニペットを呼び出すときに展開される50以上の予約文字列を利用可能。予約文字列は、日付、時間、ファイル名、クラス名、メソッド名、メソッドパラメーター、GUID等々の展開に利用できます。
![Expand file and symbol names taken from the context in which a VA Snippet is invoked](/Presentation/WholeTomato/Assets/Images/features/codeSnippets/reservedStrings.png)