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
base:main
Are you sure you want to change the base?
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); | ||
} | ||
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.')) | ||
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. Lib files will be excluded from the Monaco Editor GitHub repository.monaco-editor
| ||
.filter(f => !f.endsWith('/.eslintrc') && !f.endsWith('.json')); | ||
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. These files cause an error in the code below.typescript-website
| ||
}; | ||
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(); | ||
}; | ||
Comment on lines +169 to +172 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. We need this code to add the library and trigger linting after the parser is created, in case the user starts typing code in an empty playground. | ||
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); | ||
}, | ||
Comment on lines +110 to +112 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. We have to add library files using
| ||
updateConfig(compilerOptions): void { | ||
compilerHost = createEnv(compilerOptions); | ||
}, | ||