@@ -13,7 +13,11 @@ exports.activate = context => {
1313 let configuration = vscode . workspace . getConfiguration ( extensionId ) ;
1414 const hasSemicolons = configuration . get ( property ) ;
1515
16- generateSnippets ( snippetsPath , snippets ( hasSemicolons ) ) ;
16+ try {
17+ generateSnippets ( snippetsPath , snippets ( hasSemicolons ) ) ;
18+ } catch ( error ) {
19+ // TODO: Handle error
20+ }
1721
1822 const subscription = vscode . workspace . onDidChangeConfiguration ( ( ) => {
1923 configuration = listener (
@@ -33,21 +37,19 @@ function listener(previousConfiguration, identifier, path, property) {
3337 const hasSemicolons = configuration . get ( property ) ;
3438
3539 if ( hasSemicolons !== previousConfiguration . get ( property ) ) {
36- generateSnippets ( path , snippets ( hasSemicolons ) ) ;
40+ try {
41+ generateSnippets ( path , snippets ( hasSemicolons ) ) ;
3742
38- // TODO: Ask user to reload window, in order for change to take effect
43+ // TODO: Ask user to reload window, in order for change to take effect
44+ } catch ( error ) {
45+ // TODO: Handle error
46+ }
3947 }
4048
4149 return configuration ;
4250}
4351
44- /** Generates set of JavaScript snippets in JSON format and writes them to file. */
45- function generateSnippets ( path , data ) {
46- const stream = fs . createWriteStream ( path ) ;
47-
48- stream . on ( 'error' , error => {
49- // TODO: Throw error
50- } ) ;
51- stream . write ( JSON . stringify ( data ) ) ;
52- stream . end ( ) ;
52+ /** Synchronously generates code snippets in JSON format and writes them to file. */
53+ function generateSnippets ( file , snippets ) {
54+ fs . writeFileSync ( file , JSON . stringify ( snippets ) ) ;
5355}
0 commit comments