Repository: rust-analyzer/rust-analyzer
Pull request #2062 (2019-10-24 16:29:58)

refactor comment extraction from tasks


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index c902caeb4d..61fd24ef7f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -206,6 +206,21 @@ dependencies = [
  "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "console"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "console"
 version = "0.9.0"
@@ -495,16 +510,16 @@ dependencies = [
 
 [[package]]
 name = "insta"
-version = "0.12.0"
+version = "0.11.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "console 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "console 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -983,7 +998,7 @@ dependencies = [
  "chalk-rust-ir 0.1.0 (git+https://github.com/rust-lang/chalk.git)",
  "chalk-solve 0.1.0 (git+https://github.com/rust-lang/chalk.git)",
  "ena 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "insta 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1006,7 +1021,7 @@ version = "0.1.0"
 dependencies = [
  "format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "fst 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "insta 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1185,7 +1200,7 @@ dependencies = [
  "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_pcg 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1285,9 +1300,10 @@ dependencies = [
 
 [[package]]
 name = "rand_pcg"
-version = "0.2.1"
+version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
+ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -1678,10 +1694,10 @@ dependencies = [
 
 [[package]]
 name = "uuid"
-version = "0.8.1"
+version = "0.7.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -1802,6 +1818,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68"
 "checksum clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e"
 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
+"checksum console 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b147390a412132d75d10dd3b7b175a69cf5fd95032f7503c7091b8831ba10242"
 "checksum console 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62828f51cfa18f8c31d3d55a43c6ce6af3f87f754cba9fbba7ff38089b9f5612"
 "checksum crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2d818a4990769aac0c7ff1360e233ef3a41adcb009ebb2036bf6915eb0f6b23c"
 "checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa"
@@ -1837,7 +1854,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum indicatif 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8d596a9576eaa1446996092642d72bfef35cf47243129b7ab883baf5faec31e"
 "checksum inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b54539f3910d6f84fbf9a643efd6e3aa6e4f001426c0329576128255994718"
 "checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0"
-"checksum insta 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d499dc062e841590a67230d853bce62d0abeb91304927871670b7c55c461349"
+"checksum insta 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23f83ab4ee86f38b292f0420c27fd412690a4baa9ea0ad4e3fa624bf34379b76"
 "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
 "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
 "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
@@ -1899,7 +1916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
 "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
 "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
-"checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
+"checksum rand_pcg 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e196346cbbc5c70c77e7b4926147ee8e383a38ee4d15d58a08098b169e492b6"
 "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
 "checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123"
 "checksum rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b"
@@ -1946,7 +1963,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
 "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
 "checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"
-"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
+"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a"
 "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
 "checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
 "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 04aba37437..cda5cafb8b 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -13,7 +13,6 @@ pub fn run(
     memory_usage: bool,
     path: &Path,
     only: Option<&str>,
-    with_deps: bool,
 ) -> Result<()> {
     let db_load_time = Instant::now();
     let (mut host, roots) = ra_batch::load_cargo(path)?;
@@ -24,17 +23,18 @@ pub fn run(
     let mut visited_modules = HashSet::new();
     let mut visit_queue = Vec::new();
 
-    let members =
-        roots
-            .into_iter()
-            .filter_map(|(source_root_id, project_root)| {
-                if with_deps || project_root.is_member() {
+    let members = roots
+        .into_iter()
+        .filter_map(
+            |(source_root_id, project_root)| {
+                if project_root.is_member() {
                     Some(source_root_id)
                 } else {
                     None
                 }
-            })
-            .collect::<HashSet<_>>();
+            },
+        )
+        .collect::<HashSet<_>>();
 
     for krate in Crate::all(db) {
         let module = krate.root_module(db).expect("crate without root module");
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index a31fd5d6ae..2405eb4f4e 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -96,7 +96,6 @@ fn main() -> Result<()> {
             };
             let memory_usage = matches.contains("--memory-usage");
             let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
-            let with_deps: bool = matches.contains("--with-deps");
             let path = {
                 let mut trailing = matches.free()?;
                 if trailing.len() != 1 {
@@ -110,7 +109,6 @@ fn main() -> Result<()> {
                 memory_usage,
                 path.as_ref(),
                 only.as_ref().map(String::as_ref),
-                with_deps,
             )?;
         }
         "analysis-bench" => {
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index 54c09788aa..edf1fa49be 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -28,4 +28,4 @@ chalk-ir = { git = "https://github.com/rust-lang/chalk.git" }
 lalrpop-intern = "0.15.1"
 
 [dev-dependencies]
-insta = "0.12.0"
+insta = "0.11.0"
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index f66f0a6bad..f9bf0c686a 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -32,7 +32,7 @@ test_utils = { path = "../test_utils" }
 ra_assists = { path = "../ra_assists" }
 
 [dev-dependencies]
-insta = "0.12.0"
+insta = "0.11.0"
 
 [dev-dependencies.proptest]
 version = "0.9.0"
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 0832229fd1..19669a7f02 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -71,7 +71,7 @@ pub use crate::{
     inlay_hints::{InlayHint, InlayKind},
     line_index::{LineCol, LineIndex},
     line_index_utils::translate_offset_with_edit,
-    references::{ReferenceSearchResult, SearchScope},
+    references::ReferenceSearchResult,
     runnables::{Runnable, RunnableKind},
     syntax_highlighting::HighlightedRange,
 };
@@ -481,9 +481,8 @@ impl Analysis {
     pub fn find_all_refs(
         &self,
         position: FilePosition,
-        search_scope: Option<SearchScope>,
     ) -> Cancelable<Option<ReferenceSearchResult>> {
-        self.with_db(|db| references::find_all_refs(db, position, search_scope).map(|it| it.info))
+        self.with_db(|db| references::find_all_refs(db, position).map(|it| it.info))
     }
 
     /// Returns a short text describing element at position.
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index b5b1c9a16f..8200bd1ef3 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -27,8 +27,6 @@ pub(crate) use self::{
     rename::rename,
 };
 
-pub use self::search_scope::SearchScope;
-
 #[derive(Debug, Clone)]
 pub struct ReferenceSearchResult {
     declaration: NavigationTarget,
@@ -69,7 +67,6 @@ impl IntoIterator for ReferenceSearchResult {
 pub(crate) fn find_all_refs(
     db: &RootDatabase,
     position: FilePosition,
-    search_scope: Option<SearchScope>,
 ) -> Option<RangeInfo<ReferenceSearchResult>> {
     let parse = db.parse(position.file_id);
     let syntax = parse.tree().syntax().clone();
@@ -89,15 +86,7 @@ pub(crate) fn find_all_refs(
         NameKind::GenericParam(_) => return None,
     };
 
-    let search_scope = {
-        let base = def.search_scope(db);
-        match search_scope {
-            None => base,
-            Some(scope) => base.intersection(&scope),
-        }
-    };
-
-    let references = process_definition(db, def, name, search_scope);
+    let references = process_definition(db, def, name);
 
     Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references }))
 }
@@ -118,15 +107,11 @@ fn find_name<'a>(
     Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
 }
 
-fn process_definition(
-    db: &RootDatabase,
-    def: NameDefinition,
-    name: String,
-    scope: SearchScope,
-) -> Vec<FileRange> {
+fn process_definition(db: &RootDatabase, def: NameDefinition, name: String) -> Vec<FileRange> {
     let _p = profile("process_definition");
 
     let pat = name.as_str();
+    let scope = def.search_scope(db);
     let mut refs = vec![];
 
     for (file_id, search_range) in scope {
@@ -159,8 +144,8 @@ fn process_definition(
 #[cfg(test)]
 mod tests {
     use crate::{
-        mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis},
-        ReferenceSearchResult, SearchScope,
+        mock_analysis::analysis_and_position, mock_analysis::single_file_with_position,
+        ReferenceSearchResult,
     };
 
     #[test]
@@ -285,7 +270,7 @@ mod tests {
         "#;
 
         let (analysis, pos) = analysis_and_position(code);
-        let refs = analysis.find_all_refs(pos, None).unwrap().unwrap();
+        let refs = analysis.find_all_refs(pos).unwrap().unwrap();
         assert_eq!(refs.len(), 3);
     }
 
@@ -311,7 +296,7 @@ mod tests {
         "#;
 
         let (analysis, pos) = analysis_and_position(code);
-        let refs = analysis.find_all_refs(pos, None).unwrap().unwrap();
+        let refs = analysis.find_all_refs(pos).unwrap().unwrap();
         assert_eq!(refs.len(), 2);
     }
 
@@ -336,40 +321,12 @@ mod tests {
         "#;
 
         let (analysis, pos) = analysis_and_position(code);
-        let refs = analysis.find_all_refs(pos, None).unwrap().unwrap();
-        assert_eq!(refs.len(), 3);
-    }
-
-    #[test]
-    fn test_find_all_refs_with_scope() {
-        let code = r#"
-            //- /lib.rs
-            mod foo;
-            mod bar;
-
-            pub fn quux<|>() {}
-
-            //- /foo.rs
-            fn f() { super::quux(); }
-
-            //- /bar.rs
-            fn f() { super::quux(); }
-        "#;
-
-        let (mock, pos) = MockAnalysis::with_files_and_position(code);
-        let bar = mock.id_of("/bar.rs");
-        let analysis = mock.analysis();
-
-        let refs = analysis.find_all_refs(pos, None).unwrap().unwrap();
+        let refs = analysis.find_all_refs(pos).unwrap().unwrap();
         assert_eq!(refs.len(), 3);
-
-        let refs =
-            analysis.find_all_refs(pos, Some(SearchScope::single_file(bar))).unwrap().unwrap();
-        assert_eq!(refs.len(), 2);
     }
 
     fn get_all_refs(text: &str) -> ReferenceSearchResult {
         let (analysis, position) = single_file_with_position(text);
-        analysis.find_all_refs(position, None).unwrap().unwrap()
+        analysis.find_all_refs(position).unwrap().unwrap()
     }
 }
diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs
index ee6e73e1bf..0e2e088e0a 100644
--- a/crates/ra_ide_api/src/references/rename.rs
+++ b/crates/ra_ide_api/src/references/rename.rs
@@ -110,7 +110,7 @@ fn rename_reference(
     position: FilePosition,
     new_name: &str,
 ) -> Option<RangeInfo<SourceChange>> {
-    let RangeInfo { range, info: refs } = find_all_refs(db, position, None)?;
+    let RangeInfo { range, info: refs } = find_all_refs(db, position)?;
 
     let edit = refs
         .into_iter()
@@ -255,13 +255,13 @@ mod tests {
         "#;
 
         let (analysis, pos) = analysis_and_position(code);
-        let refs = analysis.find_all_refs(pos, None).unwrap().unwrap();
+        let refs = analysis.find_all_refs(pos).unwrap().unwrap();
         assert_eq!(refs.len(), 3);
     }
 
     fn get_all_refs(text: &str) -> ReferenceSearchResult {
         let (analysis, position) = single_file_with_position(text);
-        analysis.find_all_refs(position, None).unwrap().unwrap()
+        analysis.find_all_refs(position).unwrap().unwrap()
     }
 
     #[test]
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs
index b6eb248b74..21e667c83b 100644
--- a/crates/ra_ide_api/src/references/search_scope.rs
+++ b/crates/ra_ide_api/src/references/search_scope.rs
@@ -2,84 +2,33 @@
 //! For `pub(crate)` things it's a crate, for `pub` things it's a crate and dependant crates.
 //! In some cases, the location of the references is known to within a `TextRange`,
 //! e.g. for things like local variables.
-use std::mem;
 
 use hir::{DefWithBody, HasSource, ModuleSource};
 use ra_db::{FileId, SourceDatabase, SourceDatabaseExt};
 use ra_prof::profile;
 use ra_syntax::{AstNode, TextRange};
-use rustc_hash::FxHashMap;
+use rustc_hash::FxHashSet;
 
 use crate::db::RootDatabase;
 
 use super::{NameDefinition, NameKind};
 
-pub struct SearchScope {
-    entries: FxHashMap<FileId, Option<TextRange>>,
-}
-
-impl SearchScope {
-    fn new(entries: FxHashMap<FileId, Option<TextRange>>) -> SearchScope {
-        SearchScope { entries }
-    }
-    pub fn single_file(file: FileId) -> SearchScope {
-        SearchScope::new(std::iter::once((file, None)).collect())
-    }
-    pub(crate) fn intersection(&self, other: &SearchScope) -> SearchScope {
-        let (mut small, mut large) = (&self.entries, &other.entries);
-        if small.len() > large.len() {
-            mem::swap(&mut small, &mut large)
-        }
-
-        let res = small
-            .iter()
-            .filter_map(|(file_id, r1)| {
-                let r2 = large.get(file_id)?;
-                let r = intersect_ranges(*r1, *r2)?;
-                Some((*file_id, r))
-            })
-            .collect();
-        return SearchScope::new(res);
-
-        fn intersect_ranges(
-            r1: Option<TextRange>,
-            r2: Option<TextRange>,
-        ) -> Option<Option<TextRange>> {
-            match (r1, r2) {
-                (None, r) | (r, None) => Some(r),
-                (Some(r1), Some(r2)) => {
-                    let r = r1.intersection(&r2)?;
-                    Some(Some(r))
-                }
-            }
-        }
-    }
-}
-
-impl IntoIterator for SearchScope {
-    type Item = (FileId, Option<TextRange>);
-    type IntoIter = std::collections::hash_map::IntoIter<FileId, Option<TextRange>>;
-    fn into_iter(self) -> Self::IntoIter {
-        self.entries.into_iter()
-    }
-}
-
 impl NameDefinition {
-    pub(crate) fn search_scope(&self, db: &RootDatabase) -> SearchScope {
+    pub(crate) fn search_scope(&self, db: &RootDatabase) -> FxHashSet<(FileId, Option<TextRange>)> {
         let _p = profile("search_scope");
 
         let module_src = self.container.definition_source(db);
         let file_id = module_src.file_id.original_file(db);
 
         if let NameKind::Pat((def, _)) = self.kind {
-            let mut res = FxHashMap::default();
+            let mut res = FxHashSet::default();
             let range = match def {
                 DefWithBody::Function(f) => f.source(db).ast.syntax().text_range(),
                 DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(),
                 DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(),
             };
-            res.insert(file_id, Some(range));
-            return SearchScope::new(res);
+            res.insert((file_id, Some(range)));
+            return res;
         }
 
         let vis =
@@ -87,37 +36,37 @@ impl NameDefinition {
 
         if vis.as_str() == "pub(super)" {
             if let Some(parent_module) = self.container.parent(db) {
-                let mut res = FxHashMap::default();
+                let mut files = FxHashSet::default();
                 let parent_src = parent_module.definition_source(db);
                 let file_id = parent_src.file_id.original_file(db);
 
                 match parent_src.ast {
                     ModuleSource::Module(m) => {
                         let range = Some(m.syntax().text_range());
-                        res.insert(file_id, range);
+                        files.insert((file_id, range));
                     }
                     ModuleSource::SourceFile(_) => {
-                        res.insert(file_id, None);
-                        res.extend(parent_module.children(db).map(|m| {
+                        files.insert((file_id, None));
+                        files.extend(parent_module.children(db).map(|m| {
                             let src = m.definition_source(db);
                             (src.file_id.original_file(db), None)
                         }));
                     }
                 }
-                return SearchScope::new(res);
+                return files;
             }
         }
 
         if vis.as_str() != "" {
             let source_root_id = db.file_source_root(file_id);
             let source_root = db.source_root(source_root_id);
-            let mut res =
-                source_root.walk().map(|id| (id.into(), None)).collect::<FxHashMap<_, _>>();
+            let mut files =
+                source_root.walk().map(|id| (id.into(), None)).collect::<FxHashSet<_>>();
 
             // FIXME: add "pub(in path)"
 
             if vis.as_str() == "pub(crate)" {
-                return SearchScope::new(res);
+                return files;
             }
             if vis.as_str() == "pub" {
                 let krate = self.container.krate(db).unwrap();
@@ -128,19 +77,19 @@ impl NameDefinition {
                         let root_file = crate_graph.crate_root(crate_id);
                         let source_root_id = db.file_source_root(root_file);
                         let source_root = db.source_root(source_root_id);
-                        res.extend(source_root.walk().map(|id| (id.into(), None)));
+                        files.extend(source_root.walk().map(|id| (id.into(), None)));
                     }
                 }
-                return SearchScope::new(res);
+                return files;
             }
         }
 
-        let mut res = FxHashMap::default();
+        let mut res = FxHashSet::default();
         let range = match module_src.ast {
             ModuleSource::Module(m) => Some(m.syntax().text_range()),
             ModuleSource::SourceFile(_) => None,
         };
-        res.insert(file_id, range);
-        SearchScope::new(res)
+        res.insert((file_id, range));
+        res
     }
 }
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index a29971d107..e65f075a6d 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,9 +9,7 @@ use lsp_types::{
     Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, PrepareRenameResponse,
     Range, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
 };
-use ra_ide_api::{
-    AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind, SearchScope,
-};
+use ra_ide_api::{AssistId, FileId, FilePosition, FileRange, Query, Runnable, RunnableKind};
 use ra_prof::profile;
 use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
 use rustc_hash::FxHashMap;
@@ -487,7 +485,7 @@ pub fn handle_references(
     let _p = profile("handle_references");
     let position = params.text_document_position.try_conv_with(&world)?;
 
-    let refs = match world.analysis().find_all_refs(position, None)? {
+    let refs = match world.analysis().find_all_refs(position)? {
         None => return Ok(None),
         Some(refs) => refs,
     };
@@ -750,10 +748,7 @@ pub fn handle_document_highlight(
     let file_id = params.text_document.try_conv_with(&world)?;
     let line_index = world.analysis().file_line_index(file_id)?;
 
-    let refs = match world
-        .analysis()
-        .find_all_refs(params.try_conv_with(&world)?, Some(SearchScope::single_file(file_id)))?
-    {
+    let refs = match world.analysis().find_all_refs(params.try_conv_with(&world)?)? {
         None => return Ok(None),
         Some(refs) => refs,
     };
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 948b867192..bf3a901195 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -8,7 +8,7 @@
 mod gen_syntax;
 mod gen_parser_tests;
 
-use std::{fs, path::Path};
+use std::{fs, mem, path::Path};
 
 use crate::Result;
 
@@ -44,3 +44,26 @@ pub fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
     fs::write(path, contents)?;
     Ok(())
 }
+
+fn extract_comment_blocks(text: &str) -> Vec<Vec<String>> {
+    let mut res = Vec::new();
+
+    let prefix = "// ";
+    let lines = text.lines().map(str::trim_start);
+
+    let mut block = vec![];
+    for line in lines {
+        let is_comment = line.starts_with(prefix);
+        if is_comment {
+            block.push(line[prefix.len()..].to_string());
+        } else {
+            if !block.is_empty() {
+                res.push(mem::replace(&mut block, Vec::new()))
+            }
+        }
+    }
+    if !block.is_empty() {
+        res.push(mem::replace(&mut block, Vec::new()))
+    }
+    res
+}


Test patch:
diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs
index 0f550d9488..db1e59dacc 100644
--- a/xtask/src/codegen/gen_parser_tests.rs
+++ b/xtask/src/codegen/gen_parser_tests.rs
@@ -3,12 +3,12 @@
 
 use std::{
     collections::HashMap,
-    fs,
+    fs, iter,
     path::{Path, PathBuf},
 };
 
 use crate::{
-    codegen::{self, update, Mode},
+    codegen::{self, extract_comment_blocks, update, Mode},
     project_root, Result,
 };
 
@@ -56,48 +56,29 @@ struct Tests {
     pub err: HashMap<String, Test>,
 }
 
-fn collect_tests(s: &str) -> Vec<(usize, Test)> {
-    let mut res = vec![];
-    let prefix = "// ";
-    let lines = s.lines().map(str::trim_start).enumerate();
-
-    let mut block = vec![];
-    for (line_idx, line) in lines {
-        let is_comment = line.starts_with(prefix);
-        if is_comment {
-            block.push((line_idx, &line[prefix.len()..]));
+fn collect_tests(s: &str) -> Vec<Test> {
+    let mut res = Vec::new();
+    for comment_block in extract_comment_blocks(s) {
+        let first_line = &comment_block[0];
+        let (name, ok) = if first_line.starts_with("test ") {
+            let name = first_line["test ".len()..].to_string();
+            (name, true)
+        } else if first_line.starts_with("test_err ") {
+            let name = first_line["test_err ".len()..].to_string();
+            (name, false)
         } else {
-            process_block(&mut res, &block);
-            block.clear();
-        }
-    }
-    process_block(&mut res, &block);
-    return res;
-
-    fn process_block(acc: &mut Vec<(usize, Test)>, block: &[(usize, &str)]) {
-        if block.is_empty() {
-            return;
-        }
-        let mut ok = true;
-        let mut block = block.iter();
-        let (start_line, name) = loop {
-            match block.next() {
-                Some(&(idx, line)) if line.starts_with("test ") => {
-                    break (idx, line["test ".len()..].to_string());
-                }
-                Some(&(idx, line)) if line.starts_with("test_err ") => {
-                    ok = false;
-                    break (idx, line["test_err ".len()..].to_string());
-                }
-                Some(_) => (),
-                None => return,
-            }
+            continue;
         };
-        let text: String =
-            block.map(|(_, line)| *line).chain(std::iter::once("")).collect::<Vec<_>>().join("\n");
+        let text: String = comment_block[1..]
+            .iter()
+            .cloned()
+            .chain(iter::once(String::new()))
+            .collect::<Vec<_>>()
+            .join("\n");
         assert!(!text.trim().is_empty() && text.ends_with('\n'));
-        acc.push((start_line, Test { name, text, ok }))
+        res.push(Test { name, text, ok })
     }
+    res
 }
 
 fn tests_from_dir(dir: &Path) -> Result<Tests> {
@@ -118,7 +99,7 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> {
     fn process_file(res: &mut Tests, path: &Path) -> Result<()> {
         let text = fs::read_to_string(path)?;
 
-        for (_, test) in collect_tests(&text) {
+        for test in collect_tests(&text) {
             if test.ok {
                 if let Some(old_test) = res.ok.insert(test.name.clone(), test) {
                     Err(format!("Duplicate test: {}", old_test.name))?