-
Notifications
You must be signed in to change notification settings - Fork 649
Move version
from source file to document registry
#1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 relocates version tracking from the AST SourceFile
itself into the central DocumentRegistry
to prevent data races when caching source files.
- Replaces direct
SourceFile.Version
checks with a registry-backedgetFileVersion
lookup insnapshot
andprint
logic - Adds a
version
field toregistryEntry
and updates it whenever a new parse occurs - Removes the now-unneeded
Version
field fromast.SourceFile
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
internal/project/project.go | Switched version comparisons to use getFileVersion and added a proxy method on Project |
internal/project/documentregistry.go | Introduced version in registryEntry , updated parsing logic, and added getFileVersion |
internal/ast/ast.go | Removed the deprecated Version field from SourceFile |
Comments suppressed due to low confidence (2)
internal/project/documentregistry.go:122
- New
getFileVersion
logic inDocumentRegistry
lacks unit tests to ensure it correctly retrieves the stored version (and returns -1 when missing).
func (r *DocumentRegistry) getFileVersion(file *ast.SourceFile, options *core.CompilerOptions) int {
internal/project/project.go:1033
- The proxy
Project.getFileVersion
method is untested; consider adding tests to validate it correctly delegates to the registry.
func (p *Project) getFileVersion(file *ast.SourceFile, options *core.CompilerOptions) int {
version
from source file to document registry
func (r *DocumentRegistry) getFileVersion(file *ast.SourceFile, options *core.CompilerOptions) int { | ||
key := newRegistryKey(options, file.Path(), file.ScriptKind) | ||
if entry, ok := r.documents.Load(key); ok { | ||
return entry.version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not enough i think. The source file may have been updated for the compilerOptions by other program and hence the source file may be newer = script info version. You actually want to check if file == entry.sourceFile
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks!
The version really only concerns the project and document registry, so I moved it there to avoid a data race in #991 where we cache
SourceFile
s.