Skip to content

Advanced DocumentRegistry: what's expected of SourceFile #3662

Closed
@mihailik

Description

@mihailik

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 SourceFiles.

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions