Skip to content

Conversation

@jakebailey
Copy link
Member

Same as Strada:

export function getNameTable(sourceFile: SourceFile): Map<__String, number> {
    if (!sourceFile.nameTable) {
        initializeNameTable(sourceFile);
    }

    return sourceFile.nameTable!; // TODO: GH#18217
}

function initializeNameTable(sourceFile: SourceFile): void {
    const nameTable = sourceFile.nameTable = new Map();
    sourceFile.forEachChild(function walk(node) {

Copilot AI review requested due to automatic review settings December 12, 2025 18:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements caching of the name table on SourceFile to avoid repeated computation, following the same pattern used in the TypeScript reference implementation. The name table is lazily initialized using sync.Once for thread-safe caching.

Key changes:

  • Added cached name table with thread-safe lazy initialization to SourceFile struct
  • Moved name table generation logic from a standalone function in utilities.go to a method on SourceFile in ast.go
  • Updated call sites to use the new GetNameTable() method

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/ast/ast.go Added nameTableOnce and nameTable fields to SourceFile struct; implemented GetNameTable() method with lazy initialization using sync.Once
internal/ls/utilities.go Removed getNameTable(), literalIsName(), and isTagName() functions that are now encapsulated within the GetNameTable() method
internal/ls/findallreferences.go Updated call from getNameTable(sourceFile) to sourceFile.GetNameTable()
internal/ls/completions.go Updated call from getNameTable(file) to file.GetNameTable()

@jakebailey jakebailey requested a review from gabritto December 12, 2025 18:42
@jakebailey jakebailey added this pull request to the merge queue Dec 12, 2025
Merged via the queue into main with commit 20bf4fc Dec 12, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/cache-get-name-table branch December 12, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants