|
1 | 1 | import ts from 'typescript';
|
2 | 2 | import { DocumentSnapshot } from './DocumentSnapshot';
|
3 |
| -import { isSvelte } from './utils'; |
4 |
| -import { dirname } from 'path'; |
| 3 | +import { isSvelte, getScriptKindFromFileName } from './utils'; |
| 4 | +import { dirname, resolve } from 'path'; |
5 | 5 | import { Document } from '../../api';
|
| 6 | +import { getSveltePackageInfo } from '../svelte/sveltePackage'; |
6 | 7 |
|
7 | 8 | export interface LanguageServiceContainer {
|
8 | 9 | getService(): ts.LanguageService;
|
@@ -40,13 +41,17 @@ export function createLanguageService(
|
40 | 41 | ): LanguageServiceContainer {
|
41 | 42 | const workspacePath = tsconfigPath ? dirname(tsconfigPath) : '';
|
42 | 43 | const documents = new Map<string, DocumentSnapshot>();
|
| 44 | + const sveltePkgInfo = getSveltePackageInfo(workspacePath); |
43 | 45 |
|
44 | 46 | let compilerOptions: ts.CompilerOptions = {
|
45 | 47 | allowNonTsExtensions: true,
|
46 | 48 | target: ts.ScriptTarget.Latest,
|
47 | 49 | module: ts.ModuleKind.ESNext,
|
48 | 50 | moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
49 | 51 | allowJs: true,
|
| 52 | + types: [ |
| 53 | + resolve(sveltePkgInfo.path, 'types', 'runtime') |
| 54 | + ] |
50 | 55 | };
|
51 | 56 |
|
52 | 57 | const configJson = tsconfigPath && ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
|
@@ -82,9 +87,18 @@ export function createLanguageService(
|
82 | 87 | },
|
83 | 88 | getCurrentDirectory: () => workspacePath,
|
84 | 89 | getDefaultLibFileName: ts.getDefaultLibFilePath,
|
| 90 | + |
85 | 91 | fileExists: ts.sys.fileExists,
|
86 | 92 | readFile: ts.sys.readFile,
|
87 | 93 | readDirectory: ts.sys.readDirectory,
|
| 94 | + getScriptKind: (fileName: string) => { |
| 95 | + const doc = getSvelteSnapshot(fileName); |
| 96 | + if(doc) { |
| 97 | + return doc.scriptKind; |
| 98 | + } |
| 99 | + |
| 100 | + return getScriptKindFromFileName(fileName); |
| 101 | + }, |
88 | 102 | };
|
89 | 103 | let languageService = ts.createLanguageService(host);
|
90 | 104 |
|
|
0 commit comments