about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-12-12 22:43:33 +0100
committerLukas Wirth <lukastw97@gmail.com>2023-12-12 22:53:40 +0100
commit7cc6b0f2e98ee5045e9ecc6c7cb9c2183fbc9b50 (patch)
tree1498bbcd15630aa83de96c616d659bd960910405
parentc209b5f97c35c6d5e9a0f6868edbed1665acbdc7 (diff)
downloadrust-7cc6b0f2e98ee5045e9ecc6c7cb9c2183fbc9b50.tar.gz
rust-7cc6b0f2e98ee5045e9ecc6c7cb9c2183fbc9b50.zip
Partially revert #16101
-rw-r--r--crates/hir-def/src/import_map.rs15
-rw-r--r--crates/ide-db/src/items_locator.rs3
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs44
3 files changed, 47 insertions, 15 deletions
diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs
index 62ee45bff62..fbd754c30f5 100644
--- a/crates/hir-def/src/import_map.rs
+++ b/crates/hir-def/src/import_map.rs
@@ -413,22 +413,17 @@ pub fn search_dependencies(
     while let Some((_, indexed_values)) = stream.next() {
         for &IndexedValue { index, value } in indexed_values {
             let import_map = &import_maps[index];
-            let importables = &import_map.importables[value as usize..];
-
-            // Find the first item in this group that has a matching assoc mode and slice the rest away
-            let Some(importable) =
-                importables.iter().position(|it| query.matches_assoc_mode(import_map.map[it].1))
-            else {
+            let importables @ [importable, ..] = &import_map.importables[value as usize..] else {
                 continue;
             };
-            let importables @ [importable, ..] = &importables[importable..] else {
+            let &(ref importable_data, is_trait_assoc_item) = &import_map.map[importable];
+            if !query.matches_assoc_mode(is_trait_assoc_item) {
                 continue;
-            };
+            }
 
             // Fetch all the known names of this importable item (to handle import aliases/renames)
             common_importable_data_scratch.extend(
-                import_map.map[importable]
-                    .0
+                importable_data
                     .iter()
                     .filter(|&info| query.import_matches(info, true))
                     // Name shared by the importable items in this group.
diff --git a/crates/ide-db/src/items_locator.rs b/crates/ide-db/src/items_locator.rs
index 93ea08b7001..4a5d234f73d 100644
--- a/crates/ide-db/src/items_locator.rs
+++ b/crates/ide-db/src/items_locator.rs
@@ -37,7 +37,8 @@ pub fn items_with_name<'a>(
         | NameToImport::Exact(exact_name, case_sensitive) => {
             let mut local_query = symbol_index::Query::new(exact_name.clone());
             let mut external_query =
-                import_map::Query::new(exact_name).assoc_search_mode(assoc_item_search);
+                // import_map::Query::new(exact_name).assoc_search_mode(assoc_item_search);
+                import_map::Query::new(exact_name);
             if prefix {
                 local_query.prefix();
                 external_query = external_query.prefix();
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 3d0ebf9bde6..41ff17f5e43 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -109,10 +109,46 @@ fn integrated_completion_benchmark() {
         vfs.file_id(&path).unwrap_or_else(|| panic!("can't find virtual file for {path}"))
     };
 
+    // kick off parsing and index population
+
+    let completion_offset = {
+        let _it = stdx::timeit("change");
+        let mut text = host.analysis().file_text(file_id).unwrap().to_string();
+        let completion_offset =
+            patch(&mut text, "db.struct_data(self.id)", "sel;\ndb.struct_data(self.id)")
+                + "sel".len();
+        let mut change = Change::new();
+        change.change_file(file_id, Some(Arc::from(text)));
+        host.apply_change(change);
+        completion_offset
+    };
+
     {
-        let _it = stdx::timeit("initial");
+        let _span = profile::cpu_span();
         let analysis = host.analysis();
-        analysis.highlight_as_html(file_id, false).unwrap();
+        let config = CompletionConfig {
+            enable_postfix_completions: true,
+            enable_imports_on_the_fly: true,
+            enable_self_on_the_fly: true,
+            enable_private_editable: true,
+            full_function_signatures: false,
+            callable: Some(CallableSnippets::FillArguments),
+            snippet_cap: SnippetCap::new(true),
+            insert_use: InsertUseConfig {
+                granularity: ImportGranularity::Crate,
+                prefix_kind: hir::PrefixKind::ByCrate,
+                enforce_granularity: true,
+                group: true,
+                skip_glob_imports: true,
+            },
+            snippets: Vec::new(),
+            prefer_no_std: false,
+            prefer_prelude: true,
+            limit: None,
+        };
+        let position =
+            FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
+        analysis.completions(&config, position, None).unwrap();
     }
 
     profile::init_from("*>5");
@@ -122,8 +158,8 @@ fn integrated_completion_benchmark() {
         let _it = stdx::timeit("change");
         let mut text = host.analysis().file_text(file_id).unwrap().to_string();
         let completion_offset =
-            patch(&mut text, "db.struct_data(self.id)", "sel;\ndb.struct_data(self.id)")
-                + "sel".len();
+            patch(&mut text, "sel;\ndb.struct_data(self.id)", ";sel;\ndb.struct_data(self.id)")
+                + ";sel".len();
         let mut change = Change::new();
         change.change_file(file_id, Some(Arc::from(text)));
         host.apply_change(change);