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}> 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, content) bumps the version when content 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
setFile
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: no-op (version unchanged).
- Existing file with new content: version bumped.
type (path: string, content: string): boolean
path
stringcontent
stringbooleantrue 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