GitHub PullRequestReviewCommentEvent at 2014-09-15 20:36:01
Repository: TypeScript
Actor: JsonFreeman
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/17566960","id":17566960,"diff_hunk":"@@ -0,0 +1,517 @@\n+///<reference path='..\\services.ts' />\r\n+\r\n+module ts.formatting {\r\n+    export module SmartIndenter {\r\n+\r\n+        export function getIndentation(position: number, sourceFile: SourceFile, options: TypeScript.FormattingOptions): number {\r\n+            if (position > sourceFile.text.length) {\r\n+                return 0; // past EOF\r\n+            }\r\n+\r\n+            var precedingToken = findPrecedingToken(position, sourceFile);\r\n+            if (!precedingToken) {\r\n+                return 0;\r\n+            }\r\n+\r\n+            // no indentation in string \\regex literals\r\n+            if ((precedingToken.kind === SyntaxKind.StringLiteral || precedingToken.kind === SyntaxKind.RegularExpressionLiteral) && \r\n+                precedingToken.getStart(sourceFile) <= position && \r\n+                precedingToken.end > position) {\r\n+                return 0;\r\n+            }\r\n+\r\n+            var lineAtPosition = sourceFile.getLineAndCharacterFromPosition(position).line;\r\n+\r\n+            if (precedingToken.kind === SyntaxKind.CommaToken && precedingToken.parent.kind !== SyntaxKind.BinaryExpression) {\r\n+                // previous token is comma that separates items in list - find the previous item and try to derive indentation from it\r\n+                var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options);\r\n+                if (actualIndentation !== -1) {\r\n+                    return actualIndentation;\r\n+                }\r\n+            }\r\n+\r\n+            // try to find node that can contribute to indentation and includes 'position' starting from 'precedingToken'\r\n+            // if such node is found - compute initial indentation for 'position' inside this node\r\n+            var previous: Node;\r\n+            var current = precedingToken;\r\n+            var currentStart: LineAndCharacter;\r\n+            var indentation: number;\r\n+\r\n+            while (current) {\r\n+                if (positionBelongsToNode(current, position, sourceFile) && nodeContentIsIndented(current, previous)) {\r\n+                    currentStart = getStartLineAndCharacterForNode(current, sourceFile);\r\n+\r\n+                    if (discardInitialIndentationIfNextTokenIsOpenOrCloseBrace(precedingToken, current, lineAtPosition, sourceFile)) {\r\n+                        indentation = 0;\r\n+                    }\r\n+                    else {\r\n+                        indentation = lineAtPosition !== currentStart.line ? options.indentSpaces : 0;\r\n+                    }\r\n+\r\n+                    break;\r\n+                }\r\n+\r\n+                // check if current node is a list item - if yes, take indentation from it\r\n+                var actualIndentation = getActualIndentationForListItem(current, sourceFile, options);\r\n+                if (actualIndentation !== -1) {\r\n+                    return actualIndentation;\r\n+                }\r\n+\r\n+                previous = current;\r\n+                current = current.parent;\r\n+            }\r\n+                        \r\n+            if (!current) {\r\n+                // no parent was found - return 0 to be indented on the level of SourceFile\r\n+                return 0;\r\n+            }\r\n+\r\n+\r\n+            var parent: Node = current.parent;\r\n+            var parentStart: LineAndCharacter;\r\n+\r\n+            // walk upwards and collect indentations for pairs of parent-child nodes\r\n+            // indentation is not added if parent and child nodes start on the same line or if parent is IfStatement and child starts on the same line with 'else clause'\r\n+            while (parent) {\r\n+\r\n+                // check if current node is a list item - if yes, take indentation from it\r\n+                var actualIndentation = getActualIndentationForListItem(current, sourceFile, options);\r\n+                if (actualIndentation !== -1) {\r\n+                    return actualIndentation + indentation;\r\n+                }\r\n+\r\n+                parentStart = sourceFile.getLineAndCharacterFromPosition(parent.getStart(sourceFile));\r\n+                var parentAndChildShareLine = \r\n+                    parentStart.line === currentStart.line || \r\n+                    childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile);\r\n+\r\n+                // try to fetch actual indentation for current node from source text\r\n+                var actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options);\r\n+                if (actualIndentation !== -1) {\r\n+                    return actualIndentation + indentation;\r\n+                }\r\n+\r\n+                // increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line\r\n+                var increaseIndentation = nodeContentIsIndented(parent, current) && !parentAndChildShareLine;\r\n+\r\n+                if (increaseIndentation) {\r\n+                    indentation += options.indentSpaces;\r\n+                }\r\n+\r\n+                current = parent;\r\n+                currentStart = parentStart;\r\n+                parent = current.parent;\r\n+            }\r\n+\r\n+            return indentation;\r\n+        }\r\n+\r\n+        function isStatement(n: Node): boolean {\r","path":"src/services/formatting/smartIndenter.ts","position":109,"original_position":109,"commit_id":"685d131f4a2eb1924e2eadb602b79658120e94ad","original_commit_id":"685d131f4a2eb1924e2eadb602b79658120e94ad","user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=2","gravatar_id":"861d215ba1bf64bf4d78bd15dd9dfd30","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"body":"Actually, maybe the SyntaxKind enum should have a range for it","created_at":"2014-09-15T20:36:01Z","updated_at":"2014-09-15T20:36:01Z","html_url":"https://github.com/Microsoft/TypeScript/pull/671#discussion_r17566960","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/17566960"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/671#discussion_r17566960"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671","id":21185134,"html_url":"https://github.com/Microsoft/TypeScript/pull/671","diff_url":"https://github.com/Microsoft/TypeScript/pull/671.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/671.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/671","number":671,"state":"open","locked":false,"title":"LS: smart indentation","user":{"login":"vladima","id":8052307,"avatar_url":"https://avatars.githubusercontent.com/u/8052307?v=2","gravatar_id":"5aee15af22b78f239d28323e4194ca43","url":"https://api.github.com/users/vladima","html_url":"https://github.com/vladima","followers_url":"https://api.github.com/users/vladima/followers","following_url":"https://api.github.com/users/vladima/following{/other_user}","gists_url":"https://api.github.com/users/vladima/gists{/gist_id}","starred_url":"https://api.github.com/users/vladima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladima/subscriptions","organizations_url":"https://api.github.com/users/vladima/orgs","repos_url":"https://api.github.com/users/vladima/repos","events_url":"https://api.github.com/users/vladima/events{/privacy}","received_events_url":"https://api.github.com/users/vladima/received_events","type":"User","site_admin":false},"body":"Implementation of smart indentation that uses new syntax trees","created_at":"2014-09-12T23:22:35Z","updated_at":"2014-09-15T20:36:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d814945a675cbe425c05571ac1b4aa25b1549f2e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/671/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/685d131f4a2eb1924e2eadb602b79658120e94ad","head":{"label":"Microsoft:new_smart_indentation","ref":"new_smart_indentation","sha":"685d131f4a2eb1924e2eadb602b79658120e94ad","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=2","gravatar_id":"7d3b0469b6f73dd41ed7de7931e44510","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=2","gravatar_id":"7d3b0469b6f73dd41ed7de7931e44510","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}","created_at":"2014-06-17T15:28:39Z","updated_at":"2014-09-15T17:17:36Z","pushed_at":"2014-09-15T20:01:44Z","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":88388,"stargazers_count":2106,"watchers_count":2106,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":153,"mirror_url":null,"open_issues_count":196,"forks":153,"open_issues":196,"watchers":2106,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"b9ebb367c042132451e1d9c226f343fbb3e3e978","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=2","gravatar_id":"7d3b0469b6f73dd41ed7de7931e44510","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=2","gravatar_id":"7d3b0469b6f73dd41ed7de7931e44510","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}","created_at":"2014-06-17T15:28:39Z","updated_at":"2014-09-15T17:17:36Z","pushed_at":"2014-09-15T20:01:44Z","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":88388,"stargazers_count":2106,"watchers_count":2106,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":153,"mirror_url":null,"open_issues_count":196,"forks":153,"open_issues":196,"watchers":2106,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/671"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/671"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/671/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/671/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/685d131f4a2eb1924e2eadb602b79658120e94ad"}}}}