Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) ask to enable ts plugin #1160

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}