@@ -4,10 +4,10 @@ import {
4
4
CompletionList ,
5
5
CompletionItemKind ,
6
6
CompletionItem ,
7
+ InsertTextFormat ,
7
8
} from 'vscode-languageserver' ;
8
9
import { SvelteTag , documentation , getLatestOpeningTag } from './SvelteTags' ;
9
10
import { isInTag } from '../../../lib/documents' ;
10
-
11
11
/**
12
12
* Get completions for special svelte tags within moustache tags.
13
13
*/
@@ -54,9 +54,18 @@ function getCompletionsWithRegardToTriggerCharacter(
54
54
55
55
if ( triggerCharacter === '#' ) {
56
56
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
+ } ,
60
69
] ) ;
61
70
}
62
71
@@ -133,12 +142,16 @@ function showCompletionWithRegardsToOpenedTags(
133
142
/**
134
143
* Create the completion items for given labels and tags.
135
144
*/
136
- function createCompletionItems ( items : { label : string ; tag : SvelteTag } [ ] ) : CompletionList {
145
+ function createCompletionItems (
146
+ items : { label : string ; tag : SvelteTag ; insertText ?: string } [ ] ,
147
+ ) : CompletionList {
137
148
return CompletionList . create (
138
149
// add sortText/preselect so it is ranked higher than other completions and selected first
139
150
items . map (
140
151
( item ) =>
141
152
< CompletionItem > {
153
+ insertTextFormat : InsertTextFormat . Snippet ,
154
+ insertText : item . insertText ,
142
155
label : item . label ,
143
156
sortText : '-1' ,
144
157
kind : CompletionItemKind . Keyword ,
0 commit comments