mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
allow compiling ra_ide_api on wasm
This commit is contained in:
parent
c733993658
commit
4d81432213
6 changed files with 76 additions and 12 deletions
|
@ -38,6 +38,7 @@ use ra_syntax::{
|
|||
SyntaxKind::{self, *},
|
||||
SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent,
|
||||
};
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{db::RootDatabase, FileId, Query};
|
||||
|
@ -79,10 +80,17 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol>
|
|||
|
||||
let buf: Vec<Arc<SymbolIndex>> = if query.libs {
|
||||
let snap = Snap(db.snapshot());
|
||||
db.library_roots()
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
let buf = db
|
||||
.library_roots()
|
||||
.par_iter()
|
||||
.map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id))
|
||||
.collect()
|
||||
.collect();
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
let buf = db.library_roots().iter().map(|&lib_id| snap.0.library_symbols(lib_id)).collect();
|
||||
|
||||
buf
|
||||
} else {
|
||||
let mut files = Vec::new();
|
||||
for &root in db.local_roots().iter() {
|
||||
|
@ -91,7 +99,14 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol>
|
|||
}
|
||||
|
||||
let snap = Snap(db.snapshot());
|
||||
files.par_iter().map_with(snap, |db, &file_id| db.0.file_symbols(file_id)).collect()
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
let buf =
|
||||
files.par_iter().map_with(snap, |db, &file_id| db.0.file_symbols(file_id)).collect();
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
let buf = files.iter().map(|&file_id| snap.0.file_symbols(file_id)).collect();
|
||||
|
||||
buf
|
||||
};
|
||||
query.search(&buf)
|
||||
}
|
||||
|
@ -135,9 +150,12 @@ impl SymbolIndex {
|
|||
fn cmp_key<'a>(s1: &'a FileSymbol) -> impl Ord + 'a {
|
||||
unicase::Ascii::new(s1.name.as_str())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
symbols.par_sort_by(|s1, s2| cmp_key(s1).cmp(&cmp_key(s2)));
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
symbols.sort_by(|s1, s2| cmp_key(s1).cmp(&cmp_key(s2)));
|
||||
|
||||
let mut builder = fst::MapBuilder::memory();
|
||||
|
||||
let mut last_batch_start = 0;
|
||||
|
@ -169,6 +187,7 @@ impl SymbolIndex {
|
|||
self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm"))]
|
||||
pub(crate) fn for_files(
|
||||
files: impl ParallelIterator<Item = (FileId, Parse<ast::SourceFile>)>,
|
||||
) -> SymbolIndex {
|
||||
|
@ -178,6 +197,16 @@ impl SymbolIndex {
|
|||
SymbolIndex::new(symbols)
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
pub(crate) fn for_files(
|
||||
files: impl Iterator<Item = (FileId, Parse<ast::SourceFile>)>,
|
||||
) -> SymbolIndex {
|
||||
let symbols = files
|
||||
.flat_map(|(file_id, file)| source_file_to_file_symbols(&file.tree(), file_id))
|
||||
.collect::<Vec<_>>();
|
||||
SymbolIndex::new(symbols)
|
||||
}
|
||||
|
||||
fn range_to_map_value(start: usize, end: usize) -> u64 {
|
||||
debug_assert![start <= (std::u32::MAX as usize)];
|
||||
debug_assert![end <= (std::u32::MAX as usize)];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue