Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/website/src/components/linter/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export function createFileSystem(
const files = new Map<string, string>();
files.set(`/.eslintrc`, config.eslintrc);
files.set(`/tsconfig.json`, config.tsconfig);
files.set(`/input${config.fileType}`, config.code);
if (config.code !== '') {
files.set(`/input${config.fileType}`, config.code);
}

const fileWatcherCallbacks = new Map<RegExp, Set<ts.FileWatcherCallback>>();

Expand Down Expand Up @@ -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.'))
.filter(f => !f.endsWith('/.eslintrc') && !f.endsWith('.json'));
};
return system;
}
8 changes: 3 additions & 5 deletions packages/website/src/components/linter/createParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ export function createParser(
): {
updateConfig: (compilerOptions: ts.CompilerOptions) => void;
} & Parser.ParserModule {
const registeredFiles = new Set<string>();

const createEnv = (
compilerOptions: ts.CompilerOptions,
): tsvfs.VirtualTypeScriptEnvironment => {
return vfs.createVirtualTypeScriptEnvironment(
system,
[...registeredFiles],
system.getScriptFileNames(),
window.ts,
compilerOptions,
);
Expand All @@ -46,10 +44,10 @@ export function createParser(
// if text is empty use empty line to avoid error
const code = text || '\n';

if (registeredFiles.has(filePath)) {
if (system.fileExists(filePath)) {
compilerHost.updateFile(filePath, code);
} else {
registeredFiles.add(filePath);
system.writeFile(filePath, code);
compilerHost.createFile(filePath, code);
}

Expand Down
1 change: 1 addition & 0 deletions packages/website/src/components/linter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface WebLinterModule {
export type PlaygroundSystem = {
removeFile: (fileName: string) => void;
searchFiles: (path: string) => string[];
getScriptFileNames: () => string[];
} & Required<Pick<ts.System, 'deleteFile' | 'watchFile'>> &
ts.System;

Expand Down