{"action":"created","comment":{"url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/comments/229541097","pull_request_review_id":170065466,"id":229541097,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTU0MTA5Nw==","diff_hunk":"@@ -72,18 +71,63 @@ class RsImportOptimizer : ImportOptimizer {\n             val first = mod.childrenOfType<RsElement>()\n                 .firstOrNull { it.textOffset >= offset && it !is RsExternCrateItem && it !is RsAttr } ?: return\n             val psiFactory = RsPsiFactory(mod.project)\n-            val sortedUses = uses\n-                .sortedBy { it.useSpeck?.pathText }\n-                .mapNotNull { it.copy() as? RsUseItem }\n-            sortedUses\n-                .mapNotNull { it.useSpeck }\n-                .forEach { optimizeUseSpeck(psiFactory, it) }\n-            for (importPath in sortedUses) {\n-                mod.addBefore(importPath, first)\n+            val sortedUsesGroups = uses\n+                .map { UseItemWrapper(it) }\n+                .groupBy({ it.packageGroupLevel }, { it })\n+                .map { (groupLevel, useItemWrapper) ->\n+                    groupLevel to useItemWrapper\n+                        .sortedBy { it.useSpeckText }\n+                        .mapNotNull { it.useItem.copy() as? RsUseItem }\n+                }\n+                .filter { it.second.isNotEmpty() }\n+                .sortedBy { it.first }\n+            sortedUsesGroups.forEach { sortedUses ->\n+                sortedUses.second\n+                    .mapNotNull { it.useSpeck }\n+                    .forEach { optimizeUseSpeck(psiFactory, it) }\n+            }\n+\n+            for ((_, sortedUses) in sortedUsesGroups) {\n+                val lastUseItem = sortedUses.map { importPath ->\n+                    val addedUseItem = mod.addBefore(importPath, first)\n+                    mod.addAfter(psiFactory.createNewline(), addedUseItem)","path":"src/main/kotlin/org/rust/lang/refactoring/RsImportOptimizer.kt","position":47,"original_position":47,"commit_id":"ce89a6cb41477c480edf0dfdb2d9285fc394084e","original_commit_id":"ce89a6cb41477c480edf0dfdb2d9285fc394084e","user":{"login":"isamborskiy","id":2528429,"node_id":"MDQ6VXNlcjI1Mjg0Mjk=","avatar_url":"https://avatars0.githubusercontent.com/u/2528429?v=4","gravatar_id":"","url":"https://api.github.com/users/isamborskiy","html_url":"https://github.com/isamborskiy","followers_url":"https://api.github.com/users/isamborskiy/followers","following_url":"https://api.github.com/users/isamborskiy/following{/other_user}","gists_url":"https://api.github.com/users/isamborskiy/gists{/gist_id}","starred_url":"https://api.github.com/users/isamborskiy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isamborskiy/subscriptions","organizations_url":"https://api.github.com/users/isamborskiy/orgs","repos_url":"https://api.github.com/users/isamborskiy/repos","events_url":"https://api.github.com/users/isamborskiy/events{/privacy}","received_events_url":"https://api.github.com/users/isamborskiy/received_events","type":"User","site_admin":false},"body":"Yes, this is true.\r\nHowever, I find the current version more logical. \r\nYou do not think so, do you?","created_at":"2018-10-31T01:38:38Z","updated_at":"2018-10-31T01:38:38Z","html_url":"https://github.com/intellij-rust/intellij-rust/pull/2990#discussion_r229541097","pull_request_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/comments/229541097"},"html":{"href":"https://github.com/intellij-rust/intellij-rust/pull/2990#discussion_r229541097"},"pull_request":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990"}},"in_reply_to_id":229534694},"pull_request":{"url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990","id":226281415,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI2MjgxNDE1","html_url":"https://github.com/intellij-rust/intellij-rust/pull/2990","diff_url":"https://github.com/intellij-rust/intellij-rust/pull/2990.diff","patch_url":"https://github.com/intellij-rust/intellij-rust/pull/2990.patch","issue_url":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/2990","number":2990,"state":"open","locked":false,"title":"ACT: add ability to group imports by semantics for import optimizer","user":{"login":"isamborskiy","id":2528429,"node_id":"MDQ6VXNlcjI1Mjg0Mjk=","avatar_url":"https://avatars0.githubusercontent.com/u/2528429?v=4","gravatar_id":"","url":"https://api.github.com/users/isamborskiy","html_url":"https://github.com/isamborskiy","followers_url":"https://api.github.com/users/isamborskiy/followers","following_url":"https://api.github.com/users/isamborskiy/following{/other_user}","gists_url":"https://api.github.com/users/isamborskiy/gists{/gist_id}","starred_url":"https://api.github.com/users/isamborskiy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isamborskiy/subscriptions","organizations_url":"https://api.github.com/users/isamborskiy/orgs","repos_url":"https://api.github.com/users/isamborskiy/repos","events_url":"https://api.github.com/users/isamborskiy/events{/privacy}","received_events_url":"https://api.github.com/users/isamborskiy/received_events","type":"User","site_admin":false},"body":"Fulfilled #2259 improvement (the last checkbox).\r\n\r\nAdd the ability to group imports by semantics (std, crates, inner mods, etc.)\r\nGroups order: [here](https://github.com/isamborskiy/intellij-rust/blob/ce89a6cb41477c480edf0dfdb2d9285fc394084e/src/main/kotlin/org/rust/lang/refactoring/RsImportOptimizer.kt#L113)\r\nExamples: [here](https://github.com/isamborskiy/intellij-rust/blob/ce89a6cb41477c480edf0dfdb2d9285fc394084e/src/test/kotlin/org/rust/lang/refactoring/RsImportOptimizerTest.kt#L293) and [here](https://github.com/isamborskiy/intellij-rust/blob/ce89a6cb41477c480edf0dfdb2d9285fc394084e/src/test/kotlin/org/rust/lang/refactoring/RsImportOptimizerTest.kt#L317)\r\n","created_at":"2018-10-27T09:18:25Z","updated_at":"2018-10-31T01:38:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ebdcb6262fbc81001b42f3666ca828de0f6e4c8","assignee":{"login":"Undin","id":2539310,"node_id":"MDQ6VXNlcjI1MzkzMTA=","avatar_url":"https://avatars0.githubusercontent.com/u/2539310?v=4","gravatar_id":"","url":"https://api.github.com/users/Undin","html_url":"https://github.com/Undin","followers_url":"https://api.github.com/users/Undin/followers","following_url":"https://api.github.com/users/Undin/following{/other_user}","gists_url":"https://api.github.com/users/Undin/gists{/gist_id}","starred_url":"https://api.github.com/users/Undin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Undin/subscriptions","organizations_url":"https://api.github.com/users/Undin/orgs","repos_url":"https://api.github.com/users/Undin/repos","events_url":"https://api.github.com/users/Undin/events{/privacy}","received_events_url":"https://api.github.com/users/Undin/received_events","type":"User","site_admin":false},"assignees":[{"login":"Undin","id":2539310,"node_id":"MDQ6VXNlcjI1MzkzMTA=","avatar_url":"https://avatars0.githubusercontent.com/u/2539310?v=4","gravatar_id":"","url":"https://api.github.com/users/Undin","html_url":"https://github.com/Undin","followers_url":"https://api.github.com/users/Undin/followers","following_url":"https://api.github.com/users/Undin/following{/other_user}","gists_url":"https://api.github.com/users/Undin/gists{/gist_id}","starred_url":"https://api.github.com/users/Undin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Undin/subscriptions","organizations_url":"https://api.github.com/users/Undin/orgs","repos_url":"https://api.github.com/users/Undin/repos","events_url":"https://api.github.com/users/Undin/events{/privacy}","received_events_url":"https://api.github.com/users/Undin/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990/commits","review_comments_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990/comments","review_comment_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/2990/comments","statuses_url":"https://api.github.com/repos/intellij-rust/intellij-rust/statuses/ce89a6cb41477c480edf0dfdb2d9285fc394084e","head":{"label":"isamborskiy:group-imports","ref":"group-imports","sha":"ce89a6cb41477c480edf0dfdb2d9285fc394084e","user":{"login":"isamborskiy","id":2528429,"node_id":"MDQ6VXNlcjI1Mjg0Mjk=","avatar_url":"https://avatars0.githubusercontent.com/u/2528429?v=4","gravatar_id":"","url":"https://api.github.com/users/isamborskiy","html_url":"https://github.com/isamborskiy","followers_url":"https://api.github.com/users/isamborskiy/followers","following_url":"https://api.github.com/users/isamborskiy/following{/other_user}","gists_url":"https://api.github.com/users/isamborskiy/gists{/gist_id}","starred_url":"https://api.github.com/users/isamborskiy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isamborskiy/subscriptions","organizations_url":"https://api.github.com/users/isamborskiy/orgs","repos_url":"https://api.github.com/users/isamborskiy/repos","events_url":"https://api.github.com/users/isamborskiy/events{/privacy}","received_events_url":"https://api.github.com/users/isamborskiy/received_events","type":"User","site_admin":false},"repo":{"id":115338041,"node_id":"MDEwOlJlcG9zaXRvcnkxMTUzMzgwNDE=","name":"intellij-rust","full_name":"isamborskiy/intellij-rust","private":false,"owner":{"login":"isamborskiy","id":2528429,"node_id":"MDQ6VXNlcjI1Mjg0Mjk=","avatar_url":"https://avatars0.githubusercontent.com/u/2528429?v=4","gravatar_id":"","url":"https://api.github.com/users/isamborskiy","html_url":"https://github.com/isamborskiy","followers_url":"https://api.github.com/users/isamborskiy/followers","following_url":"https://api.github.com/users/isamborskiy/following{/other_user}","gists_url":"https://api.github.com/users/isamborskiy/gists{/gist_id}","starred_url":"https://api.github.com/users/isamborskiy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isamborskiy/subscriptions","organizations_url":"https://api.github.com/users/isamborskiy/orgs","repos_url":"https://api.github.com/users/isamborskiy/repos","events_url":"https://api.github.com/users/isamborskiy/events{/privacy}","received_events_url":"https://api.github.com/users/isamborskiy/received_events","type":"User","site_admin":false},"html_url":"https://github.com/isamborskiy/intellij-rust","description":"Rust plugin for the IntelliJ Platform: https://intellij-rust.github.io/","fork":true,"url":"https://api.github.com/repos/isamborskiy/intellij-rust","forks_url":"https://api.github.com/repos/isamborskiy/intellij-rust/forks","keys_url":"https://api.github.com/repos/isamborskiy/intellij-rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/isamborskiy/intellij-rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/isamborskiy/intellij-rust/teams","hooks_url":"https://api.github.com/repos/isamborskiy/intellij-rust/hooks","issue_events_url":"https://api.github.com/repos/isamborskiy/intellij-rust/issues/events{/number}","events_url":"https://api.github.com/repos/isamborskiy/intellij-rust/events","assignees_url":"https://api.github.com/repos/isamborskiy/intellij-rust/assignees{/user}","branches_url":"https://api.github.com/repos/isamborskiy/intellij-rust/branches{/branch}","tags_url":"https://api.github.com/repos/isamborskiy/intellij-rust/tags","blobs_url":"https://api.github.com/repos/isamborskiy/intellij-rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/isamborskiy/intellij-rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/isamborskiy/intellij-rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/isamborskiy/intellij-rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/isamborskiy/intellij-rust/statuses/{sha}","languages_url":"https://api.github.com/repos/isamborskiy/intellij-rust/languages","stargazers_url":"https://api.github.com/repos/isamborskiy/intellij-rust/stargazers","contributors_url":"https://api.github.com/repos/isamborskiy/intellij-rust/contributors","subscribers_url":"https://api.github.com/repos/isamborskiy/intellij-rust/subscribers","subscription_url":"https://api.github.com/repos/isamborskiy/intellij-rust/subscription","commits_url":"https://api.github.com/repos/isamborskiy/intellij-rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/isamborskiy/intellij-rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/isamborskiy/intellij-rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/isamborskiy/intellij-rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/isamborskiy/intellij-rust/contents/{+path}","compare_url":"https://api.github.com/repos/isamborskiy/intellij-rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/isamborskiy/intellij-rust/merges","archive_url":"https://api.github.com/repos/isamborskiy/intellij-rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/isamborskiy/intellij-rust/downloads","issues_url":"https://api.github.com/repos/isamborskiy/intellij-rust/issues{/number}","pulls_url":"https://api.github.com/repos/isamborskiy/intellij-rust/pulls{/number}","milestones_url":"https://api.github.com/repos/isamborskiy/intellij-rust/milestones{/number}","notifications_url":"https://api.github.com/repos/isamborskiy/intellij-rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/isamborskiy/intellij-rust/labels{/name}","releases_url":"https://api.github.com/repos/isamborskiy/intellij-rust/releases{/id}","deployments_url":"https://api.github.com/repos/isamborskiy/intellij-rust/deployments","created_at":"2017-12-25T12:56:31Z","updated_at":"2018-10-27T07:55:25Z","pushed_at":"2018-10-27T09:08:22Z","git_url":"git://github.com/isamborskiy/intellij-rust.git","ssh_url":"git@github.com:isamborskiy/intellij-rust.git","clone_url":"https://github.com/isamborskiy/intellij-rust.git","svn_url":"https://github.com/isamborskiy/intellij-rust","homepage":"","size":20983,"stargazers_count":0,"watchers_count":0,"language":"Kotlin","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"intellij-rust:master","ref":"master","sha":"d32cf48cbc1715af6ed8c4c339d7d1c79fdd4fea","user":{"login":"intellij-rust","id":16057867,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2MDU3ODY3","avatar_url":"https://avatars0.githubusercontent.com/u/16057867?v=4","gravatar_id":"","url":"https://api.github.com/users/intellij-rust","html_url":"https://github.com/intellij-rust","followers_url":"https://api.github.com/users/intellij-rust/followers","following_url":"https://api.github.com/users/intellij-rust/following{/other_user}","gists_url":"https://api.github.com/users/intellij-rust/gists{/gist_id}","starred_url":"https://api.github.com/users/intellij-rust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intellij-rust/subscriptions","organizations_url":"https://api.github.com/users/intellij-rust/orgs","repos_url":"https://api.github.com/users/intellij-rust/repos","events_url":"https://api.github.com/users/intellij-rust/events{/privacy}","received_events_url":"https://api.github.com/users/intellij-rust/received_events","type":"Organization","site_admin":false},"repo":{"id":42619487,"node_id":"MDEwOlJlcG9zaXRvcnk0MjYxOTQ4Nw==","name":"intellij-rust","full_name":"intellij-rust/intellij-rust","private":false,"owner":{"login":"intellij-rust","id":16057867,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2MDU3ODY3","avatar_url":"https://avatars0.githubusercontent.com/u/16057867?v=4","gravatar_id":"","url":"https://api.github.com/users/intellij-rust","html_url":"https://github.com/intellij-rust","followers_url":"https://api.github.com/users/intellij-rust/followers","following_url":"https://api.github.com/users/intellij-rust/following{/other_user}","gists_url":"https://api.github.com/users/intellij-rust/gists{/gist_id}","starred_url":"https://api.github.com/users/intellij-rust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intellij-rust/subscriptions","organizations_url":"https://api.github.com/users/intellij-rust/orgs","repos_url":"https://api.github.com/users/intellij-rust/repos","events_url":"https://api.github.com/users/intellij-rust/events{/privacy}","received_events_url":"https://api.github.com/users/intellij-rust/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/intellij-rust/intellij-rust","description":"Rust plugin for the IntelliJ Platform: https://intellij-rust.github.io/","fork":false,"url":"https://api.github.com/repos/intellij-rust/intellij-rust","forks_url":"https://api.github.com/repos/intellij-rust/intellij-rust/forks","keys_url":"https://api.github.com/repos/intellij-rust/intellij-rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/intellij-rust/intellij-rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/intellij-rust/intellij-rust/teams","hooks_url":"https://api.github.com/repos/intellij-rust/intellij-rust/hooks","issue_events_url":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/events{/number}","events_url":"https://api.github.com/repos/intellij-rust/intellij-rust/events","assignees_url":"https://api.github.com/repos/intellij-rust/intellij-rust/assignees{/user}","branches_url":"https://api.github.com/repos/intellij-rust/intellij-rust/branches{/branch}","tags_url":"https://api.github.com/repos/intellij-rust/intellij-rust/tags","blobs_url":"https://api.github.com/repos/intellij-rust/intellij-rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/intellij-rust/intellij-rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/intellij-rust/intellij-rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/intellij-rust/intellij-rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/intellij-rust/intellij-rust/statuses/{sha}","languages_url":"https://api.github.com/repos/intellij-rust/intellij-rust/languages","stargazers_url":"https://api.github.com/repos/intellij-rust/intellij-rust/stargazers","contributors_url":"https://api.github.com/repos/intellij-rust/intellij-rust/contributors","subscribers_url":"https://api.github.com/repos/intellij-rust/intellij-rust/subscribers","subscription_url":"https://api.github.com/repos/intellij-rust/intellij-rust/subscription","commits_url":"https://api.github.com/repos/intellij-rust/intellij-rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/intellij-rust/intellij-rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/intellij-rust/intellij-rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/intellij-rust/intellij-rust/contents/{+path}","compare_url":"https://api.github.com/repos/intellij-rust/intellij-rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/intellij-rust/intellij-rust/merges","archive_url":"https://api.github.com/repos/intellij-rust/intellij-rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/intellij-rust/intellij-rust/downloads","issues_url":"https://api.github.com/repos/intellij-rust/intellij-rust/issues{/number}","pulls_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls{/number}","milestones_url":"https://api.github.com/repos/intellij-rust/intellij-rust/milestones{/number}","notifications_url":"https://api.github.com/repos/intellij-rust/intellij-rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/intellij-rust/intellij-rust/labels{/name}","releases_url":"https://api.github.com/repos/intellij-rust/intellij-rust/releases{/id}","deployments_url":"https://api.github.com/repos/intellij-rust/intellij-rust/deployments","created_at":"2015-09-16T23:44:57Z","updated_at":"2018-10-30T23:47:08Z","pushed_at":"2018-10-31T01:02:31Z","git_url":"git://github.com/intellij-rust/intellij-rust.git","ssh_url":"git@github.com:intellij-rust/intellij-rust.git","clone_url":"https://github.com/intellij-rust/intellij-rust.git","svn_url":"https://github.com/intellij-rust/intellij-rust","homepage":"","size":21188,"stargazers_count":2028,"watchers_count":2028,"language":"Kotlin","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":196,"mirror_url":null,"archived":false,"open_issues_count":370,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":196,"open_issues":370,"watchers":2028,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990"},"html":{"href":"https://github.com/intellij-rust/intellij-rust/pull/2990"},"issue":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/2990"},"comments":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/2990/comments"},"review_comments":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990/comments"},"review_comment":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/2990/commits"},"statuses":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/statuses/ce89a6cb41477c480edf0dfdb2d9285fc394084e"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"isamborskiy"}}