Skip to content
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

Fix typescript rechecking after files change. #4187

Merged
merged 7 commits into from
Feb 25, 2020
26 changes: 18 additions & 8 deletions packages/validators/typescript/src/TypeScriptValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {md5FromObject} from '@parcel/utils';
import {Validator} from '@parcel/plugin';
import {LanguageServiceHost} from '@parcel/ts-utils';

let langServiceCache = {};
let langServiceCache: {
[configHash: string]: {|host: LanguageServiceHost, service: any|},
...,
} = {};

type TSValidatorConfig = {|
filepath: string | null,
Expand Down Expand Up @@ -48,18 +51,25 @@ export default new Validator({
ts.sys,
baseDir,
);

langServiceCache[configHash] = ts.createLanguageService(
new LanguageServiceHost(options.inputFS, ts, parsedCommandLine),
ts.createDocumentRegistry(),
const host = new LanguageServiceHost(
options.inputFS,
ts,
parsedCommandLine,
);
langServiceCache[configHash] = {
host,
service: ts.createLanguageService(host, ts.createDocumentRegistry()),
};
}

if (!langServiceCache[configHash]) return;

const diagnostics = langServiceCache[configHash].getSemanticDiagnostics(
asset.filePath,
);
// Make sure that when the typescript language service asks us for this file, we let it know that there is a new version.
langServiceCache[configHash].host.invalidate(asset.filePath);
DeMoorJasper marked this conversation as resolved.
Show resolved Hide resolved

const diagnostics = langServiceCache[
astegmaier marked this conversation as resolved.
Show resolved Hide resolved
configHash
].service.getSemanticDiagnostics(asset.filePath);

let validatorResult = {
warnings: [],
Expand Down