{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/86468946","pull_request_review_id":7126482,"id":86468946,"diff_hunk":"@@ -0,0 +1,279 @@\n+﻿/* @internal */\r\n+namespace ts.codefix {\r\n+    const nodeModulesFolderName = \"node_modules\";\r\n+\r\n+    registerCodeFix({\r\n+        errorCodes: [Diagnostics.Cannot_find_name_0.code],\r\n+        getCodeActions: (context: CodeFixContext, cancellationToken: CancellationToken) => {\r\n+            const sourceFile = context.sourceFile;\r\n+            const checker = context.program.getTypeChecker();\r\n+            const allSourceFiles = context.program.getSourceFiles();\r\n+            const useCaseSensitiveFileNames = context.host.useCaseSensitiveFileNames ? context.host.useCaseSensitiveFileNames() : false;\r\n+\r\n+            const token = getTokenAtPosition(sourceFile, context.span.start);\r\n+            const name = token.getText();\r\n+            const allActions: CodeAction[] = [];\r\n+            let allPotentialModules: Symbol[] = [];\r\n+\r\n+            const ambientModules = checker.getAmbientModules();\r\n+            if (ambientModules) {\r\n+                allPotentialModules = ambientModules;\r\n+            }\r\n+            for (const otherSourceFile of allSourceFiles) {\r\n+                if (otherSourceFile !== sourceFile && otherSourceFile.symbol) {\r\n+                    allPotentialModules.push(otherSourceFile.symbol);\r\n+                }\r\n+            }\r\n+\r\n+            for (const moduleSymbol of allPotentialModules) {\r\n+                cancellationToken.throwIfCancellationRequested();\r\n+\r\n+                const exports = checker.getExportsOfModule(moduleSymbol) || [];\r\n+                for (const exported of exports) {\r\n+                    if (exported.name === name) {\r\n+                        allActions.push(getCodeActionForImport(moduleSymbol));\r\n+                    }\r\n+                }\r\n+            }\r\n+\r\n+            return allActions;\r\n+\r\n+            function getCodeActionForImport(moduleSymbol: Symbol): CodeAction {\r\n+                // Check to see if there are already imports being made from this source in the current file\r\n+                const existingDeclaration = forEach(sourceFile.imports, importModuleSpecifier => {\r\n+                    const importSymbol = checker.getSymbolAtLocation(importModuleSpecifier);\r\n+                    if (importSymbol === moduleSymbol) {\r\n+                        return getImportDeclaration(importModuleSpecifier);\r\n+                    }\r\n+                });\r\n+\r\n+                if (existingDeclaration) {\r\n+                    return getCodeActionForExistingImport(existingDeclaration);\r\n+                }\r\n+                else {\r\n+                    return getCodeActionForNewImport();\r\n+                }\r\n+\r\n+                function getImportDeclaration(moduleSpecifier: LiteralExpression) {\r\n+                    let node: Node = moduleSpecifier;\r\n+                    while (node) {\r\n+                        if (node.kind !== SyntaxKind.ImportDeclaration) {\r\n+                            node = node.parent;\r\n+                        }\r\n+\r\n+                        return <ImportDeclaration>node;\r\n+                    }\r\n+                    return undefined;\r\n+                }\r\n+\r\n+                function getCodeActionForExistingImport(declaration: ImportDeclaration): CodeAction {\r\n+                    const moduleSpecifier = declaration.moduleSpecifier.getText();\r\n+\r\n+                    // We have to handle all of the different import declaration forms\r\n+                    if (declaration.importClause) {\r\n+                        if (declaration.importClause.namedBindings) {\r\n+                            const namedBindings = declaration.importClause.namedBindings;\r\n+                            if (namedBindings.kind === SyntaxKind.NamespaceImport) {\r\n+                                /**\r\n+                                 * Cases:\r\n+                                 *     import * as ns from \"mod\"\r\n+                                 *     import d, * as ns from \"mod\"\r\n+                                 *\r\n+                                 * Because there is no import list, we alter the reference to include the\r\n+                                 * namespace instead of altering the import declaration. For example, \"foo\" would\r\n+                                 * become \"ns.foo\"\r\n+                                 */\r\n+                                const ns = (<NamespaceImport>namedBindings).name.getText();\r\n+                                return createCodeAction(\r","path":"src/services/codefixes/importFixes.ts","position":87,"original_position":87,"commit_id":"1502f75c515d9704989d1e56ef28689e8cfcbb3f","original_commit_id":"1502f75c515d9704989d1e56ef28689e8cfcbb3f","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},"body":"we should also handle import equals declarations the same way.","created_at":"2016-11-04T00:05:45Z","updated_at":"2016-11-04T00:05:45Z","html_url":"https://github.com/Microsoft/TypeScript/pull/11768#discussion_r86468946","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/86468946"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/11768#discussion_r86468946"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768","id":90301324,"html_url":"https://github.com/Microsoft/TypeScript/pull/11768","diff_url":"https://github.com/Microsoft/TypeScript/pull/11768.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/11768.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11768","number":11768,"state":"open","locked":false,"title":"Pvb/fixmissingimports","user":{"login":"paulvanbrenk","id":5273975,"avatar_url":"https://avatars.githubusercontent.com/u/5273975?v=3","gravatar_id":"","url":"https://api.github.com/users/paulvanbrenk","html_url":"https://github.com/paulvanbrenk","followers_url":"https://api.github.com/users/paulvanbrenk/followers","following_url":"https://api.github.com/users/paulvanbrenk/following{/other_user}","gists_url":"https://api.github.com/users/paulvanbrenk/gists{/gist_id}","starred_url":"https://api.github.com/users/paulvanbrenk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulvanbrenk/subscriptions","organizations_url":"https://api.github.com/users/paulvanbrenk/orgs","repos_url":"https://api.github.com/users/paulvanbrenk/repos","events_url":"https://api.github.com/users/paulvanbrenk/events{/privacy}","received_events_url":"https://api.github.com/users/paulvanbrenk/received_events","type":"User","site_admin":false},"body":"Implement codefix for adding missing imports.\n\nPing @riknoll \n","created_at":"2016-10-20T23:48:23Z","updated_at":"2016-11-04T00:33:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6812b7b4036abda9752345402ebcded3454353c8","assignee":{"login":"zhengbli","id":1171301,"avatar_url":"https://avatars.githubusercontent.com/u/1171301?v=3","gravatar_id":"","url":"https://api.github.com/users/zhengbli","html_url":"https://github.com/zhengbli","followers_url":"https://api.github.com/users/zhengbli/followers","following_url":"https://api.github.com/users/zhengbli/following{/other_user}","gists_url":"https://api.github.com/users/zhengbli/gists{/gist_id}","starred_url":"https://api.github.com/users/zhengbli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhengbli/subscriptions","organizations_url":"https://api.github.com/users/zhengbli/orgs","repos_url":"https://api.github.com/users/zhengbli/repos","events_url":"https://api.github.com/users/zhengbli/events{/privacy}","received_events_url":"https://api.github.com/users/zhengbli/received_events","type":"User","site_admin":false},"assignees":[{"login":"zhengbli","id":1171301,"avatar_url":"https://avatars.githubusercontent.com/u/1171301?v=3","gravatar_id":"","url":"https://api.github.com/users/zhengbli","html_url":"https://github.com/zhengbli","followers_url":"https://api.github.com/users/zhengbli/followers","following_url":"https://api.github.com/users/zhengbli/following{/other_user}","gists_url":"https://api.github.com/users/zhengbli/gists{/gist_id}","starred_url":"https://api.github.com/users/zhengbli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhengbli/subscriptions","organizations_url":"https://api.github.com/users/zhengbli/orgs","repos_url":"https://api.github.com/users/zhengbli/repos","events_url":"https://api.github.com/users/zhengbli/events{/privacy}","received_events_url":"https://api.github.com/users/zhengbli/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11768/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/1502f75c515d9704989d1e56ef28689e8cfcbb3f","head":{"label":"Microsoft:pvb/fixmissingimports","ref":"pvb/fixmissingimports","sha":"1502f75c515d9704989d1e56ef28689e8cfcbb3f","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript/deployments","created_at":"2014-06-17T15:28:39Z","updated_at":"2016-11-04T00:24:17Z","pushed_at":"2016-11-04T00:25:54Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":599658,"stargazers_count":16401,"watchers_count":16401,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2246,"mirror_url":null,"open_issues_count":1508,"forks":2246,"open_issues":1508,"watchers":16401,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"ab75ea75d337d82138083c52caea7419f3b20929","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript/deployments","created_at":"2014-06-17T15:28:39Z","updated_at":"2016-11-04T00:24:17Z","pushed_at":"2016-11-04T00:25:54Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":599658,"stargazers_count":16401,"watchers_count":16401,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2246,"mirror_url":null,"open_issues_count":1508,"forks":2246,"open_issues":1508,"watchers":16401,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/11768"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/11768"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/11768/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/11768/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/1502f75c515d9704989d1e56ef28689e8cfcbb3f"}}}}
{"actor":{"display_login":"mhegazy"}}