From 663e602da39f118b1936a086612dd4975cdd5db2 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:16:36 +0200 Subject: [PATCH] feat: add option to force-start svelte plugin (#2185) This adds the assumeIsSvelteProject project for the typescript plugin. Some editors like Intellij may use their own detection mechanisms for whether or not a plugin should run, and this allows them to do that and skip our detection mechanism. --- packages/typescript-plugin/README.md | 5 ++++- packages/typescript-plugin/src/config-manager.ts | 5 ++++- packages/typescript-plugin/src/index.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/typescript-plugin/README.md b/packages/typescript-plugin/README.md index 1dc80b9d5..7c2e01ffb 100644 --- a/packages/typescript-plugin/README.md +++ b/packages/typescript-plugin/README.md @@ -24,7 +24,10 @@ Then add it to your `tsconfig.json` or `jsconfig.json`: "compilerOptions": { ... "plugins": [{ - "name": "typescript-svelte-plugin" + "name": "typescript-svelte-plugin", + // the following options can be set additionally; they are optional; their default values are listed here + "enabled": true, // enables this plugin + "assumeIsSvelteProject": false // if true, skip detection and always assume it's a Svelte project }] } } diff --git a/packages/typescript-plugin/src/config-manager.ts b/packages/typescript-plugin/src/config-manager.ts index f1232fc16..82f046598 100644 --- a/packages/typescript-plugin/src/config-manager.ts +++ b/packages/typescript-plugin/src/config-manager.ts @@ -4,12 +4,15 @@ const configurationEventName = 'configuration-changed'; export interface Configuration { enable: boolean; + /** Skip the Svelte detection and assume this is a Svelte project */ + assumeIsSvelteProject: boolean; } export class ConfigManager { private emitter = new EventEmitter(); private config: Configuration = { - enable: true + enable: true, + assumeIsSvelteProject: false }; onConfigurationChanged(listener: (config: Configuration) => void) { diff --git a/packages/typescript-plugin/src/index.ts b/packages/typescript-plugin/src/index.ts index 3c9653d54..3c85949ae 100644 --- a/packages/typescript-plugin/src/index.ts +++ b/packages/typescript-plugin/src/index.ts @@ -14,7 +14,10 @@ function init(modules: { typescript: typeof ts }): ts.server.PluginModule { function create(info: ts.server.PluginCreateInfo) { const logger = new Logger(info.project.projectService.logger); - if (!isSvelteProject(info.project.getCompilerOptions())) { + if ( + !(info.config as Configuration)?.assumeIsSvelteProject && + !isSvelteProject(info.project.getCompilerOptions()) + ) { logger.log('Detected that this is not a Svelte project, abort patching TypeScript'); return info.languageService; }