@@ -8,19 +8,35 @@ const TAG_REGEX = /\%(\w+)\%/gm;
8
8
export function activate ( context : vscode . ExtensionContext ) {
9
9
const disposable = vscode . workspace . onDidChangeConfiguration ( e => onConfigurationChanged ( context , e ) ) ;
10
10
context . subscriptions . push ( disposable ) ;
11
+
12
+ const currentVersion = context . extension . packageJSON . version as string ;
13
+ const lastVersion = context . globalState . get ( 'version' ) as string ?? '0.0.0' ;
14
+ if ( currentVersion === lastVersion ) return ;
15
+ updateSnippets ( context ) . then ( ( ) =>
16
+ context . globalState . update ( 'version' , currentVersion )
17
+ ) ;
11
18
}
12
19
13
20
function onConfigurationChanged ( context : vscode . ExtensionContext , e : vscode . ConfigurationChangeEvent ) {
14
- if ( ! e . affectsConfiguration ( EXT_ID ) ) { return ; }
21
+ if ( e . affectsConfiguration ( EXT_ID ) ) updateSnippets ( context ) ;
22
+ }
23
+
24
+ async function updateSnippets ( context : vscode . ExtensionContext ) : Promise < void > {
15
25
const conf = vscode . workspace . getConfiguration ( EXT_ID ) ;
16
26
17
- createSnippets ( context , parseOptions ( conf ) )
18
- . then ( content => saveSnippets ( context , content ) )
19
- . then ( ( ) => {
20
- vscode . window . showInformationMessage ( 'Restart VSCode to apply the snippets' , 'Restart' )
21
- . then ( result => { if ( result === 'Restart' ) { vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ; } } ) ;
22
- } )
23
- . catch ( showError ) ;
27
+ try {
28
+ const content = await createSnippets ( context , parseOptions ( conf ) ) ;
29
+ await saveSnippets ( context , content ) ;
30
+ vscode . window . showInformationMessage ( 'Restart VSCode to apply the snippets' , 'Restart' )
31
+ . then ( result => {
32
+ if ( result === 'Restart' ) {
33
+ vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
34
+ }
35
+ } ) ;
36
+ } catch ( e ) {
37
+ showError ( e ) ;
38
+ Promise . reject ( e ) ;
39
+ }
24
40
}
25
41
26
42
async function createSnippets ( context : vscode . ExtensionContext , options : Options ) {
0 commit comments