{"action":"created","comment":{"url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/comments/66168974","id":66168974,"diff_hunk":"@@ -1,9 +1,256 @@\n package org.rust.lang.core.resolve.scope\n \n-import org.rust.lang.core.psi.RustCompositeElement\n-import org.rust.lang.core.psi.RustNamedElement\n+import com.intellij.openapi.module.Module\n+import com.intellij.psi.PsiElement\n+import com.intellij.psi.PsiFile\n+import com.intellij.psi.util.PsiTreeUtil\n+import com.intellij.psi.util.PsiUtilCore\n+import org.rust.cargo.util.AutoInjectedCrates\n+import org.rust.cargo.util.cargoProject\n+import org.rust.cargo.util.getPsiFor\n+import org.rust.cargo.util.preludeModule\n+import org.rust.lang.core.psi.*\n+import org.rust.lang.core.psi.impl.RustFile\n+import org.rust.lang.core.psi.impl.mixin.isStarImport\n+import org.rust.lang.core.psi.impl.rustMod\n+import org.rust.lang.core.psi.util.module\n \n interface RustResolveScope : RustCompositeElement {\n-    val declarations: Collection<RustNamedElement>\n+    data class Context(\n+        val place: RustCompositeElement?,\n+        val inPrelude: Boolean = false,\n+        val visitedStarImports: Set<RustUseItemElement> = emptySet()\n+    )\n+\n+    interface Entry {\n+        val name: String\n+        val element: RustNamedElement?\n+    }\n+}\n+\n+fun RustResolveScope.declarations(context: RustResolveScope.Context): Sequence<RustResolveScope.Entry> {\n+    val visitor = RustScopeVisitor(context)\n+    accept(visitor)\n+    return visitor.result\n+}\n+\n+private class ScopeEntryImpl private constructor(","path":"src/main/kotlin/org/rust/lang/core/resolve/scope/RustResolveScope.kt","position":null,"original_position":40,"commit_id":"2a3876716f428329cdfa9090282bc90e0aa47712","original_commit_id":"ffb72dcd2673adfea4665594759fe099f6ed5bd8","user":{"login":"matklad","id":1711539,"avatar_url":"https://avatars.githubusercontent.com/u/1711539?v=3","gravatar_id":"","url":"https://api.github.com/users/matklad","html_url":"https://github.com/matklad","followers_url":"https://api.github.com/users/matklad/followers","following_url":"https://api.github.com/users/matklad/following{/other_user}","gists_url":"https://api.github.com/users/matklad/gists{/gist_id}","starred_url":"https://api.github.com/users/matklad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matklad/subscriptions","organizations_url":"https://api.github.com/users/matklad/orgs","repos_url":"https://api.github.com/users/matklad/repos","events_url":"https://api.github.com/users/matklad/events{/privacy}","received_events_url":"https://api.github.com/users/matklad/received_events","type":"User","site_admin":false},"body":"This split allows to make construction of `ScopeEntries` private to this file. If we move `ScopeEntry` to the `RRE` as per you suggestion then this split will indeed become redundant as we'd have to expose constructors anyway. ","created_at":"2016-06-07T23:12:07Z","updated_at":"2016-06-07T23:12:07Z","html_url":"https://github.com/intellij-rust/intellij-rust/pull/444#discussion_r66168974","pull_request_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444","_links":{"self":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/comments/66168974"},"html":{"href":"https://github.com/intellij-rust/intellij-rust/pull/444#discussion_r66168974"},"pull_request":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444"}}},"pull_request":{"url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444","id":72809989,"html_url":"https://github.com/intellij-rust/intellij-rust/pull/444","diff_url":"https://github.com/intellij-rust/intellij-rust/pull/444.diff","patch_url":"https://github.com/intellij-rust/intellij-rust/pull/444.patch","issue_url":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/444","number":444,"state":"open","locked":false,"title":"(RES): refactor RustResolveScope","user":{"login":"matklad","id":1711539,"avatar_url":"https://avatars.githubusercontent.com/u/1711539?v=3","gravatar_id":"","url":"https://api.github.com/users/matklad","html_url":"https://github.com/matklad","followers_url":"https://api.github.com/users/matklad/followers","following_url":"https://api.github.com/users/matklad/following{/other_user}","gists_url":"https://api.github.com/users/matklad/gists{/gist_id}","starred_url":"https://api.github.com/users/matklad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matklad/subscriptions","organizations_url":"https://api.github.com/users/matklad/orgs","repos_url":"https://api.github.com/users/matklad/repos","events_url":"https://api.github.com/users/matklad/events{/privacy}","received_events_url":"https://api.github.com/users/matklad/received_events","type":"User","site_admin":false},"body":"This PR tries to refactor `RustResolveScope` to make it more general and useful.\r\n\r\nCurrently, `RustResolveScope` allows to get a list of `RustNamedElements` for a scope. Unfortunately, the interface is not flexible enough. In particular, it can't handle\r\n\r\n* elements, which need further resolve (`use foo;`, `mod foo;`, `extern crate foo;`). This causes a ton of casts in the `assign` function of RRE. \r\n* aliases (special case of the previous bullet)\r\n* reexports (`use foo::*;` and prelude items)\r\n* context sensitivity (proper scoping for local variables)\r\n* laziness\r\n\r\nSo currently the scoping logic is dispersed across a number of `RustResolveScope` PSI elements, a bunch of RRE functions and a couple of extension methods.\r\n\r\nThe idea of this PR is to consolidate all this logic within `RustResolveScope`. So, the new `declarations` signature looks like this:\r\n\r\n```\r\nfun RustResolveScope.declarations(context: RustResolveScope.Context): Sequence<ScopeEntry> {\r\n```\r\n\r\nIt allows to lazily retrieve **all** items in the scope which are visible at a particular place together with their actual names.\r\n\r\n@alexeykudinkin what do you think about this approach? ","created_at":"2016-06-07T03:13:30Z","updated_at":"2016-06-07T23:12:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b5844753bb8f020f3153f9e76481fa162b9e459","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444/commits","review_comments_url":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444/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/444/comments","statuses_url":"https://api.github.com/repos/intellij-rust/intellij-rust/statuses/2a3876716f428329cdfa9090282bc90e0aa47712","head":{"label":"intellij-rust:scope-entries","ref":"scope-entries","sha":"2a3876716f428329cdfa9090282bc90e0aa47712","user":{"login":"intellij-rust","id":16057867,"avatar_url":"https://avatars.githubusercontent.com/u/16057867?v=3","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,"name":"intellij-rust","full_name":"intellij-rust/intellij-rust","owner":{"login":"intellij-rust","id":16057867,"avatar_url":"https://avatars.githubusercontent.com/u/16057867?v=3","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},"private":false,"html_url":"https://github.com/intellij-rust/intellij-rust","description":"Rust IDE built using the IntelliJ Platform","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":"2016-06-07T15:18:23Z","pushed_at":"2016-06-07T20:25:11Z","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":null,"size":9015,"stargazers_count":644,"watchers_count":644,"language":"Kotlin","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":36,"forks":49,"open_issues":36,"watchers":644,"default_branch":"master"}},"base":{"label":"intellij-rust:master","ref":"master","sha":"989abcd1045fe988e975c2f069fd8910c8d9b8d0","user":{"login":"intellij-rust","id":16057867,"avatar_url":"https://avatars.githubusercontent.com/u/16057867?v=3","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,"name":"intellij-rust","full_name":"intellij-rust/intellij-rust","owner":{"login":"intellij-rust","id":16057867,"avatar_url":"https://avatars.githubusercontent.com/u/16057867?v=3","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},"private":false,"html_url":"https://github.com/intellij-rust/intellij-rust","description":"Rust IDE built using the IntelliJ Platform","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":"2016-06-07T15:18:23Z","pushed_at":"2016-06-07T20:25:11Z","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":null,"size":9015,"stargazers_count":644,"watchers_count":644,"language":"Kotlin","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":36,"forks":49,"open_issues":36,"watchers":644,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444"},"html":{"href":"https://github.com/intellij-rust/intellij-rust/pull/444"},"issue":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/444"},"comments":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/issues/444/comments"},"review_comments":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/pulls/444/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/444/commits"},"statuses":{"href":"https://api.github.com/repos/intellij-rust/intellij-rust/statuses/2a3876716f428329cdfa9090282bc90e0aa47712"}}}}
{"actor":{"display_login":"matklad"}}