mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-02 17:32:16 +00:00
feat: create query crate
This commit is contained in:
parent
7e9bddb763
commit
9af8eb4b52
29 changed files with 1312 additions and 1341 deletions
50
crates/tinymist-query/src/symbol.rs
Normal file
50
crates/tinymist-query/src/symbol.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use typst_ts_compiler::NotifyApi;
|
||||
|
||||
use crate::document_symbol::get_document_symbols;
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SymbolRequest {
|
||||
pub pattern: Option<String>,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn symbol(
|
||||
world: &TypstSystemWorld,
|
||||
SymbolRequest {
|
||||
pattern,
|
||||
position_encoding,
|
||||
}: SymbolRequest,
|
||||
) -> Option<Vec<SymbolInformation>> {
|
||||
// todo: expose source
|
||||
|
||||
let mut symbols = vec![];
|
||||
|
||||
world.iter_dependencies(&mut |path, _| {
|
||||
let Ok(source) = get_suitable_source_in_workspace(world, path) else {
|
||||
return;
|
||||
};
|
||||
let uri = Url::from_file_path(path).unwrap();
|
||||
let res = get_document_symbols(source, uri, position_encoding).and_then(|symbols| {
|
||||
pattern
|
||||
.as_ref()
|
||||
.map(|pattern| filter_document_symbols(symbols, pattern))
|
||||
});
|
||||
|
||||
if let Some(mut res) = res {
|
||||
symbols.append(&mut res)
|
||||
}
|
||||
});
|
||||
|
||||
Some(symbols)
|
||||
}
|
||||
|
||||
fn filter_document_symbols(
|
||||
symbols: Vec<SymbolInformation>,
|
||||
query_string: &str,
|
||||
) -> Vec<SymbolInformation> {
|
||||
symbols
|
||||
.into_iter()
|
||||
.filter(|e| e.name.contains(query_string))
|
||||
.collect()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue