Skip to content

Commit f98a6f9

Browse files
committed
Added: Version detection to properly upgrade to newest changes
1 parent 27b6d82 commit f98a6f9

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/extension.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ const TAG_REGEX = /\%(\w+)\%/gm;
88
export function activate(context: vscode.ExtensionContext) {
99
const disposable = vscode.workspace.onDidChangeConfiguration(e => onConfigurationChanged(context, e));
1010
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+
);
1118
}
1219

1320
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> {
1525
const conf = vscode.workspace.getConfiguration(EXT_ID);
1626

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+
}
2440
}
2541

2642
async function createSnippets(context: vscode.ExtensionContext, options: Options) {

0 commit comments

Comments
 (0)