@@ -37,10 +37,7 @@ export async function migrateSnippets(
3737
3838 const spokenFormsInverted : SpokenForms = {
3939 insertion : swapKeyValue ( spokenForms . insertion ) ,
40- insertionWithPhrase : swapKeyValue (
41- spokenForms . insertionWithPhrase ,
42- ( name ) => name . split ( "." ) [ 0 ] ,
43- ) ,
40+ insertionWithPhrase : swapKeyValue ( spokenForms . insertionWithPhrase ) ,
4441 wrapper : swapKeyValue ( spokenForms . wrapper ) ,
4542 } ;
4643
@@ -100,9 +97,17 @@ export function migrateLegacySnippet(
10097
10198 for ( const snippetName of snippetNames ) {
10299 const snippet = legacySnippetFile [ snippetName ] ;
103- const phrase =
104- spokenForms . insertion [ snippetName ] ??
105- spokenForms . insertionWithPhrase [ snippetName ] ;
100+ let phrase = spokenForms . insertion [ snippetName ] ;
101+
102+ if ( ! phrase ) {
103+ const key = Object . keys ( spokenForms . insertionWithPhrase ) . find ( ( key ) =>
104+ key . startsWith ( `${ snippetName } .` ) ,
105+ ) ;
106+ if ( key ) {
107+ phrase = spokenForms . insertionWithPhrase [ key ] ;
108+ }
109+ }
110+
106111 const phrases = phrase ? [ phrase ] : undefined ;
107112
108113 if ( useHeader ) {
@@ -116,6 +121,7 @@ export function migrateLegacySnippet(
116121 snippet . variables ,
117122 undefined ,
118123 true ,
124+ false ,
119125 ) ,
120126 insertionScopes : snippet . insertionScopeTypes ,
121127 } ;
@@ -141,6 +147,7 @@ export function migrateLegacySnippet(
141147 useHeader ? undefined : snippet . variables ,
142148 def . variables ,
143149 ! useHeader ,
150+ true ,
144151 ) ,
145152 // SKIP: def.scope?.scopeTypes
146153 // SKIP: def.scope?.excludeDescendantScopeTypes
@@ -158,6 +165,7 @@ function parseVariables(
158165 snippetVariables : Record < string , SnippetVariableLegacy > | undefined ,
159166 defVariables : Record < string , SnippetVariableLegacy > | undefined ,
160167 addMissingPhrases : boolean ,
168+ addMissingInsertionFormatters : boolean ,
161169) : SnippetVariable [ ] {
162170 const map : Record < string , SnippetVariable > = { } ;
163171
@@ -197,6 +205,20 @@ function parseVariables(
197205 }
198206 }
199207
208+ if ( addMissingInsertionFormatters ) {
209+ for ( const key in spokenForms . insertionWithPhrase ) {
210+ const [ snipName , variableName ] = key . split ( "." ) ;
211+ if ( snipName === snippetName ) {
212+ if ( ! map [ variableName ] ) {
213+ map [ variableName ] = { name : variableName } ;
214+ }
215+ if ( ! map [ variableName ] . insertionFormatters ) {
216+ map [ variableName ] . insertionFormatters = [ "NOOP" ] ;
217+ }
218+ }
219+ }
220+ }
221+
200222 return Object . values ( map ) ;
201223}
202224
@@ -313,11 +335,8 @@ async function writeCommunityFile(
313335 }
314336}
315337
316- function swapKeyValue (
317- obj : Record < string , string > ,
318- map ?: ( value : string ) => string ,
319- ) : Record < string , string > {
338+ function swapKeyValue ( obj : Record < string , string > ) : Record < string , string > {
320339 return Object . fromEntries (
321- Object . entries ( obj ) . map ( ( [ key , value ] ) => [ map ?. ( value ) ?? value , key ] ) ,
340+ Object . entries ( obj ) . map ( ( [ key , value ] ) => [ value , key ] ) ,
322341 ) ;
323342}
0 commit comments