Description
I want to speed up the startup of language service. The biggest hit by far is parsing of lib.d.ts
, which may easily take many seconds on underpowered devices.
Wiki page Using the Language Service API suggests I can implement a custom document service, which would cache SourceFile
s.
Sounds good: lib.d.ts
virtually never changes and can be cached safely. Hopefully, eliminating parsing and boosting startup speeds.
But what is the nature of the data that should be cached? I can see SourceFile interface is not quite clear on what it is holding. Note the /* @internal */
members, are those expected to be cached/restored too?
export interface SourceFile {
/* @internal */ version: string;
/* @internal */ scriptSnapshot: IScriptSnapshot;
/* @internal */ nameTable: Map<string>;
/* @internal */ getNamedDeclarations(): Map<Declaration[]>;
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
getLineStarts(): number[];
getPositionOfLineAndCharacter(line: number, character: number): number;
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
}
Comments on DocumentService.acquireDocument give a slight hint that the main piece of information SourceFile
holds is IScriptSnapshot
. Is that right? Or is it more to it?
Many thanks!