Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(website): Show tsconfig parsing errors in tab#10991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
5c65c43
f20593c
a619ba6
f8903df
eb539d9
74e80cf
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
developer-bandi marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,6 +7,10 @@ import type { | ||
} from '@typescript-eslint/utils/ts-eslint'; | ||
import type * as ts from 'typescript'; | ||
import type { | ||
ErrorGroup, | ||
TabType, | ||
} from '../../../../website/src/components/types'; | ||
import type { | ||
LinterOnLint, | ||
LinterOnParse, | ||
@@ -42,6 +46,9 @@ export function createLinter( | ||
system: PlaygroundSystem, | ||
webLinterModule: WebLinterModule, | ||
vfs: typeof tsvfs, | ||
onMarkersChange: React.Dispatch< | ||
React.SetStateAction<Record<TabType, ErrorGroup[]>> | ||
>, | ||
): CreateLinter { | ||
const rules: CreateLinter['rules'] = new Map(); | ||
const configs = new Map(Object.entries(webLinterModule.configs)); | ||
@@ -153,14 +160,47 @@ export function createLinter( | ||
}; | ||
const applyTSConfig = (fileName: string): void => { | ||
let error: ErrorGroup | null = null; | ||
try { | ||
const file = system.readFile(fileName) ?? '{}'; | ||
const parsed = parseTSConfig(file).compilerOptions; | ||
compilerOptions = createCompilerOptions(parsed); | ||
console.log('[Editor] Updating', fileName, compilerOptions); | ||
parser.updateConfig(compilerOptions); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
error = { | ||
group: 'TypeScript', | ||
items: e.message | ||
.trim() | ||
.split('\n') | ||
.map((message: string) => { | ||
Comment on lines +177 to +178 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do you have an example of a message that needs to be split? I've only been able to make versions with a single reported error at a time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. | ||
return { | ||
message, | ||
severity: 8, // MarkerSeverity.Error | ||
}; | ||
}), | ||
uri: undefined, | ||
}; | ||
} | ||
} finally { | ||
onMarkersChange(prev => { | ||
const activeTabErrors = Object.fromEntries( | ||
prev.tsconfig.map(error => [error.group, error]), | ||
); | ||
if (error) { | ||
activeTabErrors.TypeScript = error; | ||
} else { | ||
delete activeTabErrors.TypeScript; | ||
} | ||
return { | ||
...prev, | ||
tsconfig: Object.values(activeTabErrors), | ||
}; | ||
}); | ||
} | ||
}; | ||
Uh oh!
There was an error while loading.Please reload this page.