@@ -4,10 +4,10 @@ import {
44 CompletionList ,
55 CompletionItemKind ,
66 CompletionItem ,
7+ InsertTextFormat ,
78} from 'vscode-languageserver' ;
89import { SvelteTag , documentation , getLatestOpeningTag } from './SvelteTags' ;
910import { isInTag } from '../../../lib/documents' ;
10-
1111/**
1212 * Get completions for special svelte tags within moustache tags.
1313 */
@@ -54,9 +54,18 @@ function getCompletionsWithRegardToTriggerCharacter(
5454
5555 if ( triggerCharacter === '#' ) {
5656 return createCompletionItems ( [
57- { tag : 'if' , label : 'if' } ,
58- { tag : 'each' , label : 'each' } ,
59- { tag : 'await' , label : 'await' } ,
57+ { tag : 'if' , label : 'if' , insertText : 'if $1}\n\t$2\n{/if' } ,
58+ { tag : 'each' , label : 'each' , insertText : 'each $1 as $2}\n\t$3\n{/each' } ,
59+ {
60+ tag : 'await' ,
61+ label : 'await :then' ,
62+ insertText : 'await $1}\n\t$2\n{:then $3} \n\t$4\n{/await' ,
63+ } ,
64+ {
65+ tag : 'await' ,
66+ label : 'await then' ,
67+ insertText : 'await $1 then $2}\n\t$3\n{/await' ,
68+ } ,
6069 ] ) ;
6170 }
6271
@@ -133,12 +142,16 @@ function showCompletionWithRegardsToOpenedTags(
133142/**
134143 * Create the completion items for given labels and tags.
135144 */
136- function createCompletionItems ( items : { label : string ; tag : SvelteTag } [ ] ) : CompletionList {
145+ function createCompletionItems (
146+ items : { label : string ; tag : SvelteTag ; insertText ?: string } [ ] ,
147+ ) : CompletionList {
137148 return CompletionList . create (
138149 // add sortText/preselect so it is ranked higher than other completions and selected first
139150 items . map (
140151 ( item ) =>
141152 < CompletionItem > {
153+ insertTextFormat : InsertTextFormat . Snippet ,
154+ insertText : item . insertText ,
142155 label : item . label ,
143156 sortText : '-1' ,
144157 kind : CompletionItemKind . Keyword ,
0 commit comments