diff --git a/packages/language-server/src/plugins/TypeScriptPlugin.ts b/packages/language-server/src/plugins/TypeScriptPlugin.ts index bdd36d7a1..125719623 100644 --- a/packages/language-server/src/plugins/TypeScriptPlugin.ts +++ b/packages/language-server/src/plugins/TypeScriptPlugin.ts @@ -91,12 +91,9 @@ export class TypeScriptPlugin let diagnostics: ts.Diagnostic[] = [ ...lang.getSyntacticDiagnostics(document.getFilePath()!), ...lang.getSuggestionDiagnostics(document.getFilePath()!), + ...lang.getSemanticDiagnostics(document.getFilePath()!) ]; - if (isTypescript) { - diagnostics.push(...lang.getSemanticDiagnostics(document.getFilePath()!)); - } - return diagnostics.map(diagnostic => ({ range: convertRange(document, diagnostic), severity: mapSeverity(diagnostic.category), diff --git a/packages/language-server/src/plugins/typescript/service.ts b/packages/language-server/src/plugins/typescript/service.ts index 3c1d0082b..8abdd6903 100644 --- a/packages/language-server/src/plugins/typescript/service.ts +++ b/packages/language-server/src/plugins/typescript/service.ts @@ -1,8 +1,9 @@ import ts from 'typescript'; import { DocumentSnapshot } from './DocumentSnapshot'; -import { isSvelte } from './utils'; -import { dirname } from 'path'; +import { isSvelte, getScriptKindFromFileName } from './utils'; +import { dirname, resolve } from 'path'; import { Document } from '../../api'; +import { getSveltePackageInfo } from '../svelte/sveltePackage'; export interface LanguageServiceContainer { getService(): ts.LanguageService; @@ -40,6 +41,7 @@ export function createLanguageService( ): LanguageServiceContainer { const workspacePath = tsconfigPath ? dirname(tsconfigPath) : ''; const documents = new Map(); + const sveltePkgInfo = getSveltePackageInfo(workspacePath); let compilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, @@ -47,6 +49,9 @@ export function createLanguageService( module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true, + types: [ + resolve(sveltePkgInfo.path, 'types', 'runtime') + ] }; const configJson = tsconfigPath && ts.readConfigFile(tsconfigPath, ts.sys.readFile).config; @@ -82,9 +87,18 @@ export function createLanguageService( }, getCurrentDirectory: () => workspacePath, getDefaultLibFileName: ts.getDefaultLibFilePath, + fileExists: ts.sys.fileExists, readFile: ts.sys.readFile, readDirectory: ts.sys.readDirectory, + getScriptKind: (fileName: string) => { + const doc = getSvelteSnapshot(fileName); + if(doc) { + return doc.scriptKind; + } + + return getScriptKindFromFileName(fileName); + }, }; let languageService = ts.createLanguageService(host);