Skip to content

Commit c6d89f6

Browse files
committed
Filter diagnostics if only MDX files are found
If a TypeScript project doesn’t include any files, this is reported on `tsconfig.json`. However, it’s useful to have a `tsconfig.json` file to configure TypeScript inside MDX. This diagnostic is now filtered if there are MDX files in the project.
1 parent f1761aa commit c6d89f6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

.changeset/flat-bottles-carry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@mdx-js/typescript-plugin': patch
3+
'vscode-mdx': patch
4+
---
5+
6+
Fix `tsconfig.json` diagnostics if only MDX inputs are found

packages/typescript-plugin/lib/index.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ const {default: remarkFrontmatter} = require('remark-frontmatter')
1616
const {default: remarkGfm} = require('remark-gfm')
1717

1818
const plugin = createLanguageServicePlugin((ts, info) => {
19+
const {getAllProjectErrors} = info.project
20+
21+
// Filter out the message “No inputs were found in config file …” if the
22+
// project contains MDX files.
23+
info.project.getAllProjectErrors = () => {
24+
const diagnostics = getAllProjectErrors.call(info.project)
25+
const fileNames = info.project.getFileNames(true, true)
26+
27+
const hasMdx = fileNames.some((fileName) => fileName.endsWith('.mdx'))
28+
29+
if (hasMdx) {
30+
diagnostics.filter((diagnostic) => diagnostic.code !== 18003)
31+
}
32+
33+
return diagnostics
34+
}
35+
1936
if (info.project.projectKind !== ts.server.ProjectKind.Configured) {
2037
return {
2138
languagePlugins: [

0 commit comments

Comments
 (0)