@@ -11,6 +11,7 @@ export class TsPlugin {
11
11
12
12
private constructor ( context : ExtensionContext ) {
13
13
this . enabled = this . getEnabledState ( ) ;
14
+ this . askToEnable ( this . enabled ) ;
14
15
this . toggleTsPlugin ( this . enabled ) ;
15
16
16
17
context . subscriptions . push (
@@ -59,15 +60,41 @@ export class TsPlugin {
59
60
}
60
61
61
62
private async showReload ( enabled : boolean ) {
62
- // Restarting the TSServer via a commend isn't enough, the whole VS Code window needs to reload
63
- const reload = await window . showInformationMessage (
64
- ` TypeScript Svelte Plugin ${
65
- enabled ? 'enabled' : 'disabled'
66
- } , please reload VS Code to restart the TS Server.`,
67
- 'Reload Window'
68
- ) ;
63
+ // Restarting the TSServer via a command isn't enough, the whole VS Code window needs to reload
64
+ let message = `TypeScript Svelte Plugin ${ enabled ? 'enabled' : 'disabled' } .` ;
65
+ if ( enabled ) {
66
+ message +=
67
+ ' Note that changes of Svelte files are only noticed by TS/JS files after they are saved to disk.' ;
68
+ }
69
+ message += ' Please reload VS Code to restart the TS Server.' ;
70
+
71
+ const reload = await window . showInformationMessage ( message , 'Reload Window' ) ;
69
72
if ( reload ) {
70
73
commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
71
74
}
72
75
}
76
+
77
+ private async askToEnable ( enabled : boolean ) {
78
+ const shouldAsk = workspace
79
+ . getConfiguration ( 'svelte' )
80
+ . get < boolean > ( 'ask-to-enable-ts-plugin' ) ;
81
+ if ( enabled || ! shouldAsk ) {
82
+ return ;
83
+ }
84
+
85
+ const answers = [ 'Ask again later' , "Don't show this message again" , 'Enable Plugin' ] ;
86
+ const response = await window . showInformationMessage (
87
+ 'The Svelte for VS Code extension now contains a TypeScript plugin. ' +
88
+ 'Enabling it will provide intellisense for Svelte files from TS/JS files. ' +
89
+ 'Would you like to enable it? ' +
90
+ 'You can always enable/disable it later on through the extension settings.' ,
91
+ ...answers
92
+ ) ;
93
+
94
+ if ( response === answers [ 2 ] ) {
95
+ workspace . getConfiguration ( 'svelte' ) . update ( 'enable-ts-plugin' , true , true ) ;
96
+ } else if ( response === answers [ 1 ] ) {
97
+ workspace . getConfiguration ( 'svelte' ) . update ( 'ask-to-enable-ts-plugin' , false , true ) ;
98
+ }
99
+ }
73
100
}
0 commit comments