@@ -168,7 +168,7 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
168168 } ) ;
169169
170170 const cachedResults = await this . getCachedResults ( xmlDocument , token , nextCharacter , enableCommitCharacters , insertArgumentPlaceholders , xmlDocument . offsetAt ( xmlPosition ) , resp ) ;
171- return [ ...includedResults , ...cachedResults , ...( isTag ? this . getWrapperPropertiesElementsCompletionItems ( ) : this . getWrapperPropertiesCompletionItems ( ) ) ] ;
171+ return [ ...includedResults , ...cachedResults , ...( isTag ? this . getWrapperPropertiesElementsCompletionItems ( xmlDocument , xmlPosition ) : this . getWrapperPropertiesCompletionItems ( xmlDocument , xmlPosition ) ) ] ;
172172 }
173173
174174 private getAttributeCompletionsForAttribute ( elementTag : string , document : TextDocument , position : Position ) : vs . CompletionItem [ ] {
@@ -178,79 +178,88 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
178178 . filter ( ( k ) => handlers [ k ] . isElement && elementTag === k )
179179 . forEach ( ( k ) => {
180180 handlers [ k ] . elementAttributes . forEach ( ( a ) => {
181- items . push ( this . createCompletionItem ( a , vs . CompletionItemKind . Variable ) ) ;
181+ items . push ( this . createCompletionItem ( document , position , a . name , vs . CompletionItemKind . Variable , false , '="' + a . snippet + '"' ) ) ;
182182 } ) ;
183183 } ) ;
184184 return items ;
185185 }
186186
187- private getWrapperPropertiesCompletionItems ( ) : vs . CompletionItem [ ] {
187+ private getWrapperPropertiesCompletionItems ( document : TextDocument , position : Position ) : vs . CompletionItem [ ] {
188188 const handlers = this . propertyHandlerProvider . getAll ( ) ;
189189 const items = Object . keys ( handlers )
190190 . filter ( ( k ) => ! handlers [ k ] . isElement )
191191 . map ( ( k ) => {
192- return this . createCompletionItem ( k , vs . CompletionItemKind . Variable ) ;
192+ return this . createCompletionItem ( document , position , k , vs . CompletionItemKind . Variable , false , handlers [ k ] . valueSnippet ) ;
193193 } ) ;
194194 return items ;
195195 }
196196
197- private getWrapperPropertiesElementsCompletionItems ( ) : vs . CompletionItem [ ] {
197+ private getWrapperPropertiesElementsCompletionItems ( document : TextDocument , position : Position ) : vs . CompletionItem [ ] {
198198 const handlers = this . propertyHandlerProvider . getAll ( ) ;
199199 const items = Object . keys ( handlers )
200200 . filter ( ( k ) => handlers [ k ] . isElement )
201201 . map ( ( k ) => {
202- return this . createCompletionItem ( k , vs . CompletionItemKind . Variable , true ) ;
202+ return this . createCompletionItem ( document , position , k , vs . CompletionItemKind . Variable , true , handlers [ k ] . valueSnippet ) ;
203203 } ) ;
204204 return items ;
205205 }
206206
207207 private getTopLevelElementAttributesCompletions ( document : TextDocument , position : Position ) : vs . CompletionItem [ ] {
208208 return [
209- this . createCompletionItem ( 'xmlns' , vs . CompletionItemKind . Variable ) ,
210- this . createCompletionItem ( 'controller' , vs . CompletionItemKind . Variable ) ,
211- this . createCompletionItem ( 'routeAware' , vs . CompletionItemKind . Variable ) ,
209+ this . createCompletionItem ( document , position , 'xmlns' , vs . CompletionItemKind . Variable ) ,
210+ this . createCompletionItem ( document , position , 'controller' , vs . CompletionItemKind . Variable ) ,
211+ this . createCompletionItem ( document , position , 'routeAware' , vs . CompletionItemKind . Variable ) ,
212212 ] ;
213213 }
214214
215215 private getSecondLevelElementCompletions ( document : TextDocument , position : Position ) : vs . CompletionItem [ ] {
216216 return [
217- this . createCompletionItem ( 'provider' , vs . CompletionItemKind . Class ) ,
218- this . createCompletionItem ( 'with' , vs . CompletionItemKind . Class ) ,
219- this . createCompletionItem ( 'var' , vs . CompletionItemKind . Class ) ,
220- this . createCompletionItem ( 'param' , vs . CompletionItemKind . Class ) ,
217+ this . createCompletionItem ( document , position , 'provider' , vs . CompletionItemKind . Class , true , ' type="$0" name="$1">$2' ) ,
218+ this . createCompletionItem ( document , position , 'with' , vs . CompletionItemKind . Class , true , ' mixin="$0">$1' ) ,
219+ this . createCompletionItem ( document , position , 'var' , vs . CompletionItemKind . Class , true , ' name="$0" value="$1">$2' ) ,
220+ this . createCompletionItem ( document , position , 'param' , vs . CompletionItemKind . Class , true , ' type="$0" name="$1">$2' ) ,
221221 ] ;
222222 }
223223
224224 private getSecondLevelElementAttributesCompletions ( elementTag : string , document : TextDocument , position : Position ) : vs . CompletionItem [ ] {
225225 const elements : { [ name : string ] : vs . CompletionItem [ ] } = {
226226 'provider' : [
227- this . createCompletionItem ( 'type' , vs . CompletionItemKind . Variable ) ,
228- this . createCompletionItem ( 'name' , vs . CompletionItemKind . Variable ) ,
227+ this . createCompletionItem ( document , position , 'type' , vs . CompletionItemKind . Variable ) ,
228+ this . createCompletionItem ( document , position , 'name' , vs . CompletionItemKind . Variable ) ,
229229 ] ,
230230 'with' : [
231- this . createCompletionItem ( 'mixin' , vs . CompletionItemKind . Variable ) ,
231+ this . createCompletionItem ( document , position , 'mixin' , vs . CompletionItemKind . Variable ) ,
232232 ] ,
233233 'var' : [
234- this . createCompletionItem ( 'type' , vs . CompletionItemKind . Variable ) ,
235- this . createCompletionItem ( 'name' , vs . CompletionItemKind . Variable ) ,
236- this . createCompletionItem ( 'value' , vs . CompletionItemKind . Variable ) ,
234+ this . createCompletionItem ( document , position , 'type' , vs . CompletionItemKind . Variable ) ,
235+ this . createCompletionItem ( document , position , 'name' , vs . CompletionItemKind . Variable ) ,
236+ this . createCompletionItem ( document , position , 'value' , vs . CompletionItemKind . Variable ) ,
237237 ] ,
238238 'param' : [
239- this . createCompletionItem ( 'type' , vs . CompletionItemKind . Variable ) ,
240- this . createCompletionItem ( 'name' , vs . CompletionItemKind . Variable ) ,
239+ this . createCompletionItem ( document , position , 'type' , vs . CompletionItemKind . Variable ) ,
240+ this . createCompletionItem ( document , position , 'name' , vs . CompletionItemKind . Variable ) ,
241241 ] ,
242242 } ;
243243
244244 return elements [ elementTag ] ;
245245 }
246246
247- private createCompletionItem ( label : string , kind : vs . CompletionItemKind , isTag = false ) : vs . CompletionItem {
247+ private createCompletionItem ( document : TextDocument , position : Position , label : string , kind : vs . CompletionItemKind , isTag = false , snippet ?: string ) : vs . CompletionItem {
248248 let insertText = '' ;
249- if ( kind === vs . CompletionItemKind . Variable && ! isTag ) {
249+ const nextChar = document . getText ( new Range ( position , new Position ( position . line , position . character + 1 ) ) ) ;
250+ if ( snippet ) {
251+ if ( kind === vs . CompletionItemKind . Variable && ! isTag ) {
252+ insertText = label + '="' + snippet + '"' ;
253+ }
254+ else {
255+ insertText = label + ' ' + snippet + ( nextChar === '>' ? '' : '>' ) ;
256+ }
257+ }
258+ else if ( kind === vs . CompletionItemKind . Variable && ! isTag ) {
250259 insertText = label + '="$0"' ;
251260 }
252261 else {
253- insertText = label + '> $0';
262+ insertText = label + ( nextChar === '>' ? '' : '>' ) + ' $0';
254263 }
255264
256265 const item = new vs . CompletionItem ( label , kind ) ;
0 commit comments