Skip to content

Commit ed8358d

Browse files
authored
(feat) ask to enable ts plugin (#1160)
There was no negative feedback so far, so let's make discoverability better by asking if it should be enabled. #580
1 parent 79bbde7 commit ed8358d

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

packages/svelte-vscode/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
"title": "Enable TypeScript Svelte plugin",
6767
"description": "Enables a TypeScript plugin which provides intellisense for Svelte files inside TS/JS files."
6868
},
69+
"svelte.ask-to-enable-ts-plugin": {
70+
"type": "boolean",
71+
"default": true,
72+
"title": "Ask to enable TypeScript Svelte plugin",
73+
"description": "Ask on startup to enable the TypeScript plugin."
74+
},
6975
"svelte.language-server.runtime": {
7076
"scope": "application",
7177
"type": "string",

packages/svelte-vscode/src/tsplugin.ts

+34-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class TsPlugin {
1111

1212
private constructor(context: ExtensionContext) {
1313
this.enabled = this.getEnabledState();
14+
this.askToEnable(this.enabled);
1415
this.toggleTsPlugin(this.enabled);
1516

1617
context.subscriptions.push(
@@ -59,15 +60,41 @@ export class TsPlugin {
5960
}
6061

6162
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');
6972
if (reload) {
7073
commands.executeCommand('workbench.action.reloadWindow');
7174
}
7275
}
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+
}
73100
}

0 commit comments

Comments
 (0)