{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11810","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11810/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11810/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11810/events","html_url":"https://github.com/Microsoft/TypeScript/issues/11810","id":184815792,"number":11810,"title":"Expose ability to add more files to program","user":{"login":"alexsaveliev","id":7010538,"avatar_url":"https://avatars.githubusercontent.com/u/7010538?v=3","gravatar_id":"","url":"https://api.github.com/users/alexsaveliev","html_url":"https://github.com/alexsaveliev","followers_url":"https://api.github.com/users/alexsaveliev/followers","following_url":"https://api.github.com/users/alexsaveliev/following{/other_user}","gists_url":"https://api.github.com/users/alexsaveliev/gists{/gist_id}","starred_url":"https://api.github.com/users/alexsaveliev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexsaveliev/subscriptions","organizations_url":"https://api.github.com/users/alexsaveliev/orgs","repos_url":"https://api.github.com/users/alexsaveliev/repos","events_url":"https://api.github.com/users/alexsaveliev/events{/privacy}","received_events_url":"https://api.github.com/users/alexsaveliev/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/API","name":"API","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-24T11:32:30Z","updated_at":"2016-10-24T19:45:05Z","closed_at":null,"body":"I'd like to propose exposing ability to add more files to `Program`, when object is already constructed.\r\n\r\nWhen using TypeScript to fetch hovers and definitions (compatible with LSP protocol) it may be redundant to parse the whole workspace to get hover or definition from single file. For example microsoft/vscode contains about 16Mb in 2500 files. I think it may be enough to add explicitly one file (and implicitly references and imports) to obtain hover info, this way we may decrease latency while source code is being analyzed. Please note that this proposal, however, does not work with LSP `references` or `workspace symbols` requests where we need to operate with the whole workspace to retrieve proper data).\r\n\r\nMy suggestion is the following:\r\n\r\nExpose new `Program::addFile(fileName: string): void` method that will call `processRootFile(fileName, /*isDefaultLib*/ false)`\r\n\r\nUsage scenario may be the following:\r\n\r\n- construct new `LanguageService` object using `LanguageServiceHost` that provides empty array for     `getScriptFileNames()`\r\n- when hover or definition is requested, checking if `LanguageService::getProgram()` contains source file with the given name using `Program::getSourceFile` method and if not, calling new `Program::addFile` method.\r\n- Then calling `LanguageService::getQuickInfoAtPosition` will synchronize program data and source code of newly added files will be fetched and parsed.\r\n\r\nThis proposal does not break existing functionality or introduce performance degradation.\r\n\r\nI am ready to submit a PR if my suggestion will be accepted"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/255844812","html_url":"https://github.com/Microsoft/TypeScript/issues/11810#issuecomment-255844812","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11810","id":255844812,"user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"created_at":"2016-10-24T19:45:05Z","updated_at":"2016-10-24T19:45:05Z","body":"see https://github.com/Microsoft/TypeScript/blob/4dc60282639aa22b87f6446b625fe360e525c3ed/src/services/services.ts#L1087 for how the language service does that."}}
{"actor":{"display_login":"mhegazy"}}