mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 21:23:45 +00:00
refactor: reduce source cache and mutability (#693)
* dev: reduce source cache and mutability * dev: update common imports
This commit is contained in:
parent
4d23b57785
commit
de130dcc2c
29 changed files with 116 additions and 224 deletions
|
@ -1,12 +1,10 @@
|
|||
use std::{ffi::OsStr, sync::Arc};
|
||||
use std::ffi::OsStr;
|
||||
|
||||
use ecow::EcoVec;
|
||||
use typst::foundations::Bytes;
|
||||
use yaml_rust2::{parser::Event, parser::MarkedEventReceiver, scanner::Marker};
|
||||
|
||||
use super::prelude::*;
|
||||
|
||||
use yaml_rust2::{parser::Event, parser::MarkedEventReceiver, scanner::Marker};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct BibSpanned<T> {
|
||||
value: T,
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
//! Hybrid analysis for function calls.
|
||||
|
||||
use typst::syntax::SyntaxNode;
|
||||
|
||||
use super::prelude::*;
|
||||
use super::{Signature, StrRef};
|
||||
use crate::{
|
||||
analysis::{analyze_signature, PrimarySignature, SignatureTarget},
|
||||
prelude::*,
|
||||
};
|
||||
use crate::analysis::{analyze_signature, PrimarySignature, SignatureTarget};
|
||||
|
||||
/// Describes kind of a parameter.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -47,7 +43,7 @@ pub fn analyze_call(
|
|||
source: Source,
|
||||
node: LinkedNode,
|
||||
) -> Option<Arc<CallInfo>> {
|
||||
trace!("func call found: {:?}", node);
|
||||
log::trace!("func call found: {:?}", node);
|
||||
let f = node.cast::<ast::FuncCall>()?;
|
||||
|
||||
let callee = f.callee();
|
||||
|
@ -74,7 +70,7 @@ pub fn analyze_call_no_cache(
|
|||
args: ast::Args<'_>,
|
||||
) -> Option<CallInfo> {
|
||||
let signature = analyze_signature(ctx, SignatureTarget::SyntaxFast(source, callee_node))?;
|
||||
trace!("got signature {signature:?}");
|
||||
log::trace!("got signature {signature:?}");
|
||||
|
||||
let mut info = CallInfo {
|
||||
arg_mapping: HashMap::new(),
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
//! Analyze color expressions in a source file.
|
||||
use std::{ops::Range, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use lsp_types::ColorInformation;
|
||||
use typst::{
|
||||
syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, Source, SyntaxKind,
|
||||
},
|
||||
visualize::Color,
|
||||
};
|
||||
use typst::visualize::Color;
|
||||
|
||||
use crate::AnalysisContext;
|
||||
use super::prelude::*;
|
||||
|
||||
/// Get color expressions from a source.
|
||||
pub fn get_color_exprs(ctx: &mut AnalysisContext, src: &Source) -> Option<Vec<ColorInformation>> {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
//! Static analysis for def-use relations.
|
||||
|
||||
use std::{collections::HashMap, ops::Range, sync::Arc};
|
||||
|
||||
use ecow::{EcoString, EcoVec};
|
||||
use reflexo::hash::hash128;
|
||||
|
||||
use super::{prelude::*, ImportInfo};
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||
use std::{collections::HashSet, ops::Deref};
|
||||
|
||||
use comemo::{Track, Tracked};
|
||||
use lsp_types::Url;
|
||||
use once_cell::sync::OnceCell;
|
||||
use reflexo::hash::{hash128, FxDashMap};
|
||||
use reflexo::{debug_loc::DataSource, ImmutPath};
|
||||
|
@ -10,19 +11,18 @@ use tinymist_world::DETACHED_ENTRY;
|
|||
use typst::diag::{eco_format, At, FileError, FileResult, PackageError, SourceResult};
|
||||
use typst::engine::Route;
|
||||
use typst::eval::{Eval, Tracer};
|
||||
use typst::foundations::{self, Bytes, Func, Module, Styles};
|
||||
use typst::foundations::{Bytes, Module, Styles};
|
||||
use typst::layout::Position;
|
||||
use typst::syntax::{package::PackageSpec, Span, VirtualPath};
|
||||
use typst::{model::Document, text::Font};
|
||||
use typst_shim::syntax::LinkedNodeExt;
|
||||
|
||||
use crate::analysis::prelude::*;
|
||||
use crate::analysis::{
|
||||
analyze_bib, analyze_expr_, analyze_import_, analyze_signature, post_type_check, BibInfo,
|
||||
DefUseInfo, DefinitionLink, DocString, IdentRef, ImportInfo, PathPreference, Signature,
|
||||
SignatureTarget, Ty, TypeScheme,
|
||||
DefUseInfo, DefinitionLink, DocString, ImportInfo, PathPreference, Signature, SignatureTarget,
|
||||
Ty, TypeScheme,
|
||||
};
|
||||
use crate::docs::{DocStringKind, SignatureDocs};
|
||||
use crate::prelude::*;
|
||||
use crate::syntax::{
|
||||
construct_module_dependencies, find_expr_in_import, get_deref_target, resolve_id_by_path,
|
||||
scan_workspace_files, DerefTarget, LexicalHierarchy, ModuleDependency,
|
||||
|
@ -86,7 +86,7 @@ pub struct AnalysisGlobalCaches {
|
|||
type_check: FxDashMap<u128, (u64, Option<Arc<TypeScheme>>)>,
|
||||
static_signatures: FxDashMap<u128, (u64, Source, usize, Option<Signature>)>,
|
||||
docstrings: FxDashMap<u128, Option<Arc<DocString>>>,
|
||||
signatures: FxDashMap<u128, (u64, foundations::Func, Option<Signature>)>,
|
||||
signatures: FxDashMap<u128, (u64, Func, Option<Signature>)>,
|
||||
}
|
||||
|
||||
/// A cache for all level of analysis results of a module.
|
||||
|
@ -103,25 +103,11 @@ pub struct AnalysisCaches {
|
|||
/// You should not holds across requests, because source code may change.
|
||||
#[derive(Default)]
|
||||
pub struct ModuleAnalysisCache {
|
||||
file: OnceCell<FileResult<Bytes>>,
|
||||
source: OnceCell<FileResult<Source>>,
|
||||
def_use: OnceCell<Option<Arc<DefUseInfo>>>,
|
||||
type_check: OnceCell<Option<Arc<TypeScheme>>>,
|
||||
}
|
||||
|
||||
impl ModuleAnalysisCache {
|
||||
/// Get the bytes content of a file.
|
||||
pub fn file(&self, ctx: &AnalysisContext, file_id: TypstFileId) -> FileResult<Bytes> {
|
||||
self.file.get_or_init(|| ctx.world().file(file_id)).clone()
|
||||
}
|
||||
|
||||
/// Get the source of a file.
|
||||
pub fn source(&self, ctx: &AnalysisContext, file_id: TypstFileId) -> FileResult<Source> {
|
||||
self.source
|
||||
.get_or_init(|| ctx.world().source(file_id))
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Try to get the def-use information of a file.
|
||||
pub fn def_use(&self) -> Option<Arc<DefUseInfo>> {
|
||||
self.def_use.get().cloned().flatten()
|
||||
|
@ -325,26 +311,23 @@ impl<'w> AnalysisContext<'w> {
|
|||
}
|
||||
|
||||
/// Get the content of a file by file id.
|
||||
pub fn file_by_id(&mut self, id: TypstFileId) -> FileResult<Bytes> {
|
||||
self.get_mut(id);
|
||||
self.get(id).unwrap().file(self, id)
|
||||
pub fn file_by_id(&self, id: TypstFileId) -> FileResult<Bytes> {
|
||||
self.world().file(id)
|
||||
}
|
||||
|
||||
/// Get the source of a file by file id.
|
||||
pub fn source_by_id(&mut self, id: TypstFileId) -> FileResult<Source> {
|
||||
self.get_mut(id);
|
||||
self.get(id).unwrap().source(self, id)
|
||||
pub fn source_by_id(&self, id: TypstFileId) -> FileResult<Source> {
|
||||
self.world().source(id)
|
||||
}
|
||||
|
||||
/// Get the source of a file by file path.
|
||||
pub fn source_by_path(&mut self, p: &Path) -> FileResult<Source> {
|
||||
// todo: source in packages
|
||||
let id = self.file_id_by_path(p)?;
|
||||
self.source_by_id(id)
|
||||
pub fn source_by_path(&self, p: &Path) -> FileResult<Source> {
|
||||
// todo: source cache
|
||||
self.source_by_id(self.file_id_by_path(p)?)
|
||||
}
|
||||
|
||||
/// Get a module by file id.
|
||||
pub fn module_by_id(&mut self, fid: TypstFileId) -> SourceResult<Module> {
|
||||
pub fn module_by_id(&self, fid: TypstFileId) -> SourceResult<Module> {
|
||||
let source = self.source_by_id(fid).at(Span::detached())?;
|
||||
self.module_by_src(source)
|
||||
}
|
||||
|
@ -370,7 +353,7 @@ impl<'w> AnalysisContext<'w> {
|
|||
|
||||
/// Get a syntax object at a position.
|
||||
pub fn deref_syntax_at<'s>(
|
||||
&mut self,
|
||||
&self,
|
||||
source: &'s Source,
|
||||
position: LspPosition,
|
||||
shift: usize,
|
||||
|
@ -381,7 +364,7 @@ impl<'w> AnalysisContext<'w> {
|
|||
|
||||
/// Get a syntax object at a position.
|
||||
pub fn deref_syntax_at_<'s>(
|
||||
&mut self,
|
||||
&self,
|
||||
source: &'s Source,
|
||||
position: LspPosition,
|
||||
shift: usize,
|
||||
|
@ -398,11 +381,6 @@ impl<'w> AnalysisContext<'w> {
|
|||
self.caches.modules.get(&file_id)
|
||||
}
|
||||
|
||||
/// Get the module-level analysis cache of a file.
|
||||
pub fn get_mut(&mut self, file_id: TypstFileId) -> &ModuleAnalysisCache {
|
||||
self.caches.modules.entry(file_id).or_default()
|
||||
}
|
||||
|
||||
/// Fork a new context for searching in the workspace.
|
||||
pub fn fork_for_search<'s>(&'s mut self) -> SearchCtx<'s, 'w> {
|
||||
SearchCtx {
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
//! Import analysis
|
||||
|
||||
use ecow::EcoVec;
|
||||
use typst::{foundations::Value, syntax::LinkedNode, World};
|
||||
use typst_shim::syntax::LinkedNodeExt;
|
||||
|
||||
use crate::{
|
||||
analysis::analyze_import_,
|
||||
syntax::{find_expr_in_import, resolve_id_by_path},
|
||||
};
|
||||
|
||||
pub use super::prelude::*;
|
||||
use super::prelude::*;
|
||||
use crate::analysis::analyze_import_;
|
||||
use crate::syntax::{find_expr_in_import, resolve_id_by_path};
|
||||
|
||||
/// The import information of a source file.
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
//! Analyze color expressions in a source file.
|
||||
use std::ops::Range;
|
||||
|
||||
use typst::syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, Source, SyntaxKind,
|
||||
};
|
||||
use lsp_types::Url;
|
||||
|
||||
use crate::prelude::*;
|
||||
use super::prelude::*;
|
||||
use crate::path_to_url;
|
||||
|
||||
/// Get link expressions from a source.
|
||||
pub fn get_link_exprs(ctx: &mut AnalysisContext, src: &Source) -> Option<Vec<(Range<usize>, Url)>> {
|
||||
|
|
|
@ -1,24 +1,12 @@
|
|||
//! Linked definition analysis
|
||||
|
||||
use std::ops::Range;
|
||||
|
||||
use log::debug;
|
||||
use once_cell::sync::Lazy;
|
||||
use typst::foundations::{IntoValue, Label, Selector, Type};
|
||||
use typst::introspection::Introspector;
|
||||
use typst::model::BibliographyElem;
|
||||
use typst::syntax::FileId as TypstFileId;
|
||||
use typst::{foundations::Value, syntax::Span};
|
||||
use typst_shim::syntax::LinkedNodeExt;
|
||||
|
||||
use super::prelude::*;
|
||||
use crate::{
|
||||
prelude::*,
|
||||
syntax::{
|
||||
find_source_by_expr, get_deref_target, DerefTarget, IdentRef, LexicalKind, LexicalModKind,
|
||||
LexicalVarKind,
|
||||
},
|
||||
};
|
||||
use crate::syntax::{find_source_by_expr, get_deref_target, DerefTarget};
|
||||
use crate::VersionedDocument;
|
||||
|
||||
/// A linked definition in the source code
|
||||
pub struct DefinitionLink {
|
||||
|
@ -145,7 +133,7 @@ fn find_ident_definition(
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
debug!("unsupported kind {kind:?}", kind = use_site.kind());
|
||||
log::debug!("unsupported kind {kind:?}", kind = use_site.kind());
|
||||
None
|
||||
}
|
||||
};
|
||||
|
@ -369,7 +357,7 @@ fn identify_call_convention(target: DynCallTarget) -> CallConvention {
|
|||
}
|
||||
|
||||
fn is_with_func(func_ptr: &Func) -> bool {
|
||||
static WITH_FUNC: Lazy<Option<&'static Func>> = Lazy::new(|| {
|
||||
static WITH_FUNC: LazyLock<Option<&'static Func>> = LazyLock::new(|| {
|
||||
let fn_ty = Type::of::<Func>();
|
||||
let Some(Value::Func(f)) = fn_ty.scope().get("with") else {
|
||||
return None;
|
||||
|
@ -381,7 +369,7 @@ fn is_with_func(func_ptr: &Func) -> bool {
|
|||
}
|
||||
|
||||
fn is_where_func(func_ptr: &Func) -> bool {
|
||||
static WITH_FUNC: Lazy<Option<&'static Func>> = Lazy::new(|| {
|
||||
static WITH_FUNC: LazyLock<Option<&'static Func>> = LazyLock::new(|| {
|
||||
let fn_ty = Type::of::<Func>();
|
||||
let Some(Value::Func(f)) = fn_ty.scope().get("where") else {
|
||||
return None;
|
||||
|
@ -521,7 +509,7 @@ fn value_to_def(
|
|||
name: impl FnOnce() -> Option<EcoString>,
|
||||
name_range: Option<Range<usize>>,
|
||||
) -> Option<DefinitionLink> {
|
||||
let mut def_at = |span: Span| {
|
||||
let def_at = |span: Span| {
|
||||
span.id().and_then(|fid| {
|
||||
let source = ctx.source_by_id(fid).ok()?;
|
||||
Some((fid, source.find(span)?.range()))
|
||||
|
|
|
@ -1,25 +1,14 @@
|
|||
//! Infer more than the principal type of some expression.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use hashbrown::HashSet;
|
||||
use tinymist_derive::BindTyCtx;
|
||||
use typst::{
|
||||
foundations::Func,
|
||||
syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, Span, SyntaxKind,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
adt::interner::Interned,
|
||||
analysis::{ArgsTy, Sig, SigChecker, SigSurfaceKind, TypeBounds},
|
||||
syntax::{get_check_target, get_check_target_by_context, CheckTarget, ParamTarget},
|
||||
AnalysisContext,
|
||||
use super::prelude::*;
|
||||
use super::{
|
||||
ArgsTy, FieldTy, Sig, SigChecker, SigShape, SigSurfaceKind, SigTy, Ty, TyCtx, TyCtxMut,
|
||||
TypeBounds, TypeScheme, TypeVar,
|
||||
};
|
||||
|
||||
use super::{FieldTy, SigShape, SigTy, Ty, TyCtx, TyCtxMut, TypeScheme, TypeVar};
|
||||
use crate::syntax::{get_check_target, get_check_target_by_context, CheckTarget, ParamTarget};
|
||||
|
||||
/// With given type information, check the type of a literal expression again by
|
||||
/// touching the possible related nodes.
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
pub use std::{
|
||||
collections::HashMap,
|
||||
hash::{Hash, Hasher},
|
||||
ops::{Deref, Range},
|
||||
sync::Arc,
|
||||
};
|
||||
pub use core::fmt;
|
||||
pub use std::collections::{BTreeMap, HashMap};
|
||||
pub use std::hash::{Hash, Hasher};
|
||||
pub use std::ops::{Deref, Range};
|
||||
pub use std::path::{Path, PathBuf};
|
||||
pub use std::sync::{Arc, LazyLock};
|
||||
|
||||
pub use comemo::Track;
|
||||
pub use ecow::*;
|
||||
pub use reflexo::vector::ir::DefId;
|
||||
pub use serde::Serialize;
|
||||
pub use typst::syntax::FileId as TypstFileId;
|
||||
pub use typst::syntax::Source;
|
||||
pub use serde::{Deserialize, Serialize};
|
||||
pub use typst::foundations::{Func, Value};
|
||||
pub use typst::syntax::ast::{self, AstNode};
|
||||
pub use typst::syntax::{FileId as TypstFileId, LinkedNode, Source, Span, SyntaxKind, SyntaxNode};
|
||||
pub use typst::World;
|
||||
pub use typst_shim::syntax::LinkedNodeExt;
|
||||
pub use typst_shim::utils::LazyHash;
|
||||
|
||||
pub use super::AnalysisContext;
|
||||
pub use super::SearchCtx;
|
||||
pub use crate::adt::snapshot_map::SnapshotMap;
|
||||
pub(crate) use super::StrRef;
|
||||
pub(crate) use crate::adt::interner::Interned;
|
||||
pub(crate) use crate::syntax::{
|
||||
IdentDef, IdentRef, LexicalHierarchy, LexicalKind, LexicalModKind, LexicalVarKind, ModSrc,
|
||||
};
|
||||
pub use crate::ty::Ty;
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
//! Analysis of function signatures.
|
||||
use core::fmt;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ecow::{eco_format, eco_vec, EcoString, EcoVec};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typst::foundations::ParamInfo;
|
||||
use typst::syntax::Source;
|
||||
use typst::{
|
||||
foundations::{Closure, Func, Value},
|
||||
syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, SyntaxKind,
|
||||
},
|
||||
};
|
||||
use typst_shim::utils::LazyHash;
|
||||
use typst::foundations::{Closure, ParamInfo};
|
||||
|
||||
use super::{IdentRef, StrRef};
|
||||
use crate::adt::interner::Interned;
|
||||
use crate::analysis::{resolve_callee, AnalysisContext};
|
||||
use super::{prelude::*, resolve_callee, SigTy};
|
||||
use crate::docs::UntypedSymbolDocs;
|
||||
use crate::syntax::get_non_strict_def_target;
|
||||
use crate::ty::{SigTy, Ty};
|
||||
use crate::upstream::truncated_repr;
|
||||
|
||||
/// Describes a function parameter.
|
||||
|
|
|
@ -1,28 +1,12 @@
|
|||
//! Type checking on source file
|
||||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use ecow::EcoString;
|
||||
use once_cell::sync::Lazy;
|
||||
use reflexo::vector::ir::DefId;
|
||||
use typst::{
|
||||
foundations::{Func, Value},
|
||||
syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, Source, Span, SyntaxKind,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
adt::interner::Interned,
|
||||
analysis::{Ty, *},
|
||||
};
|
||||
use crate::{analysis::TypeScheme, ty::TypeInterface, AnalysisContext};
|
||||
use tinymist_derive::BindTyCtx;
|
||||
|
||||
use super::{
|
||||
resolve_global_value, BuiltinTy, DefUseInfo, FlowVarKind, IdentRef, TypeBounds, TypeVar,
|
||||
TypeVarBounds,
|
||||
prelude::*, resolve_global_value, BuiltinTy, DefUseInfo, FlowVarKind, TyCtxMut, TypeBounds,
|
||||
TypeScheme, TypeVar, TypeVarBounds,
|
||||
};
|
||||
use crate::ty::*;
|
||||
|
||||
mod apply;
|
||||
mod docs;
|
||||
|
@ -180,11 +164,16 @@ impl<'a, 'w> TypeChecker<'a, 'w> {
|
|||
}
|
||||
|
||||
fn constrain(&mut self, lhs: &Ty, rhs: &Ty) {
|
||||
static FLOW_STROKE_DICT_TYPE: Lazy<Ty> = Lazy::new(|| Ty::Dict(FLOW_STROKE_DICT.clone()));
|
||||
static FLOW_MARGIN_DICT_TYPE: Lazy<Ty> = Lazy::new(|| Ty::Dict(FLOW_MARGIN_DICT.clone()));
|
||||
static FLOW_INSET_DICT_TYPE: Lazy<Ty> = Lazy::new(|| Ty::Dict(FLOW_INSET_DICT.clone()));
|
||||
static FLOW_OUTSET_DICT_TYPE: Lazy<Ty> = Lazy::new(|| Ty::Dict(FLOW_OUTSET_DICT.clone()));
|
||||
static FLOW_RADIUS_DICT_TYPE: Lazy<Ty> = Lazy::new(|| Ty::Dict(FLOW_RADIUS_DICT.clone()));
|
||||
static FLOW_STROKE_DICT_TYPE: LazyLock<Ty> =
|
||||
LazyLock::new(|| Ty::Dict(FLOW_STROKE_DICT.clone()));
|
||||
static FLOW_MARGIN_DICT_TYPE: LazyLock<Ty> =
|
||||
LazyLock::new(|| Ty::Dict(FLOW_MARGIN_DICT.clone()));
|
||||
static FLOW_INSET_DICT_TYPE: LazyLock<Ty> =
|
||||
LazyLock::new(|| Ty::Dict(FLOW_INSET_DICT.clone()));
|
||||
static FLOW_OUTSET_DICT_TYPE: LazyLock<Ty> =
|
||||
LazyLock::new(|| Ty::Dict(FLOW_OUTSET_DICT.clone()));
|
||||
static FLOW_RADIUS_DICT_TYPE: LazyLock<Ty> =
|
||||
LazyLock::new(|| Ty::Dict(FLOW_RADIUS_DICT.clone()));
|
||||
|
||||
fn is_ty(ty: &Ty) -> bool {
|
||||
match ty {
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
//! Type checking at apply site
|
||||
|
||||
use typst::syntax::{ast, Span};
|
||||
|
||||
use crate::analysis::Ty;
|
||||
use crate::ty::Sig;
|
||||
use crate::{analysis::ApplyChecker, ty::ArgsTy};
|
||||
|
||||
use super::*;
|
||||
use crate::adt::interner::Interned;
|
||||
use crate::ty::Sig;
|
||||
use crate::{analysis::ApplyChecker, ty::ArgsTy};
|
||||
|
||||
#[derive(BindTyCtx)]
|
||||
#[bind(base)]
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
use std::{collections::BTreeMap, sync::LazyLock};
|
||||
|
||||
use reflexo::TakeAs;
|
||||
use typst::foundations::{IntoValue, Module, Str, Type};
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
adt::snapshot_map::SnapshotMap,
|
||||
docs::{convert_docs, identify_func_docs, identify_var_docs, DocStringKind},
|
||||
syntax::{find_docs_of, get_non_strict_def_target},
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
const DOC_VARS: u64 = 0;
|
||||
|
||||
impl<'a, 'w> TypeChecker<'a, 'w> {
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
//! Type checking at select site
|
||||
|
||||
use typst::syntax::Span;
|
||||
|
||||
use crate::analysis::SelectChecker;
|
||||
use crate::analysis::Ty;
|
||||
|
||||
use super::*;
|
||||
use crate::adt::interner::Interned;
|
||||
use crate::analysis::SelectChecker;
|
||||
|
||||
#[derive(BindTyCtx)]
|
||||
#[bind(base)]
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
//! Type checking on source file
|
||||
|
||||
use std::{collections::BTreeMap, sync::LazyLock};
|
||||
|
||||
use ecow::eco_vec;
|
||||
use typst::{
|
||||
foundations::Value,
|
||||
syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, SyntaxKind,
|
||||
},
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
adt::interner::Interned,
|
||||
docs::{DocStringKind, SignatureDocsT, TypelessParamDocs, UntypedSymbolDocs},
|
||||
ty::*,
|
||||
};
|
||||
use crate::analysis::ParamAttrs;
|
||||
use crate::docs::{DocStringKind, SignatureDocsT, TypelessParamDocs, UntypedSymbolDocs};
|
||||
use crate::ty::*;
|
||||
|
||||
static EMPTY_DOCSTRING: LazyLock<DocString> = LazyLock::new(DocString::default);
|
||||
static EMPTY_VAR_DOC: LazyLock<VarDoc> = LazyLock::new(VarDoc::default);
|
||||
|
|
|
@ -84,7 +84,7 @@ impl SyntaxRequest for FoldingRangeRequest {
|
|||
}
|
||||
|
||||
if false {
|
||||
trace!("FoldingRangeRequest(line_folding_only={line_folding_only}) symbols: {symbols:#?} results: {results:#?}");
|
||||
log::trace!("FoldingRangeRequest(line_folding_only={line_folding_only}) symbols: {symbols:#?} results: {results:#?}");
|
||||
}
|
||||
|
||||
Some(results)
|
||||
|
@ -164,7 +164,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test() {
|
||||
snapshot_testing("folding_range", &|world, path| {
|
||||
let mut r = |line_folding_only| {
|
||||
let r = |line_folding_only| {
|
||||
let request = FoldingRangeRequest {
|
||||
path: path.clone(),
|
||||
line_folding_only,
|
||||
|
|
|
@ -122,18 +122,18 @@ fn inlay_hint(
|
|||
match node.kind() {
|
||||
// Type inlay hints
|
||||
SyntaxKind::LetBinding => {
|
||||
trace!("let binding found: {:?}", node);
|
||||
log::trace!("let binding found: {:?}", node);
|
||||
}
|
||||
// Assignment inlay hints
|
||||
SyntaxKind::Eq => {
|
||||
trace!("assignment found: {:?}", node);
|
||||
log::trace!("assignment found: {:?}", node);
|
||||
}
|
||||
SyntaxKind::DestructAssignment => {
|
||||
trace!("destruct assignment found: {:?}", node);
|
||||
log::trace!("destruct assignment found: {:?}", node);
|
||||
}
|
||||
// Parameter inlay hints
|
||||
SyntaxKind::FuncCall => {
|
||||
trace!("func call found: {:?}", node);
|
||||
log::trace!("func call found: {:?}", node);
|
||||
let call_info = analyze_call(self.ctx, self.source.clone(), node.clone())?;
|
||||
log::debug!("got call_info {call_info:?}");
|
||||
|
||||
|
@ -278,7 +278,7 @@ fn inlay_hint(
|
|||
// todo: union signatures
|
||||
}
|
||||
SyntaxKind::Set => {
|
||||
trace!("set rule found: {:?}", node);
|
||||
log::trace!("set rule found: {:?}", node);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ pub use std::{
|
|||
|
||||
pub use ecow::EcoVec;
|
||||
pub use itertools::{Format, Itertools};
|
||||
pub use log::{error, trace};
|
||||
pub use log::error;
|
||||
pub use lsp_types::{
|
||||
request::GotoDeclarationResponse, CodeAction, CodeActionKind, CodeActionOrCommand, CodeLens,
|
||||
ColorInformation, ColorPresentation, CompletionResponse, DiagnosticRelatedInformation,
|
||||
|
@ -21,11 +21,11 @@ pub use lsp_types::{
|
|||
pub use reflexo::vector::ir::DefId;
|
||||
pub use serde_json::Value as JsonValue;
|
||||
pub use typst::diag::{EcoString, FileResult, Tracepoint};
|
||||
pub use typst::foundations::{Func, Value};
|
||||
pub use typst::foundations::Value;
|
||||
pub use typst::syntax::FileId as TypstFileId;
|
||||
pub use typst::syntax::{
|
||||
ast::{self, AstNode},
|
||||
LinkedNode, Source, Spanned, SyntaxKind, SyntaxNode,
|
||||
LinkedNode, Source, Spanned, SyntaxKind,
|
||||
};
|
||||
pub use typst::World;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ impl SemanticRequest for SignatureHelpRequest {
|
|||
let Some(Value::Func(function)) = def_link.value else {
|
||||
return None;
|
||||
};
|
||||
trace!("got function {function:?}");
|
||||
log::trace!("got function {function:?}");
|
||||
|
||||
let mut function = &function;
|
||||
use typst::foundations::func::Repr;
|
||||
|
@ -151,7 +151,7 @@ impl SemanticRequest for SignatureHelpRequest {
|
|||
active_parameter.map(|x| x.min(sig.primary().pos_size().saturating_sub(1)));
|
||||
}
|
||||
|
||||
trace!("got signature info {label} {params:?}");
|
||||
log::trace!("got signature info {label} {params:?}");
|
||||
|
||||
Some(SignatureHelp {
|
||||
signatures: vec![SignatureInformation {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::LazyLock;
|
||||
|
||||
use super::{Sig, SigChecker, SigSurfaceKind, TyCtx};
|
||||
use crate::ty::def::*;
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
pub trait ApplyChecker: TyCtx {
|
||||
fn apply(&mut self, sig: Sig, arguments: &Interned<ArgsTy>, pol: bool);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::ty::def::*;
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
pub trait BoundChecker: TyCtx {
|
||||
fn collect(&mut self, ty: &Ty, pol: bool);
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use reflexo::hash::hash128;
|
||||
use typst::foundations::Repr;
|
||||
|
||||
use crate::{analysis::*, ty::def::*};
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
impl TypeScheme {
|
||||
/// Describe the given type with the given type scheme.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use typst::foundations::{Dict, Value};
|
||||
use typst::foundations::Dict;
|
||||
|
||||
use crate::{analysis::*, ty::def::*};
|
||||
use super::BoundChecker;
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Iface<'a> {
|
||||
|
|
|
@ -7,6 +7,7 @@ mod def;
|
|||
mod describe;
|
||||
mod iface;
|
||||
mod mutate;
|
||||
mod prelude;
|
||||
mod select;
|
||||
mod sig;
|
||||
mod simplify;
|
||||
|
|
8
crates/tinymist-query/src/ty/prelude.rs
Normal file
8
crates/tinymist-query/src/ty/prelude.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
pub use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub use reflexo::vector::ir::DefId;
|
||||
pub use typst::foundations::Value;
|
||||
|
||||
pub use super::builtin::*;
|
||||
pub use super::def::*;
|
||||
pub use crate::analysis::AnalysisContext;
|
|
@ -1,6 +1,7 @@
|
|||
use typst::foundations::{Func, Value};
|
||||
|
||||
use crate::{analysis::*, ty::def::*};
|
||||
use super::BoundChecker;
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Sig<'a> {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use ecow::EcoVec;
|
||||
use reflexo::hash::hash128;
|
||||
|
||||
use crate::{analysis::*, ty::def::*};
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct CompactTy {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::{analysis::*, ty::def::*};
|
||||
use super::{Sig, SigShape, TyMutator};
|
||||
use crate::ty::prelude::*;
|
||||
|
||||
impl<'a> Sig<'a> {
|
||||
pub fn call(&self, args: &Interned<ArgsTy>, pol: bool, ctx: &mut impl TyCtxMut) -> Option<Ty> {
|
||||
|
@ -57,9 +58,9 @@ mod tests {
|
|||
use insta::{assert_debug_snapshot, assert_snapshot};
|
||||
use tinymist_derive::BindTyCtx;
|
||||
|
||||
use super::{Interned, Ty, TyCtx, TypeBounds, TypeScheme, TypeVar};
|
||||
use crate::ty::tests::*;
|
||||
|
||||
use super::{ApplyChecker, Interned, Ty, TyCtx, TypeBounds, TypeScheme, TypeVar};
|
||||
use crate::ty::ApplyChecker;
|
||||
#[test]
|
||||
fn test_ty() {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue