@@ -6,42 +6,48 @@ const path = require('path');
66
77const snippets = require ( './snippets' ) ;
88
9- const EXTENSION_IDENTIFIER = 'javascript-snippets' ;
10- const SEMICOLONS = 'semicolons' ;
11- const SNIPPETS_PATH = path . resolve ( __dirname , '../snippets/snippets.json' ) ;
12-
13- exports . activate = function activate ( context ) {
14- let configuration = vscode . workspace . getConfiguration ( EXTENSION_IDENTIFIER ) ;
15- const withSemicolons = configuration . get ( SEMICOLONS ) ;
16- generateSnippets ( SNIPPETS_PATH , snippets ( withSemicolons ) ) ;
17-
18- const subscription = vscode . workspace . onDidChangeConfiguration ( function ( ) {
19- configuration = listener ( configuration , EXTENSION_IDENTIFIER , SEMICOLONS ) ;
9+ exports . activate = context => {
10+ const extensionId = 'javascript-snippets' ;
11+ const snippetsPath = path . resolve ( __dirname , '../snippets/snippets.json' ) ;
12+ const property = 'semicolons' ;
13+ let configuration = vscode . workspace . getConfiguration ( extensionId ) ;
14+ const hasSemicolons = configuration . get ( property ) ;
15+
16+ generateSnippets ( snippetsPath , snippets ( hasSemicolons ) ) ;
17+
18+ const subscription = vscode . workspace . onDidChangeConfiguration ( ( ) => {
19+ configuration = listener (
20+ configuration ,
21+ extensionId ,
22+ snippetsPath ,
23+ property ,
24+ ) ;
2025 } ) ;
26+
2127 context . subscriptions . push ( subscription ) ;
2228} ;
2329
24- /** Listens for change in user's settings for value of `semicolons` property. */
25- function listener ( previousConfiguration , identifier , semicolons ) {
30+ /** Listens for change in `semicolons` property of user's settings . */
31+ function listener ( previousConfiguration , identifier , path , property ) {
2632 const configuration = vscode . workspace . getConfiguration ( identifier ) ;
27- const withSemicolons = configuration . get ( semicolons ) ;
33+ const hasSemicolons = configuration . get ( property ) ;
2834
29- if ( withSemicolons !== previousConfiguration . get ( semicolons ) ) {
30- generateSnippets ( SNIPPETS_PATH , snippets ( withSemicolons ) ) ;
35+ if ( hasSemicolons !== previousConfiguration . get ( property ) ) {
36+ generateSnippets ( path , snippets ( hasSemicolons ) ) ;
3137
32- // FIXME: Prompt user for reloading window, since editor does not seem to pickup overwritten content.
38+ // TODO: Ask user to reload window, in order for change to take effect
3339 }
3440
3541 return configuration ;
3642}
3743
3844/** Generates set of JavaScript snippets in JSON format and writes them to file. */
39- function generateSnippets ( path , snippets ) {
40- let stream = fs . createWriteStream ( path ) ;
45+ function generateSnippets ( path , data ) {
46+ const stream = fs . createWriteStream ( path ) ;
4147
42- stream . on ( 'error' , function ( error ) {
48+ stream . on ( 'error' , error => {
4349 // TODO: Throw error
4450 } ) ;
45- stream . write ( JSON . stringify ( snippets ) ) ;
51+ stream . write ( JSON . stringify ( data ) ) ;
4652 stream . end ( ) ;
4753}
0 commit comments