|
1 |
| -import { basename, dirname, resolve } from 'path'; |
| 1 | +import { basename, dirname, join, resolve } from 'path'; |
2 | 2 | import ts from 'typescript';
|
3 | 3 | import { TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol';
|
4 |
| -import { getPackageInfo, importSvelte } from '../../importPackage'; |
| 4 | +import { getPackageInfo } from '../../importPackage'; |
5 | 5 | import { Document } from '../../lib/documents';
|
6 | 6 | import { configLoader } from '../../lib/documents/configLoader';
|
7 | 7 | import { FileMap, FileSet } from '../../lib/documents/fileCollection';
|
@@ -216,11 +216,21 @@ async function createLanguageService(
|
216 | 216 | // Fall back to dirname
|
217 | 217 | svelteTsPath = __dirname;
|
218 | 218 | }
|
219 |
| - const VERSION = importSvelte(tsconfigPath || workspacePath).VERSION; |
| 219 | + const sveltePackageInfo = getPackageInfo('svelte', tsconfigPath || workspacePath); |
| 220 | + |
| 221 | + const isSvelte3 = sveltePackageInfo.version.major === 3; |
| 222 | + const svelteHtmlDeclaration = isSvelte3 |
| 223 | + ? undefined |
| 224 | + : join(sveltePackageInfo.path, 'svelte-html.d.ts'); |
| 225 | + const svelteHtmlFallbackIfNotExist = |
| 226 | + svelteHtmlDeclaration && tsSystem.fileExists(svelteHtmlDeclaration) |
| 227 | + ? svelteHtmlDeclaration |
| 228 | + : './svelte-jsx-v4.d.ts'; |
| 229 | + |
220 | 230 | const svelteTsxFiles = (
|
221 |
| - VERSION.split('.')[0] === '3' |
| 231 | + isSvelte3 |
222 | 232 | ? ['./svelte-shims.d.ts', './svelte-jsx.d.ts', './svelte-native-jsx.d.ts']
|
223 |
| - : ['./svelte-shims-v4.d.ts', './svelte-jsx-v4.d.ts', './svelte-native-jsx.d.ts'] |
| 233 | + : ['./svelte-shims-v4.d.ts', svelteHtmlFallbackIfNotExist, './svelte-native-jsx.d.ts'] |
224 | 234 | ).map((f) => tsSystem.resolvePath(resolve(svelteTsPath, f)));
|
225 | 235 |
|
226 | 236 | let languageServiceReducedMode = false;
|
|
0 commit comments