From 026111228b5814a9109cc4d779d37fb02955fb8b Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 17 Jun 2024 21:31:59 +0200 Subject: [PATCH] fix: adjust ambient module snipping logic Since https://github.com/sveltejs/svelte/pull/12061 the `declare module "*.svelte" {..}` declaration contains more closing braces and the logic to snip it out is now outdated. This updates the logic to instead look for the first bracket that comes directly after one line. --- .../language-server/src/plugins/typescript/DocumentSnapshot.ts | 2 +- packages/typescript-plugin/src/index.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts b/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts index c0d21d282..00c902554 100644 --- a/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts +++ b/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts @@ -136,7 +136,7 @@ export namespace DocumentSnapshot { if (normalizedPath.endsWith('node_modules/svelte/types/index.d.ts')) { const startIdx = originalText.indexOf(`declare module '*.svelte' {`); - const endIdx = originalText.indexOf(`}`, originalText.indexOf(';', startIdx)) + 1; + const endIdx = originalText.indexOf(`\n}`, startIdx + 1) + 2; originalText = originalText.substring(0, startIdx) + ' '.repeat(endIdx - startIdx) + diff --git a/packages/typescript-plugin/src/index.ts b/packages/typescript-plugin/src/index.ts index 1e1bab9d4..b5e572508 100644 --- a/packages/typescript-plugin/src/index.ts +++ b/packages/typescript-plugin/src/index.ts @@ -67,8 +67,7 @@ function init(modules: { typescript: typeof ts }): ts.server.PluginModule { if (snapshot) { const originalText = snapshot.getText(0, snapshot.getLength()); const startIdx = originalText.indexOf(`declare module '*.svelte' {`); - const endIdx = - originalText.indexOf(`}`, originalText.indexOf(';', startIdx)) + 1; + const endIdx = originalText.indexOf(`\n}`, startIdx + 1) + 2; return modules.typescript.ScriptSnapshot.fromString( originalText.substring(0, startIdx) + ' '.repeat(endIdx - startIdx) +