Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
371cacd
fix (unfinished) TS6053 missing file diagnostics to match tsc (#2081)
Nov 14, 2025
3b00267
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 14, 2025
67db554
Delete TestMissingReferenceFile test case
TranNhatHan Nov 15, 2025
5de90ce
Merge branch 'microsoft:main' into fix-missing-file-diagnostics
TranNhatHan Nov 15, 2025
5b87cc2
completely fix the missing error file not found bug
Nov 15, 2025
0b3f881
failed incremental test in scenario "when global file is added, the s…
Nov 16, 2025
b44a247
fix: attach missing-file diagnostics to the correct source file
Nov 16, 2025
b615125
fix: resolve golangci-lint errors
Nov 16, 2025
5bad47f
Merge branch 'microsoft:main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
873b273
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
77d30af
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
ad50113
update code per maintainer suggestions
Nov 17, 2025
ea23f59
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 17, 2025
0ed3489
reset the .golangci.yml as default
Nov 17, 2025
f46ccc9
reset the .golangci.yml as default
Nov 18, 2025
02696be
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 19, 2025
87bd8d6
accept new baseline
Nov 19, 2025
aad5fc2
Revert "accept new baseline"
Nov 19, 2025
eadc7bf
update new baseline
Nov 19, 2025
1999a76
Revert "update new baseline"
Nov 19, 2025
1dddca1
failed tests
Nov 20, 2025
f4eddf6
failed incremental test
Nov 20, 2025
3ebb753
update new baseline
Nov 20, 2025
a8a4b3c
fix
Nov 20, 2025
5af31f1
Revert "failed incremental test"
Nov 20, 2025
c29d729
Revert "update new baseline"
Nov 20, 2025
aa2b4cf
fix
Nov 20, 2025
363bde5
keep fixing
Nov 20, 2025
4edbc11
Merge pull request #1 from TranNhatHan/fix-bug
TranNhatHan Nov 20, 2025
b0adcfe
Merge branch 'main' into fix-missing-file-diagnostics
TranNhatHan Nov 21, 2025
7e18c1f
raise error but change other behaviours
Nov 21, 2025
a6958e0
Merge branch 'fix-missing-file-diagnostics' of https://github.com/Tra…
Nov 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ type fileLoader struct {
pathForLibFileResolutions collections.SyncMap[tspath.Path, *libResolution]
}

type missingFile struct {
path string
reason *FileIncludeReason
}

type processedFiles struct {
resolver *module.Resolver
files []*ast.SourceFile
filesByPath map[tspath.Path]*ast.SourceFile
projectReferenceFileMapper *projectReferenceFileMapper
missingFiles []string
missingFiles []missingFile
resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
typeResolutionsInFile map[tspath.Path]module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
sourceFileMetaDatas map[tspath.Path]ast.SourceFileMetaData
Expand Down Expand Up @@ -136,7 +141,7 @@ func processAllProgramFiles(
totalFileCount := int(loader.totalFileCount.Load())
libFileCount := int(loader.libFileCount.Load())

var missingFiles []string
var missingFiles []missingFile
files := make([]*ast.SourceFile, 0, totalFileCount-libFileCount)
libFiles := make([]*ast.SourceFile, 0, totalFileCount) // totalFileCount here since we append files to it later to construct the final list

Expand Down Expand Up @@ -168,9 +173,13 @@ func processAllProgramFiles(
}
file := task.file
path := task.path

// !!! sheetal file preprocessing diagnostic explaining getSourceFileFromReferenceWorker
if file == nil {
// !!! sheetal file preprocessing diagnostic explaining getSourceFileFromReferenceWorker
missingFiles = append(missingFiles, task.normalizedFilePath)
missingFiles = append(missingFiles, missingFile{
path: task.normalizedFilePath,
reason: task.includeReason,
})
return
}

Expand Down
33 changes: 31 additions & 2 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Program struct {
declarationDiagnosticCache collections.SyncMap[*ast.SourceFile, []*ast.Diagnostic]

programDiagnostics []*ast.Diagnostic
programDiagnosticsOnce sync.Once
hasEmitBlockingDiagnostics collections.Set[tspath.Path]

sourceFilesToEmitOnce sync.Once
Expand Down Expand Up @@ -211,6 +212,7 @@ func NewProgram(opts ProgramOptions) *Program {
p.initCheckerPool()
p.processedFiles = processAllProgramFiles(p.opts, p.SingleThreaded())
p.verifyCompilerOptions()
p.addProgramDiagnostics()
return p
}

Expand Down Expand Up @@ -1222,6 +1224,33 @@ func (p *Program) getDiagnosticsHelper(ctx context.Context, sourceFile *ast.Sour
return SortAndDeduplicateDiagnostics(result)
}

func (p *Program) addProgramDiagnostics() {
for _, missingFile := range p.missingFiles {
missingFileReason := missingFile.reason
refData, ok := missingFileReason.data.(*referencedFileData)
if !ok {
continue
}

parentFile := p.filesByPath[refData.file]
if parentFile == nil {
continue
}

for _, ref := range parentFile.ReferencedFiles {
if tspath.GetNormalizedAbsolutePath(ref.FileName, tspath.GetDirectoryPath(parentFile.FileName())) == missingFile.path {
diagnostic := ast.NewDiagnostic(
parentFile,
ref.TextRange,
diagnostics.File_0_not_found,
ref.FileName,
)
p.programDiagnostics = append(p.programDiagnostics, diagnostic)
}
}
}
}

func (p *Program) LineCount() int {
var count int
for _, file := range p.files {
Expand Down Expand Up @@ -1553,8 +1582,8 @@ func (p *Program) GetIncludeReasons() map[tspath.Path][]*FileIncludeReason {

// Testing only
func (p *Program) IsMissingPath(path tspath.Path) bool {
return slices.ContainsFunc(p.missingFiles, func(missingPath string) bool {
return p.toPath(missingPath) == path
return slices.ContainsFunc(p.missingFiles, func(missingPath missingFile) bool {
return missingPath.path == string(path)
})
}

Expand Down