dev: convert all syntax-level request and check main state before requesting (#67)

This commit is contained in:
Myriad-Dreamin 2024-03-18 17:36:43 +08:00 committed by GitHub
parent 5d123221db
commit 2fe992e933
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 78 additions and 85 deletions

View file

@ -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(),
)
})
},
);