Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(website): acquired types are shown in the editor but not reflected in linting#11198
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
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
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -14,7 +14,9 @@ export function createFileSystem( | ||||||||||||||||
const files = new Map<string, string>(); | ||||||||||||||||
files.set(`/.eslintrc`, config.eslintrc); | ||||||||||||||||
files.set(`/tsconfig.json`, config.tsconfig); | ||||||||||||||||
if (config.code !== '') { | ||||||||||||||||
files.set(`/input${config.fileType}`, config.code); | ||||||||||||||||
} | ||||||||||||||||
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. [Question] Why wouldn't we want to set 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. The above code is executed when the playground is first loaded.
When we set If the above code is missing, the playground will not load successfully when the user clicks the playground button in thispage Therefore, we should avoid setting
Also, when the user changes the code to 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. Nice, that makes sense. Thanks! | ||||||||||||||||
const fileWatcherCallbacks = new Map<RegExp, Set<ts.FileWatcherCallback>>(); | ||||||||||||||||
@@ -78,6 +80,10 @@ export function createFileSystem( | ||||||||||||||||
const expPath = getPathRegExp(path); | ||||||||||||||||
return [...files.keys()].filter(fileName => expPath.test(fileName)); | ||||||||||||||||
}; | ||||||||||||||||
system.getScriptFileNames = (): string[] => { | ||||||||||||||||
return [...files.keys()] | ||||||||||||||||
.filter(fileName => !fileName.startsWith('/lib.')) | ||||||||||||||||
mdm317 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||||||||||
.filter(f => !f.endsWith('/.eslintrc') && !f.endsWith('.json')); | ||||||||||||||||
mdm317 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||||||||||
}; | ||||||||||||||||
return system; | ||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11,6 +11,7 @@ import type { | ||
LinterOnLint, | ||
LinterOnParse, | ||
PlaygroundSystem, | ||
RegisterFile, | ||
WebLinterModule, | ||
} from './types'; | ||
@@ -36,6 +37,7 @@ export interface CreateLinter { | ||
triggerFix(filename: string): Linter.FixReport | undefined; | ||
triggerLint(filename: string): void; | ||
updateParserOptions(sourceType?: SourceType): void; | ||
registerFile: RegisterFile; | ||
} | ||
export function createLinter( | ||
@@ -164,6 +166,11 @@ export function createLinter( | ||
} | ||
}; | ||
const registerFile = (fileName: string, code: string) => { | ||
parser.registerFile(fileName, code); | ||
triggerLintAll(); | ||
}; | ||
mdm317 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
const triggerLintAll = (): void => { | ||
system.searchFiles('/input.*').forEach(triggerLint); | ||
}; | ||
@@ -185,6 +192,7 @@ export function createLinter( | ||
configs: [...configs.keys()], | ||
onLint: onLint.register, | ||
onParse: onParse.register, | ||
registerFile, | ||
rules, | ||
triggerFix, | ||
triggerLint, | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,6 +6,7 @@ import type * as ts from 'typescript'; | ||
import type { | ||
ParseSettings, | ||
PlaygroundSystem, | ||
RegisterFile, | ||
UpdateModel, | ||
WebLinterModule, | ||
} from './types'; | ||
@@ -20,15 +21,14 @@ export function createParser( | ||
vfs: typeof tsvfs, | ||
): { | ||
updateConfig: (compilerOptions: ts.CompilerOptions) => void; | ||
registerFile: RegisterFile; | ||
} & Parser.ParserModule { | ||
const createEnv = ( | ||
compilerOptions: ts.CompilerOptions, | ||
): tsvfs.VirtualTypeScriptEnvironment => { | ||
return vfs.createVirtualTypeScriptEnvironment( | ||
system, | ||
system.getScriptFileNames(), | ||
window.ts, | ||
compilerOptions, | ||
); | ||
@@ -46,10 +46,9 @@ export function createParser( | ||
// if text is empty use empty line to avoid error | ||
const code = text || '\n'; | ||
if (system.fileExists(filePath)) { | ||
compilerHost.updateFile(filePath, code); | ||
} else { | ||
compilerHost.createFile(filePath, code); | ||
} | ||
@@ -108,6 +107,9 @@ export function createParser( | ||
visitorKeys: utils.visitorKeys, | ||
}; | ||
}, | ||
registerFile(filePath: string, code: string): void { | ||
compilerHost.createFile(filePath, code); | ||
}, | ||
mdm317 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
updateConfig(compilerOptions): void { | ||
compilerHost = createEnv(compilerOptions); | ||
}, | ||