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

isProgramUpToDate reports false because it expects HostCache to include typescript/lib/*.d.ts files #36748

Closed
cspotcode opened this issue Feb 12, 2020 · 0 comments · Fixed by #36808
Assignees
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@cspotcode
Copy link

TypeScript Version: 3.8.0-dev.20200211

Search Terms:

isProgramUpToDate
getScriptFileNames

Code

Full reproduction:
https://github.com/TypeStrong/ts-node-repros/blob/tsIsProgramUpToDate/example.ts
Output:
https://github.com/TypeStrong/ts-node-repros/blob/tsIsProgramUpToDate/output.txt

Briefly, if I create a languageService and repeatedly ask it for the Program, it should return the same program instance each time, provided nothing has changed.

//... create LanguageService using a LanguageServiceHost that does not implement getProjectVersion
assert(languageService.getProgram() === languageService.getProgram())

Expected behavior:

Same Program instance is returned because isProgramUpToDate() returns true.

Actual behavior:

New Program instance is returned each time because isProgramUpToDate() always returns false.

I believe this is the culprit:
https://github.com/microsoft/TypeScript/blob/master/src/compiler/program.ts#L586-L589
It asks HostCache for the version of all program.getSourceFiles().
However, the HostCache only contains host.getScriptFileNames()

host.getScriptFileNames() contains only root files, for example, the contents of a src directory.
program.getSourceFiles() contains things like typescript/lib/lib.es5.d.ts
As far as I know, host.getScriptFileNames() must never include typescript/lib/lib*.d.ts

Thus isProgramUpToDate() is doomed to fail every time, as far as I can tell.

Related Issues:

#36010

@sheetalkamat sheetalkamat added Bug A bug in TypeScript API Relates to the public API for TypeScript labels Feb 12, 2020
@sheetalkamat sheetalkamat self-assigned this Feb 12, 2020
@sheetalkamat sheetalkamat added this to the TypeScript 3.9.0 milestone Feb 14, 2020
@sheetalkamat sheetalkamat added the Fix Available A PR has been opened for this issue label Feb 14, 2020
sheetalkamat added a commit that referenced this issue Feb 26, 2020
…ked correctly (#36808)

* Fix tests when there are project references but has disableSourceOfProjectReferenceRedirect

* Handle getScriptVersion correctly to ensure program structure is checked correctly
Fixes #36748

* Harness's language service host doesnt have getProjectVersion.
This means earlier we were creating fresh program everytime we did LS operation
Now we reuse same program, so quick info depends on order of quickinfo demands

* Because same program is used, it unvails a bug that if `export=` is evaluated before finding references, it cant find all definitions from the merge

* Update src/server/project.ts

Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Make clearSourceMapperCache required

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
2 participants