@servicenow/sdk - v4.4.1
    Preparing search index...

    Interface DocumentRegistry

    The document registry represents a store of SourceFile objects that can be shared between multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST) of files in the context. SourceFile objects account for most of the memory usage by the language service. Sharing the same DocumentRegistry instance between different instances of LanguageService allow for more efficient memory utilization since all projects will share at least the library file (lib.d.ts).

    A more advanced use of the document registry is to serialize sourceFile objects to disk and re-hydrate them when needed.

    To create a default DocumentRegistry, use createDocumentRegistry to create one, and pass it to all subsequent createLanguageService calls.

    interface DocumentRegistry {
        acquireDocument(
            fileName: string,
            compilationSettingsOrHost:
                | tsc.CompilerOptions
                | MinimalResolutionCacheHost,
            scriptSnapshot: IScriptSnapshot,
            version: string,
            scriptKind?: tsc.ScriptKind,
            sourceFileOptions?: tsc.ScriptTarget | CreateSourceFileOptions,
        ): tsc.SourceFile;
        acquireDocumentWithKey(
            fileName: string,
            path: tsc.Path,
            compilationSettingsOrHost:
                | tsc.CompilerOptions
                | MinimalResolutionCacheHost,
            key: DocumentRegistryBucketKey,
            scriptSnapshot: IScriptSnapshot,
            version: string,
            scriptKind?: tsc.ScriptKind,
            sourceFileOptions?: tsc.ScriptTarget | CreateSourceFileOptions,
        ): tsc.SourceFile;
        getKeyForCompilationSettings(
            settings: tsc.CompilerOptions,
        ): DocumentRegistryBucketKey;
        releaseDocument(
            fileName: string,
            compilationSettings: tsc.CompilerOptions,
            scriptKind?: tsc.ScriptKind,
        ): void;
        releaseDocument(
            fileName: string,
            compilationSettings: tsc.CompilerOptions,
            scriptKind: tsc.ScriptKind,
            impliedNodeFormat: ResolutionMode,
        ): void;
        releaseDocumentWithKey(
            path: tsc.Path,
            key: DocumentRegistryBucketKey,
            scriptKind?: tsc.ScriptKind,
        ): void;
        releaseDocumentWithKey(
            path: tsc.Path,
            key: DocumentRegistryBucketKey,
            scriptKind: tsc.ScriptKind,
            impliedNodeFormat: ResolutionMode,
        ): void;
        reportStats(): string;
        updateDocument(
            fileName: string,
            compilationSettingsOrHost:
                | tsc.CompilerOptions
                | MinimalResolutionCacheHost,
            scriptSnapshot: IScriptSnapshot,
            version: string,
            scriptKind?: tsc.ScriptKind,
            sourceFileOptions?: tsc.ScriptTarget | CreateSourceFileOptions,
        ): tsc.SourceFile;
        updateDocumentWithKey(
            fileName: string,
            path: tsc.Path,
            compilationSettingsOrHost:
                | tsc.CompilerOptions
                | MinimalResolutionCacheHost,
            key: DocumentRegistryBucketKey,
            scriptSnapshot: IScriptSnapshot,
            version: string,
            scriptKind?: tsc.ScriptKind,
            sourceFileOptions?: tsc.ScriptTarget | CreateSourceFileOptions,
        ): tsc.SourceFile;
    }
    Index

    Methods

    • Request a stored SourceFile with a given fileName and compilationSettings. The first call to acquire will call createLanguageServiceSourceFile to generate the SourceFile if was not found in the registry.

      Parameters

      • fileName: string

        The name of the file requested

      • compilationSettingsOrHost: tsc.CompilerOptions | MinimalResolutionCacheHost

        Some compilation settings like target affects the shape of a the resulting SourceFile. This allows the DocumentRegistry to store multiple copies of the same file for different compilation settings. A minimal resolution cache is needed to fully define a source file's shape when the compilation settings include module: node16+, so providing a cache host object should be preferred. A common host is a language service ConfiguredProject.

      • scriptSnapshot: IScriptSnapshot

        Text of the file. Only used if the file was not found in the registry and a new one was created.

      • version: string

        Current version of the file. Only used if the file was not found in the registry and a new one was created.

      • OptionalscriptKind: tsc.ScriptKind
      • OptionalsourceFileOptions: tsc.ScriptTarget | CreateSourceFileOptions

      Returns tsc.SourceFile

    • Informs the DocumentRegistry that a file is not needed any longer.

      Note: It is not allowed to call release on a SourceFile that was not acquired from this registry originally.

      Parameters

      • fileName: string

        The name of the file to be released

      • compilationSettings: tsc.CompilerOptions

        The compilation settings used to acquire the file

      • OptionalscriptKind: tsc.ScriptKind

        The script kind of the file to be released

      Returns void

      pass scriptKind and impliedNodeFormat for correctness

    • Informs the DocumentRegistry that a file is not needed any longer.

      Note: It is not allowed to call release on a SourceFile that was not acquired from this registry originally.

      Parameters

      • fileName: string

        The name of the file to be released

      • compilationSettings: tsc.CompilerOptions

        The compilation settings used to acquire the file

      • scriptKind: tsc.ScriptKind

        The script kind of the file to be released

      • impliedNodeFormat: ResolutionMode

        The implied source file format of the file to be released

      Returns void

    • Returns string

    • Request an updated version of an already existing SourceFile with a given fileName and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile to get an updated SourceFile.

      Parameters

      • fileName: string

        The name of the file requested

      • compilationSettingsOrHost: tsc.CompilerOptions | MinimalResolutionCacheHost

        Some compilation settings like target affects the shape of a the resulting SourceFile. This allows the DocumentRegistry to store multiple copies of the same file for different compilation settings. A minimal resolution cache is needed to fully define a source file's shape when the compilation settings include module: node16+, so providing a cache host object should be preferred. A common host is a language service ConfiguredProject.

      • scriptSnapshot: IScriptSnapshot

        Text of the file.

      • version: string

        Current version of the file.

      • OptionalscriptKind: tsc.ScriptKind
      • OptionalsourceFileOptions: tsc.ScriptTarget | CreateSourceFileOptions

      Returns tsc.SourceFile