From cb94f4b0067d31d32d854e34e51c75952577d917 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 13 Sep 2022 13:25:36 +0200 Subject: [PATCH] (breaking) enable new transformation by default (#1633) #1552 --- packages/svelte-vscode/package.json | 8 ++++- packages/svelte-vscode/src/extension.ts | 47 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/svelte-vscode/package.json b/packages/svelte-vscode/package.json index 0da65b4f5..d5e98a758 100644 --- a/packages/svelte-vscode/package.json +++ b/packages/svelte-vscode/package.json @@ -271,10 +271,16 @@ }, "svelte.plugin.svelte.useNewTransformation": { "type": "boolean", - "default": false, + "default": true, "title": "Use a new transformation for intellisense", "description": "Svelte files need to be transformed to something that TypeScript understands for intellisense. Version 2.0 of this transformation can be enabled with this setting. It will be the default, soon." }, + "svelte.plugin.svelte.note-new-transformation": { + "type": "boolean", + "default": true, + "title": "Show a note about the new transformation", + "description": "There's a new transformation for improved intellisense which is now turned on by default. This note notifies you about it." + }, "svelte.plugin.svelte.diagnostics.enable": { "type": "boolean", "default": true, diff --git a/packages/svelte-vscode/src/extension.ts b/packages/svelte-vscode/src/extension.ts index 970870c20..0e4ba25fd 100644 --- a/packages/svelte-vscode/src/extension.ts +++ b/packages/svelte-vscode/src/extension.ts @@ -223,6 +223,24 @@ export function activateSvelteLanguageServer(context: ExtensionContext) { return ls; } + noteOfNewTransformation(); + let enabled = workspace + .getConfiguration('svelte.plugin.svelte') + .get('useNewTransformation'); + context.subscriptions.push( + workspace.onDidChangeConfiguration(() => { + if ( + enabled !== + workspace + .getConfiguration('svelte.plugin.svelte') + .get('useNewTransformation') + ) { + enabled = !enabled; + restartLS(false); + } + }) + ); + addDidChangeTextDocumentListener(getLS); addFindFileReferencesListener(getLS, context); @@ -488,3 +506,32 @@ function warnIfOldExtensionInstalled() { ); } } + +async function noteOfNewTransformation() { + const enabled = workspace + .getConfiguration('svelte.plugin.svelte') + .get('useNewTransformation'); + const shouldNote = workspace + .getConfiguration('svelte.plugin.svelte') + .get('note-new-transformation'); + if (!enabled || !shouldNote) { + return; + } + + const answers = ['Ask again later', 'Disable new transformation for now', 'OK']; + const response = await window.showInformationMessage( + 'The Svelte for VS Code extension comes with a new transformation for improved intellisense. ' + + 'It is enabled by default now. If you notice bugs, please report them. ' + + 'You can switch to the old transformation setting "svelte.plugin.svelte.useNewTransformation" to "false".', + ...answers + ); + + if (response === answers[1]) { + workspace + .getConfiguration('svelte.plugin.svelte') + .update('useNewTransformation', false, true); + } + workspace + .getConfiguration('svelte.plugin.svelte') + .update('note-new-transformation', response === answers[0], true); +}