{"action":"created","comment":{"url":"https://api.github.com/repos/ul/kak-lsp/pulls/comments/194202059","pull_request_review_id":127337421,"id":194202059,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDIwMjA1OQ==","diff_hunk":"@@ -43,46 +44,73 @@ pub fn editor_references(\n         ReferencesResponse::Array(locations) => Some(locations),\n         ReferencesResponse::None => None,\n     } {\n+        // Sort locations by (filename, line)\n+        let mut locations = locations.to_vec();\n+\n+        locations\n+            .sort_unstable_by_key(|location| {\n+              (location.uri.to_file_path(),\n+              location.range.start.line)\n+          });\n+\n         let content = locations\n             .iter()\n-            .map(|location| {\n-                let p = location.range.start;\n-                let path = location.uri.to_file_path().unwrap();\n-                let filename = path.to_str().unwrap();\n-                let file = File::open(filename);\n+            .group_by(|location|{\n+              location.uri.to_file_path()\n+            })\n+            .into_iter()\n+            .map(|(filename, group)| {\n+                let filename = filename.unwrap();\n+                let name = filename.to_str().unwrap();\n+                let file = File::open(name);","path":"src/language_features/references.rs","position":33,"original_position":33,"commit_id":"f7d5cea501569d02c085d6033e150e4002a95794","original_commit_id":"f7d5cea501569d02c085d6033e150e4002a95794","user":{"login":"ul","id":233227,"node_id":"MDQ6VXNlcjIzMzIyNw==","avatar_url":"https://avatars2.githubusercontent.com/u/233227?v=4","gravatar_id":"","url":"https://api.github.com/users/ul","html_url":"https://github.com/ul","followers_url":"https://api.github.com/users/ul/followers","following_url":"https://api.github.com/users/ul/following{/other_user}","gists_url":"https://api.github.com/users/ul/gists{/gist_id}","starred_url":"https://api.github.com/users/ul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ul/subscriptions","organizations_url":"https://api.github.com/users/ul/orgs","repos_url":"https://api.github.com/users/ul/repos","events_url":"https://api.github.com/users/ul/events{/privacy}","received_events_url":"https://api.github.com/users/ul/received_events","type":"User","site_admin":false},"body":"`File::open` can take path as well, no need to convert it to string. Also we could lift making relative path string from line 87 because it will be the same each iteration of loop. I imagine something like that:\r\n\r\n```\r\n                let filename = filename.unwrap();\r\n                let file = File::open(&filename);\r\n                let name = filename\r\n                    .strip_prefix(&ctx.root_path)\r\n                    .ok()\r\n                    .and_then(|p| Some(p.to_str().unwrap()))\r\n                    .or_else(|| filename.to_str())\r\n                    .unwrap();\r\n```","created_at":"2018-06-08T23:24:05Z","updated_at":"2018-06-08T23:34:20Z","html_url":"https://github.com/ul/kak-lsp/pull/61#discussion_r194202059","pull_request_url":"https://api.github.com/repos/ul/kak-lsp/pulls/61","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/ul/kak-lsp/pulls/comments/194202059"},"html":{"href":"https://github.com/ul/kak-lsp/pull/61#discussion_r194202059"},"pull_request":{"href":"https://api.github.com/repos/ul/kak-lsp/pulls/61"}}},"pull_request":{"url":"https://api.github.com/repos/ul/kak-lsp/pulls/61","id":193711052,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNzExMDUy","html_url":"https://github.com/ul/kak-lsp/pull/61","diff_url":"https://github.com/ul/kak-lsp/pull/61.diff","patch_url":"https://github.com/ul/kak-lsp/pull/61.patch","issue_url":"https://api.github.com/repos/ul/kak-lsp/issues/61","number":61,"state":"open","locked":false,"title":"Apply Issue #34 optimization","user":{"login":"Pantoofle","id":22241764,"node_id":"MDQ6VXNlcjIyMjQxNzY0","avatar_url":"https://avatars2.githubusercontent.com/u/22241764?v=4","gravatar_id":"","url":"https://api.github.com/users/Pantoofle","html_url":"https://github.com/Pantoofle","followers_url":"https://api.github.com/users/Pantoofle/followers","following_url":"https://api.github.com/users/Pantoofle/following{/other_user}","gists_url":"https://api.github.com/users/Pantoofle/gists{/gist_id}","starred_url":"https://api.github.com/users/Pantoofle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pantoofle/subscriptions","organizations_url":"https://api.github.com/users/Pantoofle/orgs","repos_url":"https://api.github.com/users/Pantoofle/repos","events_url":"https://api.github.com/users/Pantoofle/events{/privacy}","received_events_url":"https://api.github.com/users/Pantoofle/received_events","type":"User","site_admin":false},"body":"Now the locations are grouped by filename and then sorted by line number.\r\nThis way, we only scan files once and load only one buffer.","created_at":"2018-06-08T20:05:19Z","updated_at":"2018-06-08T23:34:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0d639c2f02295d69ceed1cbadc9e73f6b1b84d1c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/ul/kak-lsp/pulls/61/commits","review_comments_url":"https://api.github.com/repos/ul/kak-lsp/pulls/61/comments","review_comment_url":"https://api.github.com/repos/ul/kak-lsp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ul/kak-lsp/issues/61/comments","statuses_url":"https://api.github.com/repos/ul/kak-lsp/statuses/f7d5cea501569d02c085d6033e150e4002a95794","head":{"label":"Pantoofle:master","ref":"master","sha":"f7d5cea501569d02c085d6033e150e4002a95794","user":{"login":"Pantoofle","id":22241764,"node_id":"MDQ6VXNlcjIyMjQxNzY0","avatar_url":"https://avatars2.githubusercontent.com/u/22241764?v=4","gravatar_id":"","url":"https://api.github.com/users/Pantoofle","html_url":"https://github.com/Pantoofle","followers_url":"https://api.github.com/users/Pantoofle/followers","following_url":"https://api.github.com/users/Pantoofle/following{/other_user}","gists_url":"https://api.github.com/users/Pantoofle/gists{/gist_id}","starred_url":"https://api.github.com/users/Pantoofle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pantoofle/subscriptions","organizations_url":"https://api.github.com/users/Pantoofle/orgs","repos_url":"https://api.github.com/users/Pantoofle/repos","events_url":"https://api.github.com/users/Pantoofle/events{/privacy}","received_events_url":"https://api.github.com/users/Pantoofle/received_events","type":"User","site_admin":false},"repo":{"id":136530498,"node_id":"MDEwOlJlcG9zaXRvcnkxMzY1MzA0OTg=","name":"kak-lsp","full_name":"Pantoofle/kak-lsp","owner":{"login":"Pantoofle","id":22241764,"node_id":"MDQ6VXNlcjIyMjQxNzY0","avatar_url":"https://avatars2.githubusercontent.com/u/22241764?v=4","gravatar_id":"","url":"https://api.github.com/users/Pantoofle","html_url":"https://github.com/Pantoofle","followers_url":"https://api.github.com/users/Pantoofle/followers","following_url":"https://api.github.com/users/Pantoofle/following{/other_user}","gists_url":"https://api.github.com/users/Pantoofle/gists{/gist_id}","starred_url":"https://api.github.com/users/Pantoofle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pantoofle/subscriptions","organizations_url":"https://api.github.com/users/Pantoofle/orgs","repos_url":"https://api.github.com/users/Pantoofle/repos","events_url":"https://api.github.com/users/Pantoofle/events{/privacy}","received_events_url":"https://api.github.com/users/Pantoofle/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Pantoofle/kak-lsp","description":"Kakoune Language Server Protocol Client","fork":true,"url":"https://api.github.com/repos/Pantoofle/kak-lsp","forks_url":"https://api.github.com/repos/Pantoofle/kak-lsp/forks","keys_url":"https://api.github.com/repos/Pantoofle/kak-lsp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Pantoofle/kak-lsp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Pantoofle/kak-lsp/teams","hooks_url":"https://api.github.com/repos/Pantoofle/kak-lsp/hooks","issue_events_url":"https://api.github.com/repos/Pantoofle/kak-lsp/issues/events{/number}","events_url":"https://api.github.com/repos/Pantoofle/kak-lsp/events","assignees_url":"https://api.github.com/repos/Pantoofle/kak-lsp/assignees{/user}","branches_url":"https://api.github.com/repos/Pantoofle/kak-lsp/branches{/branch}","tags_url":"https://api.github.com/repos/Pantoofle/kak-lsp/tags","blobs_url":"https://api.github.com/repos/Pantoofle/kak-lsp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Pantoofle/kak-lsp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Pantoofle/kak-lsp/git/refs{/sha}","trees_url":"https://api.github.com/repos/Pantoofle/kak-lsp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Pantoofle/kak-lsp/statuses/{sha}","languages_url":"https://api.github.com/repos/Pantoofle/kak-lsp/languages","stargazers_url":"https://api.github.com/repos/Pantoofle/kak-lsp/stargazers","contributors_url":"https://api.github.com/repos/Pantoofle/kak-lsp/contributors","subscribers_url":"https://api.github.com/repos/Pantoofle/kak-lsp/subscribers","subscription_url":"https://api.github.com/repos/Pantoofle/kak-lsp/subscription","commits_url":"https://api.github.com/repos/Pantoofle/kak-lsp/commits{/sha}","git_commits_url":"https://api.github.com/repos/Pantoofle/kak-lsp/git/commits{/sha}","comments_url":"https://api.github.com/repos/Pantoofle/kak-lsp/comments{/number}","issue_comment_url":"https://api.github.com/repos/Pantoofle/kak-lsp/issues/comments{/number}","contents_url":"https://api.github.com/repos/Pantoofle/kak-lsp/contents/{+path}","compare_url":"https://api.github.com/repos/Pantoofle/kak-lsp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Pantoofle/kak-lsp/merges","archive_url":"https://api.github.com/repos/Pantoofle/kak-lsp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Pantoofle/kak-lsp/downloads","issues_url":"https://api.github.com/repos/Pantoofle/kak-lsp/issues{/number}","pulls_url":"https://api.github.com/repos/Pantoofle/kak-lsp/pulls{/number}","milestones_url":"https://api.github.com/repos/Pantoofle/kak-lsp/milestones{/number}","notifications_url":"https://api.github.com/repos/Pantoofle/kak-lsp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Pantoofle/kak-lsp/labels{/name}","releases_url":"https://api.github.com/repos/Pantoofle/kak-lsp/releases{/id}","deployments_url":"https://api.github.com/repos/Pantoofle/kak-lsp/deployments","created_at":"2018-06-07T21:00:17Z","updated_at":"2018-06-08T20:03:47Z","pushed_at":"2018-06-08T20:03:46Z","git_url":"git://github.com/Pantoofle/kak-lsp.git","ssh_url":"git@github.com:Pantoofle/kak-lsp.git","clone_url":"https://github.com/Pantoofle/kak-lsp.git","svn_url":"https://github.com/Pantoofle/kak-lsp","homepage":null,"size":171,"stargazers_count":0,"watchers_count":0,"language":"Rust","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":"unlicense","name":"The Unlicense","spdx_id":"Unlicense","url":"https://api.github.com/licenses/unlicense","node_id":"MDc6TGljZW5zZTE1"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ul:master","ref":"master","sha":"f94f787839d5d45a597c1e7adc553863864696d0","user":{"login":"ul","id":233227,"node_id":"MDQ6VXNlcjIzMzIyNw==","avatar_url":"https://avatars2.githubusercontent.com/u/233227?v=4","gravatar_id":"","url":"https://api.github.com/users/ul","html_url":"https://github.com/ul","followers_url":"https://api.github.com/users/ul/followers","following_url":"https://api.github.com/users/ul/following{/other_user}","gists_url":"https://api.github.com/users/ul/gists{/gist_id}","starred_url":"https://api.github.com/users/ul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ul/subscriptions","organizations_url":"https://api.github.com/users/ul/orgs","repos_url":"https://api.github.com/users/ul/repos","events_url":"https://api.github.com/users/ul/events{/privacy}","received_events_url":"https://api.github.com/users/ul/received_events","type":"User","site_admin":false},"repo":{"id":127094854,"node_id":"MDEwOlJlcG9zaXRvcnkxMjcwOTQ4NTQ=","name":"kak-lsp","full_name":"ul/kak-lsp","owner":{"login":"ul","id":233227,"node_id":"MDQ6VXNlcjIzMzIyNw==","avatar_url":"https://avatars2.githubusercontent.com/u/233227?v=4","gravatar_id":"","url":"https://api.github.com/users/ul","html_url":"https://github.com/ul","followers_url":"https://api.github.com/users/ul/followers","following_url":"https://api.github.com/users/ul/following{/other_user}","gists_url":"https://api.github.com/users/ul/gists{/gist_id}","starred_url":"https://api.github.com/users/ul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ul/subscriptions","organizations_url":"https://api.github.com/users/ul/orgs","repos_url":"https://api.github.com/users/ul/repos","events_url":"https://api.github.com/users/ul/events{/privacy}","received_events_url":"https://api.github.com/users/ul/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ul/kak-lsp","description":"Kakoune Language Server Protocol Client","fork":false,"url":"https://api.github.com/repos/ul/kak-lsp","forks_url":"https://api.github.com/repos/ul/kak-lsp/forks","keys_url":"https://api.github.com/repos/ul/kak-lsp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ul/kak-lsp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ul/kak-lsp/teams","hooks_url":"https://api.github.com/repos/ul/kak-lsp/hooks","issue_events_url":"https://api.github.com/repos/ul/kak-lsp/issues/events{/number}","events_url":"https://api.github.com/repos/ul/kak-lsp/events","assignees_url":"https://api.github.com/repos/ul/kak-lsp/assignees{/user}","branches_url":"https://api.github.com/repos/ul/kak-lsp/branches{/branch}","tags_url":"https://api.github.com/repos/ul/kak-lsp/tags","blobs_url":"https://api.github.com/repos/ul/kak-lsp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ul/kak-lsp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ul/kak-lsp/git/refs{/sha}","trees_url":"https://api.github.com/repos/ul/kak-lsp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ul/kak-lsp/statuses/{sha}","languages_url":"https://api.github.com/repos/ul/kak-lsp/languages","stargazers_url":"https://api.github.com/repos/ul/kak-lsp/stargazers","contributors_url":"https://api.github.com/repos/ul/kak-lsp/contributors","subscribers_url":"https://api.github.com/repos/ul/kak-lsp/subscribers","subscription_url":"https://api.github.com/repos/ul/kak-lsp/subscription","commits_url":"https://api.github.com/repos/ul/kak-lsp/commits{/sha}","git_commits_url":"https://api.github.com/repos/ul/kak-lsp/git/commits{/sha}","comments_url":"https://api.github.com/repos/ul/kak-lsp/comments{/number}","issue_comment_url":"https://api.github.com/repos/ul/kak-lsp/issues/comments{/number}","contents_url":"https://api.github.com/repos/ul/kak-lsp/contents/{+path}","compare_url":"https://api.github.com/repos/ul/kak-lsp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ul/kak-lsp/merges","archive_url":"https://api.github.com/repos/ul/kak-lsp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ul/kak-lsp/downloads","issues_url":"https://api.github.com/repos/ul/kak-lsp/issues{/number}","pulls_url":"https://api.github.com/repos/ul/kak-lsp/pulls{/number}","milestones_url":"https://api.github.com/repos/ul/kak-lsp/milestones{/number}","notifications_url":"https://api.github.com/repos/ul/kak-lsp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ul/kak-lsp/labels{/name}","releases_url":"https://api.github.com/repos/ul/kak-lsp/releases{/id}","deployments_url":"https://api.github.com/repos/ul/kak-lsp/deployments","created_at":"2018-03-28T06:33:47Z","updated_at":"2018-06-08T05:44:05Z","pushed_at":"2018-06-08T20:05:20Z","git_url":"git://github.com/ul/kak-lsp.git","ssh_url":"git@github.com:ul/kak-lsp.git","clone_url":"https://github.com/ul/kak-lsp.git","svn_url":"https://github.com/ul/kak-lsp","homepage":null,"size":162,"stargazers_count":31,"watchers_count":31,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":11,"license":{"key":"unlicense","name":"The Unlicense","spdx_id":"Unlicense","url":"https://api.github.com/licenses/unlicense","node_id":"MDc6TGljZW5zZTE1"},"forks":10,"open_issues":11,"watchers":31,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ul/kak-lsp/pulls/61"},"html":{"href":"https://github.com/ul/kak-lsp/pull/61"},"issue":{"href":"https://api.github.com/repos/ul/kak-lsp/issues/61"},"comments":{"href":"https://api.github.com/repos/ul/kak-lsp/issues/61/comments"},"review_comments":{"href":"https://api.github.com/repos/ul/kak-lsp/pulls/61/comments"},"review_comment":{"href":"https://api.github.com/repos/ul/kak-lsp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ul/kak-lsp/pulls/61/commits"},"statuses":{"href":"https://api.github.com/repos/ul/kak-lsp/statuses/f7d5cea501569d02c085d6033e150e4002a95794"}},"author_association":"NONE"}}
{"actor":{"display_login":"ul"}}