Skip to content

Commit

Permalink
skip type-check for shim files
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Aug 16, 2024
1 parent 6f87833 commit cd76dbe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
48 changes: 33 additions & 15 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface LanguageServiceContainer {
getTsConfigSvelteOptions(): { namespace: string };
getResolvedProjectReferences(): TsConfigInfo[];
openVirtualDocument(document: Document): void;
isShimFiles(filePath: string): boolean;
dispose(): void;
}

Expand Down Expand Up @@ -353,22 +354,8 @@ async function createLanguageService(
? importSvelte(tsconfigPath || workspacePath)
: undefined;

const isSvelte3 = sveltePackageInfo.version.major === 3;
const svelteHtmlDeclaration = isSvelte3
? undefined
: join(sveltePackageInfo.path, 'svelte-html.d.ts');
const svelteHtmlFallbackIfNotExist =
svelteHtmlDeclaration && tsSystem.fileExists(svelteHtmlDeclaration)
? svelteHtmlDeclaration
: './svelte-jsx-v4.d.ts';

const changedFilesForExportCache = new Set<string>();

const svelteTsxFiles = (
isSvelte3
? ['./svelte-shims.d.ts', './svelte-jsx.d.ts', './svelte-native-jsx.d.ts']
: ['./svelte-shims-v4.d.ts', svelteHtmlFallbackIfNotExist, './svelte-native-jsx.d.ts']
).map((f) => tsSystem.resolvePath(resolve(svelteTsPath, f)));
const svelteTsxFiles = getSvelteShimFiles();

let languageServiceReducedMode = false;
let projectVersion = 0;
Expand Down Expand Up @@ -446,6 +433,7 @@ async function createLanguageService(
getTsConfigSvelteOptions,
getResolvedProjectReferences,
openVirtualDocument,
isShimFiles,
dispose
};

Expand Down Expand Up @@ -1153,6 +1141,36 @@ async function createLanguageService(
updateSnapshot(document);
scheduleUpdate(filePath);
}

function getSvelteShimFiles() {
const isSvelte3 = sveltePackageInfo.version.major === 3;
const svelteHtmlDeclaration = isSvelte3
? undefined
: join(sveltePackageInfo.path, 'svelte-html.d.ts');
const svelteHtmlFallbackIfNotExist =
svelteHtmlDeclaration && tsSystem.fileExists(svelteHtmlDeclaration)
? svelteHtmlDeclaration
: './svelte-jsx-v4.d.ts';

const svelteTsxFiles = (
isSvelte3
? ['./svelte-shims.d.ts', './svelte-jsx.d.ts', './svelte-native-jsx.d.ts']
: [
'./svelte-shims-v4.d.ts',
svelteHtmlFallbackIfNotExist,
'./svelte-native-jsx.d.ts'
]
).map((f) => tsSystem.resolvePath(resolve(svelteTsPath, f)));

const result = new FileSet(tsSystem.useCaseSensitiveFileNames);

svelteTsxFiles.forEach((f) => result.add(normalizePath(f)));
return result;
}

function isShimFiles(filePath: string) {
return svelteTsxFiles.has(normalizePath(filePath));
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/language-server/src/svelte-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class SvelteCheck {
const skipDiagnosticsForFile =
(options.skipLibCheck && file.isDeclarationFile) ||
(options.skipDefaultLibCheck && file.hasNoDefaultLib) ||
lsContainer.isShimFiles(file.fileName) ||
// ignore JS files in node_modules
/\/node_modules\/.+\.(c|m)?js$/.test(file.fileName);
const snapshot = lsContainer.snapshotManager.get(file.fileName) as
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-check/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@tsconfig/node12/tsconfig.json",
"compilerOptions": {
"target": "ES2019",
"moduleResolution": "node",
"strict": true,
"allowJs": true,
Expand Down

0 comments on commit cd76dbe

Please sign in to comment.