mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 12:46:43 +00:00
dev: collect func.with type information for signature help (#759)
* feat: static analysis on `func.with` bindings * test: update snapshot
This commit is contained in:
parent
67367b03bf
commit
f1f77065d7
16 changed files with 163 additions and 230 deletions
|
|
@ -11,11 +11,12 @@ use typst::syntax::package::PackageSpec;
|
|||
use typst::syntax::FileId;
|
||||
|
||||
use crate::docs::file_id_repr;
|
||||
use crate::package::{get_manifest_id, PackageInfo};
|
||||
use crate::syntax::{Decl, DefKind, Expr, ExprInfo};
|
||||
use crate::ty::Interned;
|
||||
use crate::LocalContext;
|
||||
|
||||
use super::{get_manifest_id, DefDocs, PackageInfo};
|
||||
use super::DefDocs;
|
||||
|
||||
/// Get documentation of definitions in a package.
|
||||
pub fn package_module_docs(ctx: &mut LocalContext, pkg: &PackageInfo) -> StrResult<PackageDefInfo> {
|
||||
|
|
|
|||
|
|
@ -6,24 +6,13 @@ use ecow::{EcoString, EcoVec};
|
|||
use indexmap::IndexSet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typst::diag::{eco_format, StrResult};
|
||||
use typst::syntax::package::{PackageManifest, PackageSpec};
|
||||
use typst::syntax::{FileId, Span, VirtualPath};
|
||||
use typst::World;
|
||||
use typst::syntax::package::PackageManifest;
|
||||
use typst::syntax::{FileId, Span};
|
||||
|
||||
use crate::docs::{file_id_repr, module_docs, DefDocs, PackageDefInfo};
|
||||
use crate::package::{get_manifest_id, PackageInfo};
|
||||
use crate::LocalContext;
|
||||
|
||||
/// Check Package.
|
||||
pub fn check_package(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<()> {
|
||||
let toml_id = get_manifest_id(spec)?;
|
||||
let manifest = ctx.get_manifest(toml_id)?;
|
||||
|
||||
let entry_point = toml_id.join(&manifest.package.entrypoint);
|
||||
|
||||
ctx.shared_().preload_package(entry_point);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate full documents in markdown format
|
||||
pub fn package_docs(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<String> {
|
||||
log::info!("generate_md_docs {spec:?}");
|
||||
|
|
@ -326,55 +315,6 @@ pub fn package_docs(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<Str
|
|||
Ok(md)
|
||||
}
|
||||
|
||||
/// Parses the manifest of the package located at `package_path`.
|
||||
pub fn get_manifest_id(spec: &PackageInfo) -> StrResult<FileId> {
|
||||
Ok(FileId::new(
|
||||
Some(PackageSpec {
|
||||
namespace: spec.namespace.clone(),
|
||||
name: spec.name.clone(),
|
||||
version: spec.version.parse()?,
|
||||
}),
|
||||
VirtualPath::new("typst.toml"),
|
||||
))
|
||||
}
|
||||
|
||||
/// Parses the manifest of the package located at `package_path`.
|
||||
pub fn get_manifest(world: &dyn World, toml_id: FileId) -> StrResult<PackageManifest> {
|
||||
let toml_data = world
|
||||
.file(toml_id)
|
||||
.map_err(|err| eco_format!("failed to read package manifest ({})", err))?;
|
||||
|
||||
let string = std::str::from_utf8(&toml_data)
|
||||
.map_err(|err| eco_format!("package manifest is not valid UTF-8 ({})", err))?;
|
||||
|
||||
toml::from_str(string)
|
||||
.map_err(|err| eco_format!("package manifest is malformed ({})", err.message()))
|
||||
}
|
||||
|
||||
/// Information about a package.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PackageInfo {
|
||||
/// The path to the package if any.
|
||||
pub path: PathBuf,
|
||||
/// The namespace the package lives in.
|
||||
pub namespace: EcoString,
|
||||
/// The name of the package within its namespace.
|
||||
pub name: EcoString,
|
||||
/// The package's version.
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
impl From<(PathBuf, PackageSpec)> for PackageInfo {
|
||||
fn from((path, spec): (PathBuf, PackageSpec)) -> Self {
|
||||
Self {
|
||||
path,
|
||||
namespace: spec.namespace,
|
||||
name: spec.name,
|
||||
version: spec.version.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn jbase64<T: Serialize>(s: &T) -> String {
|
||||
use base64::Engine;
|
||||
let content = serde_json::to_string(s).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue