also exported from index.ts
AnalysisSession import type {AnalysisSession} from 'svelte-docinfo/session.js'; Persistent analysis handle.
Concurrency: not safe across overlapping calls. Serialize externally
(each caller awaits the previous setFile/setFiles before starting the
next). The LS underneath is sync, but the resolver phase awaits I/O for
async resolvers (Vite/Rollup), so the session does cross await boundaries.
Cache-hit semantics: per-entry, all-or-nothing. The implementation must not split the guarantee across separate caches (e.g. transform-cache hit + lex re-run). The match criterion is mode-discriminated:
- lex+resolve mode:
existing.content === incoming.contentANDexisting.resolverIdentity === incoming.resolverIdentity. - pre-resolved mode:
existing.content === incoming.contentANDarraysShallowEqual(existing.preResolvedDepsSnapshot, incoming.dependencies).
Mode flips (an entry previously ingested as lex+resolve now arrives with
dependencies, or vice versa) always cache-miss.
Deferred resolutions: a cache hit reuses the entry's dependency edges,
but an import specifier that resolved to nothing isn't a settled answer —
its target may be ingested later, and the file that changes then is the
*dep*, not the importer, so the importer would stay a cache hit with a
missing edge. A setFiles that adds paths therefore retries the unresolved
specifiers of already-owned entries and updates their edges in place,
retiring any resolver_failed that has since resolved. This is the one way
an entry changes without being re-ingested; it consumes no resolver work for
files whose imports all resolved, and none at all for pre-resolved callers,
whose edges are theirs to declare.
Promise resolution: setFile / setFiles resolve only after the
serial LS push (phase 3) completes for every file in the batch. Awaiting
the returned promise is sufficient — no separate flush step.
Owned ⊇ emitted: ingest is additive and ungated — any file can be
pushed, and owned entries are served to the checker from memory before the
disk fallback, so non-source files (unsaved buffers, virtual-only helpers,
configs) can shape type resolution in the modules that import them.
query() gates the *module set* through isSource: only owned files under
sourceOptions.sourcePaths and not matching exclude emit a ModuleJson.
The gate emits no diagnostics — query() logs the gated count as info, and
list() reports the full owned set for introspection. By default the
session completes the owned set itself: contextClosure ingests the
in-root non-source dependency closure (e.g. internal/ modules public
files import) so those files are version-tracked rather than pinned at
their first disk read.
setFile
Ingest one file's content into the session. Idempotent on cache hit.
type (file: SourceFileInfo, opts?: SetFileOptions | undefined): Promise<SetFileResult>
file
opts?
Promise<SetFileResult>{changed, diagnostics} — changed: false indicates a
cache-hit no-op where the cached ingest diagnostics are returned.
setFiles
Ingest a batch of files. Additive — never removes; use deleteFile for
removal. Cache hits are folded into the result with changed: false.
type (files: readonly SourceFileInfo[], opts?: SetFileOptions | undefined): Promise<SetFilesResult>
files
readonly SourceFileInfo[]opts?
Promise<SetFilesResult>deleteFile
Drop a file from the session and evict from the LS.
type (id: string): Promise<void>
id
stringPromise<void>has
Whether the given file ID is currently owned by the session.
type (id: string): boolean
id
stringbooleanlist
Snapshot of currently-owned file IDs (sort order is insertion order).
type (): readonly string[]
readonly string[]query
Run a two-phase analysis pass against the current owned set, gated by
isSource — owned files outside sourcePaths (or matching exclude)
provide checker context but emit no module (see "Owned ⊇ emitted"
above).
type (opts?: QueryOptions | undefined): { modules: { path: string; declarations: ({ kind: "function"; parameters: { name: string; type: string; optional: boolean; rest: boolean; typeInfo?: TypeJson | undefined; description?: string | undefined; defaultValue?: string | undefined; propertyDescriptions?: Record<...> | undefined; }[]; ... 19 more ...; sourceLine?: number | undefined; } | ... 7 more ... | { ...; })[]; ... 7 more ...; moduleComment?: string | undefined; }[]; diagnostics: ({ ...; } | ... 14 more ... | { ...; })[]; }
opts?
{ modules: { path: string; declarations: ({ kind: "function"; parameters: { name: string; type: string; optional: boolean; rest: boolean; typeInfo?: TypeJson | undefined; description?: string | undefined; defaultValue?: string | undefined; propertyDescriptions?: Record<...> | undefined; }[]; ... 19 more ...; sourceL...analyzed modules and analysis-pass diagnostics. Ingest
diagnostics from prior setFile/setFiles calls are NOT included
here — concat with those returns for the full picture.
throws
Error- if `onDuplicates: 'throw'` and duplicates exist
allIngestDiagnostics
Concatenated ingest-time diagnostics across every owned entry — the
cumulative view of every setFile/setFiles return, kept current as
entries are added/replaced/deleted.
Lets long-lived consumers (Vite plugin, LSP) publish the full ingest picture without tracking per-batch returns themselves. Cheap: walks the owned map.
type (): ({ symbolName: string; file: string; message: string; severity: "error" | "warning"; kind: "type_extraction_failed"; line?: number | undefined; column?: number | undefined; } | { functionName: string; ... 5 more ...; column?: number | undefined; } | ... 13 more ... | { ...; })[]
({ symbolName: string; file: string; message: string; severity: "error" | "warning"; kind: "type_extraction_failed"; line?: number | undefined; column?: number | undefined; } | { functionName: string; ... 5 more ...; column?: number | undefined; } | ... 13 more ... | { ...; })[]getProgram
The LS-backed ts.Program, for incremental consumers doing their own
checker work over analyzed declarations (e.g., a docgen provider
converting ts.Types into its own structured model).
Freshness caveat: returns whatever the most recent ingest produced —
the same reference as the prior call when no file version bumped, else
a fresh program reusing unchanged ASTs via the document registry. A
retained reference goes stale after any setFile / setFiles /
deleteFile; re-call after mutating. Subject to the session's
concurrency contract above; invalid after dispose().
type (): Program
Programdispose
Release LS resources and clear the owned set. The session must not be used after disposal.
type (): void
void