typescript-program.ts view source
AnalysisLanguageService import type {AnalysisLanguageService} from 'svelte-docinfo/typescript-program.js'; Persistent language-service handle that drives a ts.Program incrementally.
Owns the LS, document registry, and a `Map<path, {content, version,
scriptKind}>` of "owned" files (real source files + virtuals pushed via
setFile). Files not in the owned map are read from disk on demand by the
LS host.
Each setFile(path, entry) bumps the version when content or script kind
differs from cache, so the next getProgram() reparses only the changed
file. Calling getProgram() with no version bumps returns the same
ts.Program as the previous call (reference-stable when nothing changed).
see also
``createAnalysisSession`` in session.ts for the high-level API that wraps this with content cache + svelte virtual cache + analysis pipeline.
getProgram
Get the current ts.Program.
Returns the same reference as the previous call when no setFile /
deleteFile invalidated state in between. Returns a fresh ts.Program
(sharing parsed ASTs for unchanged files via the document registry) when
versions changed.
type (): Program
Programthrows
Error- if the underlying LS returned undefined (should not happen
getCompilerOptions
The merged compiler options the service was constructed with — parsed
tsconfig with the caller's compilerOptions overrides applied per-key.
Cheap accessor over the construction-time loadTsconfig result; prefer
it over getProgram().getCompilerOptions() when only the options are
needed — getProgram() forces the LS to sync and parse every root file.
Treat the returned object as read-only: it is the same reference the LS
host serves via getCompilationSettings, so mutating it would desync
consumers (e.g., the session's default import resolver) from the checker.
type (): CompilerOptions
CompilerOptionssetFile
Set or replace a file's content (real path or virtual path).
- New file: added to the owned map with version 1.
- Existing file with identical content and script kind: no-op (version unchanged).
- Existing file with new content or script kind: version bumped.
type (path: string, entry: VirtualFileEntry): boolean
path
stringentry
booleantrue when the file was added or its version bumped, false on no-op.
deleteFile
Remove a file from the owned set.
type (path: string): boolean
path
stringbooleantrue when the file was tracked, false when it was unknown.
hasFile
Whether the given path is currently tracked.
type (path: string): boolean
path
stringbooleandispose
Release LS resources.
Calls ts.LanguageService.dispose() and clears the owned map. The
service must not be used after disposal.
type (): void
void