mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 13:13:43 +00:00
dev: convert all syntax-level request and check main state before requesting (#67)
This commit is contained in:
parent
5d123221db
commit
2fe992e933
6 changed files with 78 additions and 85 deletions
|
@ -3,6 +3,7 @@ use typst_ts_compiler::NotifyApi;
|
|||
use crate::{
|
||||
prelude::*,
|
||||
syntax::{get_lexical_hierarchy, LexicalHierarchy, LexicalScopeKind},
|
||||
SyntaxRequest,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -10,25 +11,29 @@ pub struct SymbolRequest {
|
|||
pub pattern: Option<String>,
|
||||
}
|
||||
|
||||
impl SymbolRequest {
|
||||
pub fn request(
|
||||
self,
|
||||
world: &TypstSystemWorld,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Vec<SymbolInformation>> {
|
||||
impl SyntaxRequest for SymbolRequest {
|
||||
type Response = Vec<SymbolInformation>;
|
||||
|
||||
fn request(self, ctx: &mut AnalysisContext) -> Option<Self::Response> {
|
||||
// todo: expose source
|
||||
|
||||
let mut symbols = vec![];
|
||||
|
||||
world.iter_dependencies(&mut |path, _| {
|
||||
let Ok(source) = get_suitable_source_in_workspace(world, path) else {
|
||||
ctx.world.iter_dependencies(&mut |path, _| {
|
||||
let Ok(source) = ctx.source_by_path(path) else {
|
||||
return;
|
||||
};
|
||||
let uri = Url::from_file_path(path).unwrap();
|
||||
let res = get_lexical_hierarchy(source.clone(), LexicalScopeKind::Symbol).and_then(
|
||||
|symbols| {
|
||||
self.pattern.as_ref().map(|pattern| {
|
||||
filter_document_symbols(&symbols, pattern, &source, &uri, position_encoding)
|
||||
filter_document_symbols(
|
||||
&symbols,
|
||||
pattern,
|
||||
&source,
|
||||
&uri,
|
||||
ctx.position_encoding(),
|
||||
)
|
||||
})
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue