aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--crates/ra_analysis/Cargo.toml1
-rw-r--r--crates/ra_analysis/src/symbol_index.rs29
3 files changed, 27 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5f82e92f4..5f35f2872 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -680,6 +680,7 @@ dependencies = [
680 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 680 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
681 "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)", 681 "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
682 "test_utils 0.1.0", 682 "test_utils 0.1.0",
683 "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
683] 684]
684 685
685[[package]] 686[[package]]
@@ -1354,6 +1355,14 @@ dependencies = [
1354] 1355]
1355 1356
1356[[package]] 1357[[package]]
1358name = "unicase"
1359version = "2.2.0"
1360source = "registry+https://github.com/rust-lang/crates.io-index"
1361dependencies = [
1362 "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1363]
1364
1365[[package]]
1357name = "unicode-bidi" 1366name = "unicode-bidi"
1358version = "0.3.4" 1367version = "0.3.4"
1359source = "registry+https://github.com/rust-lang/crates.io-index" 1368source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1616,6 +1625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1616"checksum unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ca47cbb09fb5fcd066b5867d11dc528302fa465277882797d6a836e1ee6f9e" 1625"checksum unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ca47cbb09fb5fcd066b5867d11dc528302fa465277882797d6a836e1ee6f9e"
1617"checksum unic-ucd-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "48f1a08ce0409a9e391b88d1930118eec48af12742fc538bcec55f775865776e" 1626"checksum unic-ucd-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "48f1a08ce0409a9e391b88d1930118eec48af12742fc538bcec55f775865776e"
1618"checksum unic-ucd-version 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1f5e6c6c53c2d0ece4a5964bc55fcff8602153063cb4fab20958ff32998ff6" 1627"checksum unic-ucd-version 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1f5e6c6c53c2d0ece4a5964bc55fcff8602153063cb4fab20958ff32998ff6"
1628"checksum unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d3218ea14b4edcaccfa0df0a64a3792a2c32cc706f1b336e48867f9d3147f90"
1619"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" 1629"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
1620"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" 1630"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25"
1621"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" 1631"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml
index c0174cdc5..7a4fdaed9 100644
--- a/crates/ra_analysis/Cargo.toml
+++ b/crates/ra_analysis/Cargo.toml
@@ -13,6 +13,7 @@ fst = "0.3.1"
13salsa = "0.9.0" 13salsa = "0.9.0"
14rustc-hash = "1.0" 14rustc-hash = "1.0"
15parking_lot = "0.7.0" 15parking_lot = "0.7.0"
16unicase = "2.2.0"
16 17
17ra_syntax = { path = "../ra_syntax" } 18ra_syntax = { path = "../ra_syntax" }
18ra_editor = { path = "../ra_editor" } 19ra_editor = { path = "../ra_editor" }
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index b355b14ed..55caae5c2 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -20,6 +20,7 @@
20//! file in the current workspace, and run a query aginst the union of all 20//! file in the current workspace, and run a query aginst the union of all
21//! thouse fsts. 21//! thouse fsts.
22use std::{ 22use std::{
23 cmp::Ordering,
23 hash::{Hash, Hasher}, 24 hash::{Hash, Hasher},
24 sync::Arc, 25 sync::Arc,
25}; 26};
@@ -111,6 +112,17 @@ impl Hash for SymbolIndex {
111} 112}
112 113
113impl SymbolIndex { 114impl SymbolIndex {
115 fn new(mut symbols: Vec<FileSymbol>) -> SymbolIndex {
116 fn cmp(s1: &FileSymbol, s2: &FileSymbol) -> Ordering {
117 unicase::Ascii::new(s1.name.as_str()).cmp(&unicase::Ascii::new(s2.name.as_str()))
118 }
119 symbols.par_sort_by(cmp);
120 symbols.dedup_by(|s1, s2| cmp(s1, s2) == Ordering::Equal);
121 let names = symbols.iter().map(|it| it.name.as_str().to_lowercase());
122 let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
123 SymbolIndex { symbols, map }
124 }
125
114 pub(crate) fn len(&self) -> usize { 126 pub(crate) fn len(&self) -> usize {
115 self.symbols.len() 127 self.symbols.len()
116 } 128 }
@@ -118,28 +130,19 @@ impl SymbolIndex {
118 pub(crate) fn for_files( 130 pub(crate) fn for_files(
119 files: impl ParallelIterator<Item = (FileId, SourceFileNode)>, 131 files: impl ParallelIterator<Item = (FileId, SourceFileNode)>,
120 ) -> SymbolIndex { 132 ) -> SymbolIndex {
121 let mut symbols = files 133 let symbols = files
122 .flat_map(|(file_id, file)| { 134 .flat_map(|(file_id, file)| {
123 file.syntax() 135 file.syntax()
124 .descendants() 136 .descendants()
125 .filter_map(to_symbol) 137 .filter_map(to_symbol)
126 .map(move |(name, ptr)| { 138 .map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
127 (
128 name.as_str().to_lowercase(),
129 FileSymbol { name, ptr, file_id },
130 )
131 })
132 .collect::<Vec<_>>() 139 .collect::<Vec<_>>()
133 }) 140 })
134 .collect::<Vec<_>>(); 141 .collect::<Vec<_>>();
135 symbols.par_sort_by(|s1, s2| s1.0.cmp(&s2.0)); 142 SymbolIndex::new(symbols)
136 symbols.dedup_by(|s1, s2| s1.0 == s2.0);
137 let (names, symbols): (Vec<String>, Vec<FileSymbol>) = symbols.into_iter().unzip();
138 let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
139 SymbolIndex { symbols, map }
140 } 143 }
141 144
142 pub(crate) fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex { 145 fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
143 SymbolIndex::for_files(rayon::iter::once((file_id, file))) 146 SymbolIndex::for_files(rayon::iter::once((file_id, file)))
144 } 147 }
145} 148}