Skip to content

Commit

Permalink
(feat) ask to enable ts plugin
Browse files Browse the repository at this point in the history
There was no negative feedback so far, so let's make discoverability better by asking if it should be enabled.
sveltejs#580
  • Loading branch information
Simon Holthausen committed Sep 2, 2021
1 parent 79bbde7 commit 51255fe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/svelte-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"title": "Enable TypeScript Svelte plugin",
"description": "Enables a TypeScript plugin which provides intellisense for Svelte files inside TS/JS files."
},
"svelte.ask-to-enable-ts-plugin": {
"type": "boolean",
"default": true,
"title": "Ask to enable TypeScript Svelte plugin",
"description": "Ask on startup to enable the TypeScript plugin."
},
"svelte.language-server.runtime": {
"scope": "application",
"type": "string",
Expand Down
41 changes: 34 additions & 7 deletions packages/svelte-vscode/src/tsplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class TsPlugin {

private constructor(context: ExtensionContext) {
this.enabled = this.getEnabledState();
this.askToEnable(this.enabled);
this.toggleTsPlugin(this.enabled);

context.subscriptions.push(
Expand Down Expand Up @@ -59,15 +60,41 @@ export class TsPlugin {
}

private async showReload(enabled: boolean) {
// Restarting the TSServer via a commend isn't enough, the whole VS Code window needs to reload
const reload = await window.showInformationMessage(
` TypeScript Svelte Plugin ${
enabled ? 'enabled' : 'disabled'
}, please reload VS Code to restart the TS Server.`,
'Reload Window'
);
// Restarting the TSServer via a command isn't enough, the whole VS Code window needs to reload
let message = `TypeScript Svelte Plugin ${enabled ? 'enabled' : 'disabled'}.`;
if (enabled) {
message +=
' Note that changes of Svelte files are only noticed by TS/JS files after they are saved to disk.';
}
message += ' Please reload VS Code to restart the TS Server.';

const reload = await window.showInformationMessage(message, 'Reload Window');
if (reload) {
commands.executeCommand('workbench.action.reloadWindow');
}
}

private async askToEnable(enabled: boolean) {
const shouldAsk = workspace
.getConfiguration('svelte')
.get<boolean>('ask-to-enable-ts-plugin');
if (enabled || !shouldAsk) {
return;
}

const answers = ['Ask again later', "Don't show this message again", 'Enable Plugin'];
const response = await window.showInformationMessage(
'The Svelte for VS Code extension now contains a TypeScript plugin. ' +
'Enabling it will provide intellisense for Svelte files from TS/JS files. ' +
'Would you like to enable it? ' +
'You can always enable/disable it later on through the extension settings.',
...answers
);

if (response === answers[2]) {
workspace.getConfiguration('svelte').update('enable-ts-plugin', true, true);
} else if (response === answers[1]) {
workspace.getConfiguration('svelte').update('ask-to-enable-ts-plugin', false, true);
}
}
}

0 comments on commit 51255fe

Please sign in to comment.