-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
I'm in the process of updating a language service client and re-provider (provides access to language services from the commandline, for editor plugins) from codeplex to github versions of typescript, and once again I'm struggling with the sparse documentation.
The variety of interfaces is confusing. One the one hand, there are the compiler vs language service differences, eg, CompilerHost vs ServiceHost, Program vs DocumentRegistry, on the other hand, there seem to be way too many ways of storing sets of file (with associated information).
https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API helps a little bit, but inline docs and a concept map would be helpful, explaining why each of those is necessary and how they relate to each other.
It would be great to have a place to discuss language services API design and usage.
My first concrete question is about import/reference resolution: how do I integrate that with a language service client, without duplicating code?
There used to be a Resolver in the compiler sources that could be used to do nothing but close a set of filenames under import, reference, and filename normalization. That was easy to use.
Now, that functionality seems to be hidden in createProgram. createLanguageService internally uses createProgram, without exposing the Program, but it seems to have no less than four sources of truth about files in the project: the documentRegistry, which seems to be an externally visible copy of the internal sourceFilesByName, in addition to which there are host and hostCache (and program, which is read-only-connected to sourceFilesByName via its compilerHost).
That leaves me with two problems:
-
after createProgram, program.getSourceFiles might have more files than sourceFilesByName (added through import/reference resolution) and I don't see how this information is propagated?
if I get this right, synchronizeHostData should nearly always do unnecessary work, and will not bring program.getSourceFiles in sync with sourceFilesByName; the language service API functions then use program.getSourceFiles, which is a superset of sourceFilesByName, which should be correct if possibly inefficient (since each of them calls synchronizeHostData)
-
once I have a language service, how do I modify its set of files, taking import/reference resolution into account, without recreating the whole thing from scratch?