Skip to content

Commit d593902

Browse files
committed
Add documentation to DocumentRegistry
1 parent e503f38 commit d593902

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/services/services.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,13 +1155,62 @@ module ts {
11551155
getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult;
11561156
}
11571157

1158+
/**
1159+
* The document registry represents a store of SourceFile objects that can be shared between
1160+
* multiple LanguageService instances. A LanguageService instance holds on the SourceFile (AST)
1161+
* of files in the context.
1162+
* SourceFile objects account for most of the memory usage by the language service. Sharing
1163+
* the same DocumentRegistry instance between different instances of LanguageService allow
1164+
* for more efficient memory utilization since all projects will share at least the library
1165+
* file (lib.d.ts).
1166+
*
1167+
* A more advanced use of the document registry is to serialize sourceFile objects to disk
1168+
* and re-hydrate them when needed.
1169+
*
1170+
* To create a default DocumentRegistry, use createDocumentRegistry to create one, and pass it
1171+
* to all subsequent createLanguageService calls.
1172+
*/
11581173
export interface DocumentRegistry {
1174+
/**
1175+
* Request a stored SourceFile with a given filename and compilationSettings.
1176+
* The first call to acquire will call createLanguageServiceSourceFile to generate
1177+
* the SourceFile if was not found in the registry.
1178+
*
1179+
* @param filename The name of the file requested
1180+
* @param compilationSettings Some compilation settings like target affects the
1181+
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
1182+
* multiple copies of the same file for different compilation settings.
1183+
* @parm scriptSnapshot Text of the file. Only used if the file was not found
1184+
* in the registry and a new one was created.
1185+
* @parm version Current version of the file. Only used if the file was not found
1186+
* in the registry and a new one was created.
1187+
*/
11591188
acquireDocument(
11601189
filename: string,
11611190
compilationSettings: CompilerOptions,
11621191
scriptSnapshot: IScriptSnapshot,
11631192
version: string): SourceFile;
11641193

1194+
/**
1195+
* Request an updated version of an already existing SourceFile with a given filename
1196+
* and compilationSettings. The update will intern call updateLanguageServiceSourceFile
1197+
* to get an updated SourceFile.
1198+
*
1199+
* Note: It is not allowed to call update on a SourceFile that was not acquired from this
1200+
* registry originally.
1201+
*
1202+
* @param sourceFile The original sourceFile object to update
1203+
* @param filename The name of the file requested
1204+
* @param compilationSettings Some compilation settings like target affects the
1205+
* shape of a the resulting SourceFile. This allows the DocumentRegistry to store
1206+
* multiple copies of the same file for different compilation settings.
1207+
* @parm scriptSnapshot Text of the file. Only used if the file was not found
1208+
* in the registry and a new one was created.
1209+
* @parm version Current version of the file. Only used if the file was not found
1210+
* in the registry and a new one was created.
1211+
* @parm textChangeRange Change ranges since the last snapshot. Only used if the file
1212+
* was not found in the registry and a new one was created.
1213+
*/
11651214
updateDocument(
11661215
sourceFile: SourceFile,
11671216
filename: string,
@@ -1170,6 +1219,15 @@ module ts {
11701219
version: string,
11711220
textChangeRange: TextChangeRange): SourceFile;
11721221

1222+
/**
1223+
* Informs the DocumentRegistry that a file is not needed any longer.
1224+
*
1225+
* Note: It is not allowed to call release on a SourceFile that was not acquired from
1226+
* this registry originally.
1227+
*
1228+
* @param filename The name of the file to be released
1229+
* @param compilationSettings The compilation settings used to acquire the file
1230+
*/
11731231
releaseDocument(filename: string, compilationSettings: CompilerOptions): void
11741232
}
11751233

0 commit comments

Comments
 (0)