{"action":"created","comment":{"url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/comments/173504656","pull_request_review_id":102706364,"id":173504656,"diff_hunk":"@@ -0,0 +1,95 @@\n+package org.scalafmt.internal\n+\n+import scala.meta._\n+import scala.meta.Token\n+import scala.meta.tokens.Token._\n+\n+object SyntaxTokens {\n+  private implicit class Util[A <: Tree](val tree: A) extends AnyVal {\n+    def findAfter(f: Token => Boolean, p: A => Tree): Option[Token] = {\n+      val end = p(tree).tokens.last\n+      tree.tokens.dropWhile(_ != end).drop(1).find(f)\n+    }\n+  }\n+  implicit class TermAssignSyntax(val tree: Term.Assign) extends AnyVal {\n+    def `=` : Token = tree.findAfter(_.is[Equals], _.lhs).get\n+  }\n+\n+  implicit class TermThisSyntax(val tree: Term.This) extends AnyVal {\n+    def `.` : Option[Token] = {\n+      tree.qual match {\n+        case _: Name.Anonymous => None\n+        case _ => tree.findAfter(_.is[Dot], _.qual)\n+      }\n+    }\n+  }\n+  implicit class TermSuperSyntax(val tree: Term.Super) extends AnyVal {\n+    def `.` : Option[Token] = {\n+      tree.thisp match {\n+        case _: Name.Anonymous => None\n+        case _ => tree.tokens.find(_.is[Dot])\n+      }\n+    }\n+  }\n+  implicit class TermSelectSyntax(val tree: Term.Select) extends AnyVal {\n+    def `.` : Token = tree.findAfter(_.is[Dot], _.qual).get\n+  }\n+  implicit class TermInterpolate(val tree: Term.Interpolate) extends AnyVal {\n+    def startQuote: Token = tree.tokens.find(_.is[Interpolation.Start]).get\n+    def endQuote: Token = tree.tokens.find(_.is[Interpolation.End]).get\n+  }\n+\n+  implicit class TermReturn(val tree: Term.Return) extends AnyVal {\n+    def `return`: Token = tree.tokens.find(_.is[KwReturn]).get","path":"format/src/main/scala/org/scalafmt/internal/SyntaxTokens.scala","position":43,"original_position":43,"commit_id":"21144c60f3ee21d3aceee28199933d28a5c51451","original_commit_id":"21144c60f3ee21d3aceee28199933d28a5c51451","user":{"login":"olafurpg","id":1408093,"avatar_url":"https://avatars0.githubusercontent.com/u/1408093?v=4","gravatar_id":"","url":"https://api.github.com/users/olafurpg","html_url":"https://github.com/olafurpg","followers_url":"https://api.github.com/users/olafurpg/followers","following_url":"https://api.github.com/users/olafurpg/following{/other_user}","gists_url":"https://api.github.com/users/olafurpg/gists{/gist_id}","starred_url":"https://api.github.com/users/olafurpg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olafurpg/subscriptions","organizations_url":"https://api.github.com/users/olafurpg/orgs","repos_url":"https://api.github.com/users/olafurpg/repos","events_url":"https://api.github.com/users/olafurpg/events{/privacy}","received_events_url":"https://api.github.com/users/olafurpg/received_events","type":"User","site_admin":false},"body":"`tokensReturn: Token.KwReturn`","created_at":"2018-03-09T16:48:57Z","updated_at":"2018-03-09T17:00:23Z","html_url":"https://github.com/scalacenter/scala-syntax/pull/31#discussion_r173504656","pull_request_url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/comments/173504656"},"html":{"href":"https://github.com/scalacenter/scala-syntax/pull/31#discussion_r173504656"},"pull_request":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31","id":174047713,"html_url":"https://github.com/scalacenter/scala-syntax/pull/31","diff_url":"https://github.com/scalacenter/scala-syntax/pull/31.diff","patch_url":"https://github.com/scalacenter/scala-syntax/pull/31.patch","issue_url":"https://api.github.com/repos/scalacenter/scala-syntax/issues/31","number":31,"state":"open","locked":false,"title":"Comments property","user":{"login":"MasseGuillaume","id":921490,"avatar_url":"https://avatars2.githubusercontent.com/u/921490?v=4","gravatar_id":"","url":"https://api.github.com/users/MasseGuillaume","html_url":"https://github.com/MasseGuillaume","followers_url":"https://api.github.com/users/MasseGuillaume/followers","following_url":"https://api.github.com/users/MasseGuillaume/following{/other_user}","gists_url":"https://api.github.com/users/MasseGuillaume/gists{/gist_id}","starred_url":"https://api.github.com/users/MasseGuillaume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MasseGuillaume/subscriptions","organizations_url":"https://api.github.com/users/MasseGuillaume/orgs","repos_url":"https://api.github.com/users/MasseGuillaume/repos","events_url":"https://api.github.com/users/MasseGuillaume/events{/privacy}","received_events_url":"https://api.github.com/users/MasseGuillaume/received_events","type":"User","site_admin":false},"body":"We want to add support for comments. Our current strategy is the following:\r\n\r\nFind the associated comment from the tree root. This gives us a way to retrieve leading and trailing comments from a Token. When we print the tree, recursively (in TreePrinter), we query tokens from the tree. For example for if:\r\n\r\n```scala\r\ncase t: Term.If =>\r\n  def body(expr: Term) = expr match {\r\n    case b: Term.Block => space + dBlock(b.stats)\r\n    case _: Term.If => space + print(expr)\r\n    case _ => (line + print(expr)).nested(2)\r\n  }\r\n  val delse =\r\n    if (t.elsep.tokens.isEmpty) empty\r\n    else line + t.`else` + body(t.elsep)\r\n\r\n  (\r\n    t.`if` + space + t.`(` + print(t.cond) + t.`)` +\r\n    body(t.thenp) +\r\n    delse\r\n\r\n  ).grouped\r\n```\r\n","created_at":"2018-03-09T16:24:59Z","updated_at":"2018-03-09T17:00:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d034964b634bbaf2a1c5004d4c811e5ff252d1c7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31/commits","review_comments_url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31/comments","review_comment_url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scalacenter/scala-syntax/issues/31/comments","statuses_url":"https://api.github.com/repos/scalacenter/scala-syntax/statuses/21144c60f3ee21d3aceee28199933d28a5c51451","head":{"label":"MasseGuillaume:comments-property","ref":"comments-property","sha":"21144c60f3ee21d3aceee28199933d28a5c51451","user":{"login":"MasseGuillaume","id":921490,"avatar_url":"https://avatars2.githubusercontent.com/u/921490?v=4","gravatar_id":"","url":"https://api.github.com/users/MasseGuillaume","html_url":"https://github.com/MasseGuillaume","followers_url":"https://api.github.com/users/MasseGuillaume/followers","following_url":"https://api.github.com/users/MasseGuillaume/following{/other_user}","gists_url":"https://api.github.com/users/MasseGuillaume/gists{/gist_id}","starred_url":"https://api.github.com/users/MasseGuillaume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MasseGuillaume/subscriptions","organizations_url":"https://api.github.com/users/MasseGuillaume/orgs","repos_url":"https://api.github.com/users/MasseGuillaume/repos","events_url":"https://api.github.com/users/MasseGuillaume/events{/privacy}","received_events_url":"https://api.github.com/users/MasseGuillaume/received_events","type":"User","site_admin":false},"repo":{"id":121634306,"name":"scala-syntax","full_name":"MasseGuillaume/scala-syntax","owner":{"login":"MasseGuillaume","id":921490,"avatar_url":"https://avatars2.githubusercontent.com/u/921490?v=4","gravatar_id":"","url":"https://api.github.com/users/MasseGuillaume","html_url":"https://github.com/MasseGuillaume","followers_url":"https://api.github.com/users/MasseGuillaume/followers","following_url":"https://api.github.com/users/MasseGuillaume/following{/other_user}","gists_url":"https://api.github.com/users/MasseGuillaume/gists{/gist_id}","starred_url":"https://api.github.com/users/MasseGuillaume/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MasseGuillaume/subscriptions","organizations_url":"https://api.github.com/users/MasseGuillaume/orgs","repos_url":"https://api.github.com/users/MasseGuillaume/repos","events_url":"https://api.github.com/users/MasseGuillaume/events{/privacy}","received_events_url":"https://api.github.com/users/MasseGuillaume/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MasseGuillaume/scala-syntax","description":null,"fork":true,"url":"https://api.github.com/repos/MasseGuillaume/scala-syntax","forks_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/forks","keys_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/teams","hooks_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/hooks","issue_events_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/issues/events{/number}","events_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/events","assignees_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/assignees{/user}","branches_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/branches{/branch}","tags_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/tags","blobs_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/git/refs{/sha}","trees_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/statuses/{sha}","languages_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/languages","stargazers_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/stargazers","contributors_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/contributors","subscribers_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/subscribers","subscription_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/subscription","commits_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/commits{/sha}","git_commits_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/git/commits{/sha}","comments_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/comments{/number}","issue_comment_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/issues/comments{/number}","contents_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/contents/{+path}","compare_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/merges","archive_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/downloads","issues_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/issues{/number}","pulls_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/pulls{/number}","milestones_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/milestones{/number}","notifications_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/labels{/name}","releases_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/releases{/id}","deployments_url":"https://api.github.com/repos/MasseGuillaume/scala-syntax/deployments","created_at":"2018-02-15T13:42:07Z","updated_at":"2018-02-15T13:42:09Z","pushed_at":"2018-03-09T16:37:56Z","git_url":"git://github.com/MasseGuillaume/scala-syntax.git","ssh_url":"git@github.com:MasseGuillaume/scala-syntax.git","clone_url":"https://github.com/MasseGuillaume/scala-syntax.git","svn_url":"https://github.com/MasseGuillaume/scala-syntax","homepage":null,"size":287,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scalacenter:master","ref":"master","sha":"84457fd595024ed553febf152a0d180bd17ab8da","user":{"login":"scalacenter","id":16118980,"avatar_url":"https://avatars2.githubusercontent.com/u/16118980?v=4","gravatar_id":"","url":"https://api.github.com/users/scalacenter","html_url":"https://github.com/scalacenter","followers_url":"https://api.github.com/users/scalacenter/followers","following_url":"https://api.github.com/users/scalacenter/following{/other_user}","gists_url":"https://api.github.com/users/scalacenter/gists{/gist_id}","starred_url":"https://api.github.com/users/scalacenter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalacenter/subscriptions","organizations_url":"https://api.github.com/users/scalacenter/orgs","repos_url":"https://api.github.com/users/scalacenter/repos","events_url":"https://api.github.com/users/scalacenter/events{/privacy}","received_events_url":"https://api.github.com/users/scalacenter/received_events","type":"Organization","site_admin":false},"repo":{"id":105354469,"name":"scala-syntax","full_name":"scalacenter/scala-syntax","owner":{"login":"scalacenter","id":16118980,"avatar_url":"https://avatars2.githubusercontent.com/u/16118980?v=4","gravatar_id":"","url":"https://api.github.com/users/scalacenter","html_url":"https://github.com/scalacenter","followers_url":"https://api.github.com/users/scalacenter/followers","following_url":"https://api.github.com/users/scalacenter/following{/other_user}","gists_url":"https://api.github.com/users/scalacenter/gists{/gist_id}","starred_url":"https://api.github.com/users/scalacenter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalacenter/subscriptions","organizations_url":"https://api.github.com/users/scalacenter/orgs","repos_url":"https://api.github.com/users/scalacenter/repos","events_url":"https://api.github.com/users/scalacenter/events{/privacy}","received_events_url":"https://api.github.com/users/scalacenter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scalacenter/scala-syntax","description":"Scalameta pretty printer for better Scalafix refactorings","fork":false,"url":"https://api.github.com/repos/scalacenter/scala-syntax","forks_url":"https://api.github.com/repos/scalacenter/scala-syntax/forks","keys_url":"https://api.github.com/repos/scalacenter/scala-syntax/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scalacenter/scala-syntax/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scalacenter/scala-syntax/teams","hooks_url":"https://api.github.com/repos/scalacenter/scala-syntax/hooks","issue_events_url":"https://api.github.com/repos/scalacenter/scala-syntax/issues/events{/number}","events_url":"https://api.github.com/repos/scalacenter/scala-syntax/events","assignees_url":"https://api.github.com/repos/scalacenter/scala-syntax/assignees{/user}","branches_url":"https://api.github.com/repos/scalacenter/scala-syntax/branches{/branch}","tags_url":"https://api.github.com/repos/scalacenter/scala-syntax/tags","blobs_url":"https://api.github.com/repos/scalacenter/scala-syntax/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scalacenter/scala-syntax/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scalacenter/scala-syntax/git/refs{/sha}","trees_url":"https://api.github.com/repos/scalacenter/scala-syntax/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scalacenter/scala-syntax/statuses/{sha}","languages_url":"https://api.github.com/repos/scalacenter/scala-syntax/languages","stargazers_url":"https://api.github.com/repos/scalacenter/scala-syntax/stargazers","contributors_url":"https://api.github.com/repos/scalacenter/scala-syntax/contributors","subscribers_url":"https://api.github.com/repos/scalacenter/scala-syntax/subscribers","subscription_url":"https://api.github.com/repos/scalacenter/scala-syntax/subscription","commits_url":"https://api.github.com/repos/scalacenter/scala-syntax/commits{/sha}","git_commits_url":"https://api.github.com/repos/scalacenter/scala-syntax/git/commits{/sha}","comments_url":"https://api.github.com/repos/scalacenter/scala-syntax/comments{/number}","issue_comment_url":"https://api.github.com/repos/scalacenter/scala-syntax/issues/comments{/number}","contents_url":"https://api.github.com/repos/scalacenter/scala-syntax/contents/{+path}","compare_url":"https://api.github.com/repos/scalacenter/scala-syntax/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scalacenter/scala-syntax/merges","archive_url":"https://api.github.com/repos/scalacenter/scala-syntax/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scalacenter/scala-syntax/downloads","issues_url":"https://api.github.com/repos/scalacenter/scala-syntax/issues{/number}","pulls_url":"https://api.github.com/repos/scalacenter/scala-syntax/pulls{/number}","milestones_url":"https://api.github.com/repos/scalacenter/scala-syntax/milestones{/number}","notifications_url":"https://api.github.com/repos/scalacenter/scala-syntax/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scalacenter/scala-syntax/labels{/name}","releases_url":"https://api.github.com/repos/scalacenter/scala-syntax/releases{/id}","deployments_url":"https://api.github.com/repos/scalacenter/scala-syntax/deployments","created_at":"2017-09-30T08:18:47Z","updated_at":"2018-02-28T11:14:06Z","pushed_at":"2018-03-09T16:37:57Z","git_url":"git://github.com/scalacenter/scala-syntax.git","ssh_url":"git@github.com:scalacenter/scala-syntax.git","clone_url":"https://github.com/scalacenter/scala-syntax.git","svn_url":"https://github.com/scalacenter/scala-syntax","homepage":"","size":221,"stargazers_count":4,"watchers_count":4,"language":"Scala","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":3,"open_issues":3,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31"},"html":{"href":"https://github.com/scalacenter/scala-syntax/pull/31"},"issue":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/issues/31"},"comments":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/scalacenter/scala-syntax/statuses/21144c60f3ee21d3aceee28199933d28a5c51451"}},"author_association":"OWNER"}}
{"actor":{"display_login":"olafurpg"}}