{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1786","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1786/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1786/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1786/events","html_url":"https://github.com/Microsoft/TypeScript/issues/1786","id":55281629,"number":1786,"title":"please clarify language service import/reference resolution and set-of-files handling","user":{"login":"clausreinke","id":837040,"avatar_url":"https://avatars.githubusercontent.com/u/837040?v=3","gravatar_id":"","url":"https://api.github.com/users/clausreinke","html_url":"https://github.com/clausreinke","followers_url":"https://api.github.com/users/clausreinke/followers","following_url":"https://api.github.com/users/clausreinke/following{/other_user}","gists_url":"https://api.github.com/users/clausreinke/gists{/gist_id}","starred_url":"https://api.github.com/users/clausreinke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clausreinke/subscriptions","organizations_url":"https://api.github.com/users/clausreinke/orgs","repos_url":"https://api.github.com/users/clausreinke/repos","events_url":"https://api.github.com/users/clausreinke/events{/privacy}","received_events_url":"https://api.github.com/users/clausreinke/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Question","name":"Question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-01-23T13:33:59Z","updated_at":"2015-01-24T02:38:43Z","closed_at":null,"body":"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.\r\n\r\nThe 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). \r\n\r\nhttps://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.\r\n\r\nIt would be great to have a place to discuss language services API design and usage.\r\n\r\nMy first concrete question is about import/reference resolution: how do I integrate that with a language service client, without duplicating code? \r\n\r\nThere 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.\r\n\r\nNow, 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).\r\n\r\nThat leaves me with two problems:\r\n\r\n1. 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?\r\n\r\n  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)\r\n\r\n2. 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?"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/71296851","html_url":"https://github.com/Microsoft/TypeScript/issues/1786#issuecomment-71296851","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1786","id":71296851,"user":{"login":"basarat","id":874898,"avatar_url":"https://avatars.githubusercontent.com/u/874898?v=3","gravatar_id":"","url":"https://api.github.com/users/basarat","html_url":"https://github.com/basarat","followers_url":"https://api.github.com/users/basarat/followers","following_url":"https://api.github.com/users/basarat/following{/other_user}","gists_url":"https://api.github.com/users/basarat/gists{/gist_id}","starred_url":"https://api.github.com/users/basarat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basarat/subscriptions","organizations_url":"https://api.github.com/users/basarat/orgs","repos_url":"https://api.github.com/users/basarat/repos","events_url":"https://api.github.com/users/basarat/events{/privacy}","received_events_url":"https://api.github.com/users/basarat/received_events","type":"User","site_admin":false},"created_at":"2015-01-24T02:38:43Z","updated_at":"2015-01-24T02:38:43Z","body":"@mhegazy Excellent! I didn't know the reason for document registry. Super cool!"}}